Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubrohleder committed Sep 10, 2015
1 parent d33bcdb commit cee20d9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/devise_token_auth/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def edit
# ensure that user is confirmed
@resource.skip_confirmation! if @resource.devise_modules.include?(:confirmable) && !@resource.confirmed_at

# allow user to change password without current_password
# allow user to change password once without current_password
@resource.allow_password_change = true;

@resource.save!
Expand Down
40 changes: 40 additions & 0 deletions test/controllers/devise_token_auth/passwords_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase
assert_equal @data["errors"], [I18n.t("devise_token_auth.passwords.missing_email")]
end
end

describe 'not redirect_url should return 401' do
before do
@auth_headers = @resource.create_new_auth_token
Expand Down Expand Up @@ -300,6 +301,45 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase
end
end

describe 'success with after password reset' do
before do
xhr :post, :create, {
email: @resource.email,
redirect_url: @redirect_url
}

@mail = ActionMailer::Base.deliveries.last
@mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1])
@mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1]

xhr :get, :edit, {
reset_password_token: @mail_reset_token,
redirect_url: @mail_redirect_url
}

@auth_headers = @resource.create_new_auth_token
request.headers.merge!(@auth_headers)
@new_password = Faker::Internet.password

xhr :put, :update, {
password: @new_password,
password_confirmation: @new_password
}

@data = JSON.parse(response.body)
@allow_password_change = @resource.allow_password_change
@resource.reload
end

test "request should be successful" do
assert_equal 200, response.status
end

test "sets allow_password_change false" do
assert_equal false, @allow_password_change
end
end

describe 'current password mismatch error' do
before do
@auth_headers = @resource.create_new_auth_token
Expand Down

0 comments on commit cee20d9

Please sign in to comment.