Sha256: ada4d4ebae3b2884342dc80c1e34e45016ef44ccc3575cd324bf1c6b8fb4deb5

Contents?: true

Size: 1.02 KB

Versions: 115

Compression:

Stored size: 1.02 KB

Contents

module ClearanceMatchers
  class DenyAccessMatcher
    include Shoulda::ActionController::Matchers

    def initialize(context)
      @context = context
    end

    def matches?(controller)
      if @method
        @context.__send__(@method, *@args)
      end

      begin
        if @flash
          controller.should set_the_flash.to(@flash)
        else
          controller.should_not set_the_flash
        end

        url = controller.__send__(:sign_in_url)
        controller.should redirect_to(url).in_context(@context)

        true
      rescue RSpec::Expectations::ExpectationNotMetError => failure
        @failure_message = failure.message
        false
      end
    end

    def flash(flash)
      @flash = flash
      self
    end

    def on(method, *args)
      @method = method
      @args   = args
      self
    end

    def failure_message_for_should
      @failure_message
    end
  end

  def deny_access
    DenyAccessMatcher.new(self)
  end
end


RSpec.configure do |config|
  config.include ClearanceMatchers
end

Version data entries

115 entries across 115 versions & 2 rubygems

Version Path
saucy-0.10.10 spec/support/clearance_matchers.rb
saucy-0.10.9 spec/support/clearance_matchers.rb
saucy-0.10.8 spec/support/clearance_matchers.rb
saucy-0.10.7 spec/support/clearance_matchers.rb
saucy-0.10.6 spec/support/clearance_matchers.rb
saasy-0.0.2.alpha3 spec/support/clearance_matchers.rb
saasy-0.0.2.alpha2 spec/support/clearance_matchers.rb
saasy-0.0.2.alpha1 spec/support/clearance_matchers.rb
saucy-0.10.5 spec/support/clearance_matchers.rb
saucy-0.10.4 spec/support/clearance_matchers.rb
saucy-0.10.3 spec/support/clearance_matchers.rb
saucy-0.10.2 spec/support/clearance_matchers.rb
saucy-0.10.1 spec/support/clearance_matchers.rb
saucy-0.10.0 spec/support/clearance_matchers.rb
saucy-0.9.1 spec/support/clearance_matchers.rb
saucy-0.9.0 spec/support/clearance_matchers.rb
saucy-0.8.5 spec/support/clearance_matchers.rb
saucy-0.8.4 spec/support/clearance_matchers.rb
saucy-0.8.3 spec/support/clearance_matchers.rb
saasy-0.0.1 spec/support/clearance_matchers.rb