Sha256: 1791044a337ec4451a197f28aadc0ca0fa6569cc2426947b02c7394dfa993864

Contents?: true

Size: 978 Bytes

Versions: 5

Compression:

Stored size: 978 Bytes

Contents

require "test_helper"

class SessionsControllerTest < ActionDispatch::IntegrationTest
  setup do
    @<%= singular_table_name %> = <%= table_name %>(:lazaro_nixon)
  end

  test "should sign in" do
    post sign_in_url, params: { email: @<%= singular_table_name %>.email, password: "secret123" }
    assert_response :success
  end

  test "should not sign in with wrong credentials" do
    post sign_in_url, params: { email: @<%= singular_table_name %>.email, password: "wrong_password" }
    assert_response :unauthorized
  end

  test "should sign out" do
    <%= singular_table_name %>, token = sign_in_as(@<%= singular_table_name %>)

    delete sign_out_url, headers: { "Authorization" => "Bearer #{token}" }
    assert_response :no_content
  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/sessions_controller_test.rb.tt
authentication-zero-1.0.1 lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt
authentication-zero-1.0.0 lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt
authentication-zero-0.0.24 lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt
authentication-zero-0.0.23 lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt