Sha256: 5ba5175b49bfbc72ca683c2db8374fd1270366d658e312912ca5a07366e09ff7

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

require "test_helper"

class PasswordsControllerTest < ActionDispatch::IntegrationTest
  setup do
    @<%= singular_table_name %>, @token = sign_in_as(<%= table_name %>(:lazaro_nixon))
  end

  test "should update password" do
    assert_enqueued_email_with PasswordMailer, :changed, args: { <%= singular_table_name %>: @<%= singular_table_name %> } do
      patch passwords_url, params: { current_password: "secret123", password: "new_password", password_confirmation: "new_password" }, headers: { "Authorization" => "Bearer #{@token}" }
    end

    assert_response :success
  end

  test "should not update password with wrong current password" do
    assert_no_enqueued_emails do
      patch passwords_url, params: { current_password: "wrong_password", password: "new_password", password_confirmation: "new_password" }, headers: { "Authorization" => "Bearer #{@token}" }
    end

    assert_response :bad_request
    assert_equal "The current password you entered is incorrect", response.parsed_body["error"]
  end

  def sign_in_as(<%= singular_table_name %>)
    post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" })
    [<%= singular_table_name %>, response.parsed_body["session_token"]]
  end  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
authentication-zero-1.0.2 lib/generators/authentication/templates/test_unit/controllers/api/passwords_controller_test.rb.tt
authentication-zero-1.0.1 lib/generators/authentication/templates/test_unit/controllers/api/passwords_controller_test.rb.tt
authentication-zero-1.0.0 lib/generators/authentication/templates/test_unit/controllers/api/passwords_controller_test.rb.tt
authentication-zero-0.0.24 lib/generators/authentication/templates/test_unit/controllers/api/passwords_controller_test.rb.tt
authentication-zero-0.0.23 lib/generators/authentication/templates/test_unit/controllers/api/passwords_controller_test.rb.tt