Sha256: ad28c09d2d464f0b5d2d721f77a4276ddb6d4e8bb18d6841bc28a530cdfc2a21

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

Stored size: 1.52 KB

Contents

require 'rest-core/test'

describe RC::FollowRedirect do
  before do
    @dry = RC::Dry.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
      mock(dry).call(anything){ |env|
        env.merge(RC::RESPONSE_STATUS => status,
                  RC::RESPONSE_HEADERS => {'LOCATION' => 'location'})
      }
      app.call(RC::REQUEST_METHOD => :get,
               'max_redirects' => 0)[RC::RESPONSE_HEADERS]['LOCATION'].
                                                 should.eq 'location'
    end

    should "follow once: #{status}" do
      mock(dry).call(anything){ |env|
        env.merge(RC::RESPONSE_STATUS => status,
                  RC::RESPONSE_HEADERS => {'LOCATION' => 'location'})
      }.times(2)
      app.call(RC::REQUEST_METHOD => :get)[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
      mock(dry).call(anything){ |env|
        env.merge(RC::RESPONSE_STATUS => status,
                  RC::RESPONSE_HEADERS => {'LOCATION' => 'location'})
      }
      app.call(RC::REQUEST_METHOD => :get,
               'max_redirects' => 9)[RC::RESPONSE_HEADERS]['LOCATION'].
                                                 should.eq 'location'
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rest-core-1.0.3 test/test_follow_redirect.rb
rest-core-1.0.2 test/test_follow_redirect.rb
rest-core-1.0.1 test/test_follow_redirect.rb
rest-core-1.0.0 test/test_follow_redirect.rb