Sha256: 50aa8f52d9cf28b6cb26892db9cb7099e200e3a4687cd0a858884d1ee3697b91

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

module Refinery
  module Authentication
    module Devise
      module ControllerMacros
        def self.extended(base)
          base.send :include, ::Devise::TestHelpers
        end

        def refinery_login_with_devise(*roles)
          roles = handle_deprecated_roles!(roles).flatten
          let(:logged_in_user) do
            FactoryGirl.create(:authentication_devise_user).tap do |user|
              roles.each do |role|
                user.add_role(role)
              end
            end
          end
          before do
            @request.env["devise.mapping"] = ::Devise.mappings[:authentication_devise_user]
            sign_in logged_in_user
          end
        end

        def factory_user(factory)
          let(:logged_in_user) { FactoryGirl.create(factory) }
          before do
            @request.env["devise.mapping"] = ::Devise.mappings[:authentication_devise_user]
            sign_in logged_in_user
          end
        end

        private
        def handle_deprecated_roles!(*roles)
          mappings = {
            :user => [],
            :refinery_user => [:refinery],
            :refinery_superuser => [:refinery, :superuser]
          }
          mappings[roles.flatten.first] || roles
        end
      end
    end
  end
end

RSpec.configure do |config|
  config.extend Refinery::Authentication::Devise::ControllerMacros, type: :controller
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
refinerycms-authentication-devise-1.0.4 spec/support/refinery/authentication/devise/controller_macros.rb
refinerycms-authentication-devise-1.0.3 spec/support/refinery/authentication/devise/controller_macros.rb
refinerycms-authentication-devise-1.0.2 spec/support/refinery/authentication/devise/controller_macros.rb
refinerycms-authentication-devise-1.0.1 spec/support/refinery/authentication/devise/controller_macros.rb
refinerycms-authentication-devise-1.0.0 spec/support/refinery/authentication/devise/controller_macros.rb