diff --git a/app/models/user.rb b/app/models/user.rb index 572a1e708..1d572fc68 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -307,7 +307,7 @@ class User < ActiveRecord::Base end def regular? - !(admin? || moderator?) + !staff? end def password=(password) @@ -325,10 +325,6 @@ class User < ActiveRecord::Base self.password_hash == hash_password(password, salt) end - def seen?(date) - last_seen_at.to_date >= date if last_seen_at.present? - end - def seen_before? last_seen_at.present? end @@ -338,14 +334,9 @@ class User < ActiveRecord::Base end def update_visit_record!(date) - unless seen_before? + unless has_visit_record?(date) + update_column(:days_visited, days_visited + 1) user_visits.create!(visited_at: date) - update_column(:days_visited, 1) - end - - unless seen?(date) || has_visit_record?(date) - user_visits.create!(visited_at: date) - User.update_all('days_visited = days_visited + 1', id: self.id) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 061f87b1f..464b7d158 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -321,6 +321,46 @@ describe User do end + describe 'staff and regular users' do + let(:user) { Fabricate.build(:user) } + + describe '#staff?' do + subject { user.staff? } + + it { should be_false } + + context 'for a moderator user' do + before { user.moderator = true } + + it { should be_true } + end + + context 'for an admin user' do + before { user.admin = true } + + it { should be_true } + end + end + + describe '#regular?' do + subject { user.regular? } + + it { should be_true } + + context 'for a moderator user' do + before { user.moderator = true } + + it { should be_false } + end + + context 'for an admin user' do + before { user.admin = true } + + it { should be_false } + end + end + end + describe 'temporary_key' do let(:user) { Fabricate(:user) }