Sha256: 2381299ec18d3397d8e6b23fb2c1b2735d185808cf44570355874875d103b5f4

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 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" }
    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" }
    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" }); <%= singular_table_name %>
  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/html/sessions_controller_test.rb.tt
authentication-zero-2.3.1 lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt
authentication-zero-2.3.0 lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt