Sha256: 64ad58377b0270098e8e7e4ca3a79f0ec32db3a140dc477d9f56b849d453d815

Contents?: true

Size: 1.66 KB

Versions: 5

Compression:

Stored size: 1.66 KB

Contents

require 'declarative_authorization/maintenance'

module Alchemy
  module Specs

    # Helpers for integration specs
    #
    # This file is included in rspec integration/request tests.
    #
    module IntegrationHelpers
      include ::Authorization::TestHelper

      # Shortcut method for:
      #
      #   * create_admin_user
      #   * login_into_alchemy
      #
      def authorize_as_admin
        create_admin_user
        login_into_alchemy
      end

      # Capybara actions to login into Alchemy Backend
      #
      # You should have a admin user before loggin in.
      #
      # See: create_admin_user method
      #
      def login_into_alchemy
        # Ensure that phantomjs has always the same browser language.
        if Capybara.current_driver == :poltergeist
          page.driver.headers = { 'Accept-Language' => 'en' }
        end
        visit login_path
        fill_in('user_login', :with => 'jdoe')
        fill_in('user_password', :with => 's3cr3t')
        click_on('Login')
      end

      # Load additional authorization_rules for specs.
      #
      # For some strange reason, this isn't done automatically while running the specs
      #
      def load_authorization_rules
        instance = Alchemy::Auth::Engine.get_instance
        instance.load(File.join(File.dirname(__FILE__), '../../dummy', 'config/authorization_rules.rb'))
      end

      # Creates an admin user in a way it works
      #
      # You should create it once in a before block
      #
      # === Example:
      #
      #   before do
      #     create_admin_user
      #   end
      #
      def create_admin_user
        FactoryGirl.create(:admin_user)
      end

    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alchemy_cms-2.8.1 spec/support/alchemy/integration_helpers.rb
alchemy_cms-2.7.3 spec/support/alchemy/integration_helpers.rb
alchemy_cms-2.7.2 spec/support/alchemy/integration_helpers.rb
alchemy_cms-2.7.1 spec/support/alchemy/integration_helpers.rb
alchemy_cms-2.7.0 spec/support/alchemy/integration_helpers.rb