Skip to content

Commit

Permalink
better naming of password expiration submodule methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Erhard committed Apr 23, 2014
1 parent 37e9a91 commit 39cddfb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/sorcery/controller/submodules/password_expiration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module InstanceMethods
# To be used as before_filter.
# If password is expired, the failure callback will be called.
def require_valid_password
if logged_in? && current_user.need_password_changed?
if logged_in? && current_user.password_expired?
session[:return_to_url] = request.url if Config.save_return_to_url && request.get?
self.send(Config.change_password_action)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/sorcery/model/submodules/password_expiration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ def define_password_expiration_datamapper_fields
end

module InstanceMethods
def need_password_changed?
def password_expired?
expired_if_before_date = self.class.sorcery_config.password_expiration_time_period.ago
_password_changed_at = self.send(sorcery_config.password_changed_at_attribute_name)
_password_changed_at.nil? || (_password_changed_at < expired_if_before_date)
end

def need_password_changed!
def expire_password!
expiration_date = self.class.sorcery_config.password_expiration_time_period.ago
self.send("#{sorcery_config.password_changed_at_attribute_name}=", expiration_date)
self.sorcery_save
Expand Down
2 changes: 1 addition & 1 deletion spec/active_record/controller_password_expiration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

before(:each) do
create_new_user
@user.need_password_changed!
@user.expire_password!
login_user
end

Expand Down
10 changes: 5 additions & 5 deletions spec/shared_examples/user_password_expiration_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@

Timecop.travel(before_expiration)

expect(@user.need_password_changed?).to be_false
expect(@user.password_expired?).to be_false

Timecop.travel(after_expiration)

expect(@user.need_password_changed?).to be_true
expect(@user.password_expired?).to be_true
end

it 'can force a user to need password changed' do
expect(@user.need_password_changed?).to be_false
expect(@user.password_expired?).to be_false

@user.need_password_changed!
@user.expire_password!

expect(@user.need_password_changed?).to be_true
expect(@user.password_expired?).to be_true
end

it "updates a user's password" do
Expand Down

0 comments on commit 39cddfb

Please sign in to comment.