Skip to content

Commit

Permalink
Add User#recently_sent_password_reset?
Browse files Browse the repository at this point in the history
  • Loading branch information
rspeicher committed Oct 2, 2015
1 parent 19748dd commit ad7ad87
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ def generate_reset_token
@reset_token
end

def recently_sent_password_reset?
reset_password_sent_at.present? && reset_password_sent_at >= 1.minute.ago
end

def disable_two_factor!
update_attributes(
two_factor_enabled: false,
Expand Down
20 changes: 20 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,26 @@
end
end

describe 'recently_sent_password_reset?' do
it 'is false when reset_password_sent_at is nil' do
user = build_stubbed(:user, reset_password_sent_at: nil)

expect(user.recently_sent_password_reset?).to eq false
end

it 'is false when sent more than one minute ago' do
user = build_stubbed(:user, reset_password_sent_at: 5.minutes.ago)

expect(user.recently_sent_password_reset?).to eq false
end

it 'is true when sent less than one minute ago' do
user = build_stubbed(:user, reset_password_sent_at: Time.now)

expect(user.recently_sent_password_reset?).to eq true
end
end

describe '#disable_two_factor!' do
it 'clears all 2FA-related fields' do
user = create(:user, :two_factor)
Expand Down

0 comments on commit ad7ad87

Please sign in to comment.