Created
February 14, 2015 01:29
-
-
Save dhulihan/494284bd4a87a5b17b23 to your computer and use it in GitHub Desktop.
RSpec 3 + FactoryGirl Login Stubs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # support/login.rb | |
| module RSpec | |
| module Core | |
| class ExampleGroup | |
| def login_admin | |
| u = FactoryGirl.create(:admin) | |
| login_as(u) | |
| allow_any_instance_of(ApplicationController).to receive(:check_permissions).and_return(true) | |
| end | |
| def login_user | |
| u = FactoryGirl.create(:user) | |
| group = FactoryGirl.create(:group, :name => "#{u.to_s}'s Group") | |
| login_as(u) | |
| end | |
| def login_as(user) | |
| configure_request | |
| # Stub on Class Level for capybara, since it doesn't use @controller | |
| if described_class | |
| allow_any_instance_of(described_class).to receive(:authenticate_user).and_return(true) | |
| allow_any_instance_of(described_class).to receive(:current_user).and_return(user) | |
| end | |
| end | |
| def login_anonymous | |
| configure_request | |
| end | |
| def current_user | |
| @controller.send(:current_user) | |
| end | |
| def bypass_captcha | |
| allow_any_instance_of(ApplicationController).to receive(:human?).and_return(true) | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment