Sha256: 905af799751a6e7c9e16ed6996c9726e084083c7b0e83825ac4a528de3886084

Contents?: true

Size: 1.5 KB

Versions: 91

Compression:

Stored size: 1.5 KB

Contents

module Shoulda # :nodoc:
  module ActionController # :nodoc:
    module Matchers

      # Ensures a controller redirected to the given url.
      #
      # Example:
      #
      #   it { should redirect_to('http://somewhere.com')  }
      #   it { should redirect_to(users_path)  }
      def redirect_to(url_or_description, &block)
        RedirectToMatcher.new(url_or_description, self, &block)
      end

      class RedirectToMatcher # :nodoc:

        def initialize(url_or_description, context, &block)
          if block
            @url_block = block
            @location = @url_or_description
          else
            @url = url_or_description
            @location = @url
          end
          @context = context
        end

        def in_context(context)
          @context = context
          self
        end

        def matches?(controller)
          @controller = controller
          redirects_to_url?
        end

        attr_reader :failure_message, :negative_failure_message

        def description
          "redirect to #{@location}"
        end

        private

        def redirects_to_url?
          @url = @context.instance_eval(&@url_block) if @url_block
          begin
            @context.send(:assert_redirected_to, @url)
            @negative_failure_message = "Didn't expect to redirect to #{@url}"
            true
          rescue Test::Unit::AssertionFailedError => error
            @failure_message = error.message
            false
          end
        end

      end

    end
  end
end

Version data entries

91 entries across 61 versions & 10 rubygems

Version Path
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
dirty_history-0.7.3 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
dirty_history-0.7.2 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
dirty_history-0.7.1 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
dirty_history-0.7.0 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
dirty_history-0.6.7 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
dirty_history-0.6.6 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
dirty_history-0.6.5 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
dirty_history-0.6.4 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
dirty_history-0.6.3 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
challah-0.6.2 vendor/bundle/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
dirty_history-0.6.2 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
dirty_history-0.6.1 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
dirty_history-0.6.0 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
challah-0.6.1 vendor/bundle/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
dirty_history-0.5.4 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb
challah-0.6.0 vendor/bundle/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/redirect_to_matcher.rb