Sha256: 7dc1954a91c8e4b09e71d701537aa60aeb167ff7aeff94a0e4f0dc16d4233a23

Contents?: true

Size: 877 Bytes

Versions: 5

Compression:

Stored size: 877 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 => double("current_session").as_null_object,
        :authorized => true,
        :user => double("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-2.0.4 lib/simple_auth/rspec.rb
simple_auth-2.0.3 lib/simple_auth/rspec.rb
simple_auth-2.0.2 lib/simple_auth/rspec.rb
simple_auth-2.0.1 lib/simple_auth/rspec.rb
simple_auth-2.0.0 lib/simple_auth/rspec.rb