Sha256: ead1070a8119a3ffdeca211717edd95e46f935615b92053ed458fcf43d4e1d97

Contents?: true

Size: 948 Bytes

Versions: 3

Compression:

Stored size: 948 Bytes

Contents

require "test_helper"

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

  test "should update email" do
    patch email_url, params: { email: "new_email@hey.com" }, headers: { "Authorization" => "Bearer #{@token}" }
    assert_response :success
  end

  test "should not update email without sudo" do
    @<%= singular_table_name %>.sessions.last.update! sudo_at: 1.day.ago

    patch email_url, params: { email: "new_email@hey.com" }, headers: { "Authorization" => "Bearer #{@token}" }

    assert_response :forbidden
    assert_equal "Enter your password to continue", response.parsed_body["error"]
  end

  def sign_in_as(<%= singular_table_name %>)
    post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret123456" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
authentication-zero-2.3.2 lib/generators/authentication/templates/test_unit/controllers/api/emails_controller_test.rb.tt
authentication-zero-2.3.1 lib/generators/authentication/templates/test_unit/controllers/api/emails_controller_test.rb.tt
authentication-zero-2.3.0 lib/generators/authentication/templates/test_unit/controllers/api/emails_controller_test.rb.tt