adds User#age
This commit is contained in:
@@ -246,6 +246,14 @@ class User < ActiveRecord::Base
|
||||
"#{name} (#{email})"
|
||||
end
|
||||
|
||||
def age
|
||||
if date_of_birth.blank?
|
||||
nil
|
||||
else
|
||||
((Date.today - date_of_birth.to_date).to_i / 365.25).to_i
|
||||
end
|
||||
end
|
||||
|
||||
def save_requiring_finish_signup
|
||||
begin
|
||||
self.registering_with_oauth = true
|
||||
|
||||
@@ -65,6 +65,13 @@ describe User do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#age" do
|
||||
it "is the rounded integer age based on the date_of_birth" do
|
||||
user = create(:user, date_of_birth: 33.years.ago)
|
||||
expect(user.age).to eq(33)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'preferences' do
|
||||
describe 'email_on_comment' do
|
||||
it 'should be false by default' do
|
||||
|
||||
Reference in New Issue
Block a user