Module: SimpleAuth::RSpec
- Defined in:
- lib/simple_auth/rspec.rb
Instance Method Summary collapse
-
#simple_auth(options = {}) ⇒ Object
A simple helper to stub current session options.
Instance Method Details
#simple_auth(options = {}) ⇒ Object
A simple helper to stub current session options.
simple_auth(:user => User.first) # the most common case
simple_auth(:authorized => false)
simple_auth(:session => mock("current_session", :valid? => false))
This is how you set it up:
# spec/spec_helper.rb
require "simple_auth/rspec"
RSpec.configure {|c| c.include SimpleAuth::RSpec, :type => :controller}
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/simple_auth/rspec.rb', line 15 def simple_auth( = {}) .reverse_merge!({ :session => double("current_session").as_null_object, :authorized => true, :user => double("current_user").as_null_object }) controller.stub({ :current_user => [:user], :authorized? => [:authorized], :current_session => [:session] }) end |