Sha256: 659a0953954745ef0e702843ca01ff25172baea235e45e8b543772f301aed145

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

require 'rest-core/test'

describe RC::FollowRedirect do
  before do
    @dry = Class.new do
      attr_accessor :status
      def call env
        yield(env.merge(RC::RESPONSE_STATUS  => status,
                        RC::RESPONSE_HEADERS => {'LOCATION' => 'location'}))
      end
    end.new
    @app = RC::FollowRedirect.new(dry, 1)
  end
  after do
    RR.verify
  end
  def dry; @dry; end
  def app; @app; end

  [301, 302, 303, 307].each do |status|
    should "not follow redirect if reached max_redirects: #{status}" do
      dry.status = status
      app.call(RC::REQUEST_METHOD => :get, 'max_redirects' => 0){ |res|
        res[RC::RESPONSE_HEADERS]['LOCATION'].should.eq 'location'
      }
    end

    should "follow once: #{status}" do
      dry.status = status
      app.call(RC::REQUEST_METHOD => :get){ |res|
        res[RC::RESPONSE_HEADERS]['LOCATION'].should.eq 'location'
      }
    end
  end

  [200, 201, 404, 500].each do |status|
    should "not follow redirect if it's not a redirect status: #{status}" do
      dry.status = status
      app.call(RC::REQUEST_METHOD => :get, 'max_redirects' => 9){ |res|
        res[RC::RESPONSE_HEADERS]['LOCATION'].should.eq 'location'
      }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rest-core-2.0.4 test/test_follow_redirect.rb
rest-core-2.0.3 test/test_follow_redirect.rb
rest-core-2.0.2 test/test_follow_redirect.rb
rest-core-2.0.1 test/test_follow_redirect.rb
rest-core-2.0.0 test/test_follow_redirect.rb