Sha256: 201b3b208f13a4d8f7ad4943a971720d693f1f3b1297268a776aa31712c872da

Contents?: true

Size: 873 Bytes

Versions: 5

Compression:

Stored size: 873 Bytes

Contents

module SimpleAuth
  module RSpec
    # 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}
    #
    def simple_auth(options = {})
      options.reverse_merge!({
        :session => mock("current_session").as_null_object,
        :authorized => true,
        :user => mock("current_user").as_null_object
      })

      controller.stub({
        :current_user => options[:user],
        :authorized? => options[:authorized],
        :current_session => options[:session]
      })
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
simple_auth-1.5.0 lib/simple_auth/rspec.rb
simple_auth-1.4.5 lib/simple_auth/rspec.rb
simple_auth-1.4.4 lib/simple_auth/rspec.rb
simple_auth-1.4.3 lib/simple_auth/rspec.rb
simple_auth-1.4.2 lib/simple_auth/rspec.rb