Module: Answers::Testing::ControllerMacros::Authentication
- Defined in:
- lib/answers/testing/controller_macros/authentication.rb
Class Method Summary collapse
Instance Method Summary collapse
- #answers_login_with(*roles) ⇒ Object
- #answers_login_with_factory(factory) ⇒ Object
- #factory_user(factory) ⇒ Object
- #mock_user(roles) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
5 6 7 |
# File 'lib/answers/testing/controller_macros/authentication.rb', line 5 def self.extended(base) base.send :include, Devise::TestHelpers end |
Instance Method Details
#answers_login_with(*roles) ⇒ Object
9 10 11 |
# File 'lib/answers/testing/controller_macros/authentication.rb', line 9 def answers_login_with(*roles) mock_user roles end |
#answers_login_with_factory(factory) ⇒ Object
13 14 15 |
# File 'lib/answers/testing/controller_macros/authentication.rb', line 13 def answers_login_with_factory(factory) factory_user factory end |
#factory_user(factory) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/answers/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] sign_in logged_in_user end 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/answers/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 'Answers::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_answers_users!).and_return false controller.should_receive(:authenticate_answers_user!).and_return true controller.should_receive(:restrict_plugins).and_return true controller.should_receive(:allow_controller?).and_return controller.stub(:answers_user?).and_return true controller.stub(:current_answers_user).and_return logged_in_user end end |