Module: Refinery::Testing::ControllerMacros::Authentication

Defined in:
lib/refinery/testing/controller_macros/authentication.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



5
6
7
# File 'lib/refinery/testing/controller_macros/authentication.rb', line 5

def self.extended(base)
  base.send :include, Devise::TestHelpers
end

Instance Method Details

#factory_user(factory) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/refinery/testing/controller_macros/authentication.rb', line 41

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

#login_refinery_superuserObject



59
60
61
62
# File 'lib/refinery/testing/controller_macros/authentication.rb', line 59

def 
  Refinery.deprecate :login_refinery_superuser, :when => '2.2', :replacement => 'refinery_login_with :refinery_superuser'
   :refinery_superuser
end

#login_refinery_translatorObject



64
65
66
67
# File 'lib/refinery/testing/controller_macros/authentication.rb', line 64

def 
  Refinery.deprecate :login_refinery_translator, :when => '2.2', :replacement => 'refinery_login_with :refinery_translator'
   :refinery_translator
end

#login_refinery_userObject



54
55
56
57
# File 'lib/refinery/testing/controller_macros/authentication.rb', line 54

def 
  Refinery.deprecate :login_refinery_user, :when => '2.2', :replacement => 'refinery_login_with :refinery_user'
   :refinery_user
end

#login_userObject



49
50
51
52
# File 'lib/refinery/testing/controller_macros/authentication.rb', line 49

def 
  Refinery.deprecate :login_user, :when => '2.2', :replacement => 'refinery_login_with :user'
   :user
end

#mock_user(roles) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/refinery/testing/controller_macros/authentication.rb', line 17

def mock_user(roles)
  let(:controller_permission) { true }
  roles = handle_deprecated_roles! roles
  let(:logged_in_user) do
    user = double 'Refinery::User', :username => 'Joe Fake'

    roles.each do |role|
      user.stub(:has_role?).with(role).and_return true
    end
    user.stub(:has_role?).with(:superuser).and_return false if roles.exclude? :superuser

    user
  end

  before do
    controller.should_receive(:require_refinery_users!).and_return false
    controller.should_receive(:authenticate_refinery_user!).and_return true
    controller.should_receive(:restrict_plugins).and_return true
    controller.should_receive(:allow_controller?).and_return controller_permission
    controller.stub(:refinery_user?).and_return true
    controller.stub(:current_refinery_user).and_return logged_in_user
  end
end

#refinery_login_with(*roles) ⇒ Object



9
10
11
# File 'lib/refinery/testing/controller_macros/authentication.rb', line 9

def (*roles)
  mock_user roles
end

#refinery_login_with_factory(factory) ⇒ Object



13
14
15
# File 'lib/refinery/testing/controller_macros/authentication.rb', line 13

def (factory)
  factory_user factory
end