Sha256: f4e883acffe31e9d5052b66938b93ea31be2cf23b59d323547051ebd8bfa898c

Contents?: true

Size: 1.57 KB

Versions: 28

Compression:

Stored size: 1.57 KB

Contents

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

      # 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:
        attr_reader :failure_message, :negative_failure_message

        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

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

        private

        def redirects_to_url?
          begin
            @context.send(:assert_redirected_to, url)
            @negative_failure_message = "Didn't expect to redirect to #{url}"
            true
          rescue Shoulda::Matchers::AssertionError => error
            @failure_message = error.message
            false
          end
        end

        def url
          if @url_block
            @context.instance_eval(&@url_block)
          else
            @url
          end
        end
      end
    end
  end
end

Version data entries

28 entries across 20 versions & 4 rubygems

Version Path
challah-1.0.0.beta vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-0.9.1.beta.3 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
devise_sociable-0.1.0 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-0.9.1.beta vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-0.9.0 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
shoulda-matchers-1.4.2 lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.4.1/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.2.0/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/shoulda-matchers-1.4.1/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/shoulda-matchers-1.2.0/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-0.8.3 vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-0.8.3 vendor/bundle/gems/shoulda-matchers-1.4.1/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
shoulda-matchers-1.4.1 lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
shoulda-matchers-1.4.0 lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-0.8.1 vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/shoulda-matchers-1.2.0/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-rolls-0.1.0 vendor/bundle/gems/shoulda-matchers-1.2.0/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb
challah-rolls-0.1.0 vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb