Sha256: a86bc90736968c7195925c957b99e7af1dfdba0dea6c1a944b8aeba137f22d13

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 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
    patch password_url, params: { current_password: "secret123", password: "new_password", password_confirmation: "new_password" }, headers: { "Authorization" => "Bearer #{@token}" }
    assert_response :success
  end

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

    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.headers["X-Session-Token"]]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authentication-zero-2.2.8 lib/generators/authentication/templates/test_unit/controllers/api/passwords_controller_test.rb.tt