Skip to content

Commit

Permalink
Improve test coverage for password expirable (#254)
Browse files Browse the repository at this point in the history
* Add test cases for password expired controller

* Add .byebug_history to .gitignore

* Remove unneeded call that was for < Rails 4.0 support
  • Loading branch information
dillonwelch committed Mar 1, 2021
1 parent e280f14 commit 90f046b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -48,3 +48,5 @@ bin/*
gemfiles/*.lock

vendor/

.byebug_history
6 changes: 1 addition & 5 deletions app/controllers/devise/password_expired_controller.rb
Expand Up @@ -41,11 +41,7 @@ def skip_password_change
def resource_params
permitted_params = [:current_password, :password, :password_confirmation]

if params.respond_to?(:permit)
params.require(resource_name).permit(*permitted_params)
else
params[scope].slice(*permitted_params)
end
params.require(resource_name).permit(*permitted_params)
end

def scope
Expand Down
24 changes: 24 additions & 0 deletions test/controllers/test_password_expired_controller.rb
Expand Up @@ -21,11 +21,35 @@ class Devise::PasswordExpiredControllerTest < ActionController::TestCase
sign_in(@user)
end

test 'redirects on show if user not logged in' do
sign_out(@user)
get :show
assert_redirected_to :root
end

test 'redirects on show if user does not need password change' do
@user.update(password_changed_at: Time.zone.now)
get :show
assert_redirected_to :root
end

test 'should render show' do
get :show
assert_includes @response.body, 'Renew your password'
end

test 'redirects on update if user not logged in' do
sign_out(@user)
put :update
assert_redirected_to :root
end

test 'redirects on update if user does not need password change' do
@user.update(password_changed_at: Time.zone.now)
put :update
assert_redirected_to :root
end

test 'update password with default format' do
if Rails.gem_version < Gem::Version.new('5.0')
put :update,
Expand Down

0 comments on commit 90f046b

Please sign in to comment.