Sha256: 4fdac6ec44258ff6013c79a3045de2a2ebf0c00788d7872fe659e20eb8952199

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require "test_helper"

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

  test "should get index" do
    get sessions_url, headers: { "Authorization" => "Bearer #{@token}" }
    assert_response :success
  end

  test "should show session" do
    get session_url(@<%= singular_table_name %>.sessions.last), headers: { "Authorization" => "Bearer #{@token}" }
    assert_response :success
  end

  test "should sign in" do
    post sign_in_url, params: { email: @<%= singular_table_name %>.email, password: "secret123" }
    assert_response :created
  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
    delete session_url(@<%= singular_table_name %>.sessions.last), 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.headers["X-Session-Token"]]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authentication-zero-2.0.0 lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt