Sha256: d1d3c1ee04cebbbda6c2d5d03d32d8f35f7fa8911b5a15119098149944fa5280

Contents?: true

Size: 1.69 KB

Versions: 21

Compression:

Stored size: 1.69 KB

Contents

require 'test_helper'

module Workarea
  module Admin
    class ImpersonationsIntegrationTest < Workarea::IntegrationTest
      include Admin::IntegrationTest
      setup :set_user
      setup :login_admin_user

      def set_user
        @user = create_user
      end

      def login_admin_user
        admin_user.update!(password: 'W3bl1nc!')

        post storefront.login_path,
          params: { email: admin_user.email, password: 'W3bl1nc!' }
      end

      def test_can_create_an_impersonation
        previous_user_id = session[:user_id]

        post admin.impersonations_path, params: { user_id: @user.id }

        assert(response.redirect?)
        assert_equal(@user.id.to_s, session[:user_id])
        assert_equal(previous_user_id, session[:admin_id])
      end

      def test_does_not_allow_impersonating_another_admin
        @user.update_attributes!(admin: true)

        assert_raises Admin::InvalidImpersonation do
          post admin.impersonations_path, params: { user_id: @user.id }
        end
      end

      def test_logs_the_impersonation_info_with_the_user
        previous_user_id = session[:user_id]
        post admin.impersonations_path, params: { user_id: @user.id }
        @user.reload

        assert_equal(previous_user_id, @user.last_impersonated_by_id)
        assert(@user.last_impersonated_at.present?)
      end

      def test_can_destroy_an_impersonation
        previous_user_id = session[:user_id]

        post admin.impersonations_path, params: { user_id: @user.id }
        delete admin.impersonations_path

        assert(response.redirect?)
        assert_equal(previous_user_id, session[:user_id])
        assert(session[:admin_id].blank?)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
workarea-admin-3.5.19 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.18 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.17 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.16 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.15 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.14 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.13 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.12 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.11 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.10 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.9 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.8 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.7 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.6 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.5 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.4 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.3 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.2 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.1 test/integration/workarea/admin/impersonations_integration_test.rb
workarea-admin-3.5.0 test/integration/workarea/admin/impersonations_integration_test.rb