Sha256: 37a2df42565ad1cedab486d8f2afd9ced96fa1f04f363da17bca38b88dee0832

Contents?: true

Size: 1.62 KB

Versions: 5

Compression:

Stored size: 1.62 KB

Contents

require "test_helper"

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

  test "should get index" do
    sign_in_as @<%= singular_table_name %>

    get sessions_url
    assert_response :success
  end

  test "should get new" do
    get sign_in_url
    assert_response :success
  end

  test "should sign in" do
    post sign_in_url, params: { email: @<%= singular_table_name %>.email, password: "Secret123456" }, headers: { "User-Agent" => "Firefox" }
    assert_enqueued_email_with SessionMailer, :signed_in_notification, args: { session: @<%= singular_table_name %>.sessions.last }

    assert_redirected_to root_url

    get root_url
    assert_response :success
  end

  test "should not sign in with wrong credentials" do
    post sign_in_url, params: { email: @<%= singular_table_name %>.email, password: "SecretWrong123" }, headers: { "User-Agent" => "Firefox" }
    assert_redirected_to sign_in_url(email_hint: @<%= singular_table_name %>.email)
    assert_equal "That email or password is incorrect", flash[:alert]

    get root_url
    assert_redirected_to sign_in_path
  end

  test "should sign out" do
    sign_in_as @<%= singular_table_name %>

    delete session_url(@<%= singular_table_name %>.sessions.last)
    assert_redirected_to sessions_path

    follow_redirect!
    assert_redirected_to sign_in_path
  end

  def sign_in_as(<%= singular_table_name %>)
    post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "Secret123456" }, headers: { "User-Agent" => "Firefox" }); <%= singular_table_name %>
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
authentication-zero-2.4.0 lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt
authentication-zero-2.3.6 lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt
authentication-zero-2.3.5 lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt
authentication-zero-2.3.4 lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt
authentication-zero-2.3.3 lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt