require 'integration_test_helper'
include Warden::Test::Helpers

class SignInFlowTest < ActionDispatch::IntegrationTest

  setup do
    Warden.test_mode!
    I18n.available_locales = [:en, :fr, :et]
    I18n.locale = :en
  end

  teardown do
    Warden.test_reset!
  end

  test "a browser should be able to sign in and be shown the home page" do
    sign_in
    assert_equal '/en', current_path
  end

  test "an admin should be able to sign in and be shown the admin page" do
    sign_in_admin
    assert_equal '/admin', path
  end

  # TODO: for some reason I could not get the admin login with the regular sign_in method to work
  # The current path never changed from /en so I had to resort to doing it this way:
  def sign_in_admin
    get "/en/users/sign_in"
    post '/en/users/sign_in', 'user[email]' => 'admin@test.com', 'user[password]' => '12345678'
    follow_redirect!
  end

end

require 'integration_test_helper'
include Warden::Test::Helpers

class SignInFlowTest < ActionDispatch::IntegrationTest

  setup do
    Warden.test_mode!
    I18n.available_locales = [:en, :fr, :et]
    I18n.locale = :en
  end

  teardown do
    Warden.test_reset!
  end

  def sign_out
    visit '/'
    within("div#above-header") do
      click_on("Logout")
    end
  end

  test "a browser should be able to sign in and be shown the home page" do
    sign_in
    assert_equal '/en', current_path
    sign_out
  end

  test "an admin should be able to sign in and be shown the admin page" do
    sign_in("admin@test.com")
    assert_equal '/admin', current_path
    sign_out
  end

  test "a browser visiting an admin page should be redirected to login in their locale" do
    visit '/admin'
    assert_equal '/en/users/sign_in', current_path
  end

end

Add new sign in test if browse direct to admin
Add new sign in test if browse direct to admin
