Sha256: 34ba899c7e6fdb144b4efff9b729d832b4657d5d5a172024ec944c577bfe719f

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

require "test_helper"

class SessionsControllerTest < ActionDispatch::IntegrationTest
  setup do
    @<%= singular_table_name %> = <%= table_name %>(:lazaro_nixon)
  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: "secret123" }
    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: "wrong_password" }
    assert_redirected_to sign_in_url(email_hint: @<%= singular_table_name %>.email)
    assert_equal "Invalid email or password", flash[:alert]

    get root_url
    assert_redirected_to sign_in_path
    assert_equal "You need to sign in or sign up before continuing", flash[:alert]
  end

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

    delete sign_out_url
    assert_redirected_to sign_in_path

    get root_path
    assert_redirected_to sign_in_path
    assert_equal "You need to sign in or sign up before continuing", flash[:alert]
  end

  def sign_in_as(<%= singular_table_name %>)
    post(sign_in_url, params: { email: <%= singular_table_name %>.email, password: "secret123" }); user
  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/html/sessions_controller_test.rb.tt
authentication-zero-1.0.1 lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt
authentication-zero-1.0.0 lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt
authentication-zero-0.0.24 lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt
authentication-zero-0.0.23 lib/generators/authentication/templates/test_unit/controllers/html/sessions_controller_test.rb.tt