Sha256: 5e63c7edccc1d19cf0899b25b34156efbc8f3046d0e1b368b69d7c07cc1726b4

Contents?: true

Size: 1.5 KB

Versions: 9

Compression:

Stored size: 1.5 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: "Secret1*3*5*" }, headers: { "User-Agent" => "App iOS" }

    assert_enqueued_email_with SessionMailer, :signed_in_notification, args: { session: @<%= singular_table_name %>.sessions.last }
    assert_response :created
  end

  test "should not sign in with wrong credentials" do
    post sign_in_url, params: { email: @<%= singular_table_name %>.email, password: "SecretWrong1*3" }, headers: { "User-Agent" => "App iOS" }
    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: "Secret1*3*5*" }, headers: { "User-Agent" => "App iOS" }); [<%= singular_table_name %>, response.headers["X-Session-Token"]]
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
authentication-zero-2.8.4 lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt
authentication-zero-2.8.3 lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt
authentication-zero-2.8.2 lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt
authentication-zero-2.8.1 lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt
authentication-zero-2.8.0 lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt
authentication-zero-2.7.0 lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt
authentication-zero-2.6.0 lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt
authentication-zero-2.5.1 lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt
authentication-zero-2.5.0 lib/generators/authentication/templates/test_unit/controllers/api/sessions_controller_test.rb.tt