Sha256: 9ddde0a161aa595ccbaf8ba8897ff647aa7a87a93d100002fe1ecb0ab7c8fd50

Contents?: true

Size: 1.02 KB

Versions: 17

Compression:

Stored size: 1.02 KB

Contents

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

    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

17 entries across 17 versions & 1 rubygems

Version Path
saucy-0.14.3 spec/support/clearance_matchers.rb
saucy-0.14.2 spec/support/clearance_matchers.rb
saucy-0.14.1 spec/support/clearance_matchers.rb
saucy-0.14.0 spec/support/clearance_matchers.rb
saucy-0.13.3 spec/support/clearance_matchers.rb
saucy-0.13.2 spec/support/clearance_matchers.rb
saucy-0.13.1 spec/support/clearance_matchers.rb
saucy-0.13.0 spec/support/clearance_matchers.rb
saucy-0.12.5 spec/support/clearance_matchers.rb
saucy-0.12.4 spec/support/clearance_matchers.rb
saucy-0.12.3 spec/support/clearance_matchers.rb
saucy-0.12.2 spec/support/clearance_matchers.rb
saucy-0.12.1 spec/support/clearance_matchers.rb
saucy-0.12.0 spec/support/clearance_matchers.rb
saucy-0.11.5 spec/support/clearance_matchers.rb
saucy-0.11.3 spec/support/clearance_matchers.rb
saucy-0.11.2 spec/support/clearance_matchers.rb