Merge pull request #859 from lengarvey/user_refactoring
Light refactoring of the User model
This commit is contained in:
commit
18b00d01d0
|
@ -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
|
||||
|
||||
|
|
|
@ -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) }
|
||||
|
|
Loading…
Reference in New Issue