File: test_redirect_verb_handling.rb

package info (click to toggle)
libwww-mechanize-ruby 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 956 kB
  • ctags: 883
  • sloc: ruby: 6,621; makefile: 4
file content (49 lines) | stat: -rw-r--r-- 1,544 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require "helper"

class TestRedirectNotGetOrHead < Test::Unit::TestCase
  def setup
    @agent = Mechanize.new
  end

  def test_to_s
    page = MechTestHelper.fake_page(@agent)
    error = Mechanize::RedirectNotGetOrHeadError.new(page, :put)
    assert_match(/put/, error.to_s)
  end

  def test_head_redirect_results_in_head_request
    page = @agent.head('http://localhost/redirect')
    assert_equal(page.uri.to_s, 'http://localhost/verb')
    assert_equal(page.body, "method: HEAD")
  end

  def test_get_takes_a_verb
    page = @agent.get(:url => 'http://localhost/redirect', :verb => :head)
    assert_equal(page.uri.to_s, 'http://localhost/verb')
    assert_equal(page.body, "method: HEAD")
  end

  def test_get_redirect_results_in_get_request
    page = @agent.get('http://localhost/redirect')
    assert_equal(page.uri.to_s, 'http://localhost/verb')
    assert_equal(page.body, "method: GET")
  end

  def test_post_redirect_results_in_get_request
    page = @agent.post('http://localhost/redirect')
    assert_equal(page.uri.to_s, 'http://localhost/verb')
    assert_equal(page.body, "method: GET")
  end

  def test_put_redirect_results_in_get_request
    page = @agent.put('http://localhost/redirect', 'foo')
    assert_equal(page.uri.to_s, 'http://localhost/verb')
    assert_equal(page.body, "method: GET")
  end

  def test_delete_redirect_results_in_get_request
    page = @agent.delete('http://localhost/redirect')
    assert_equal(page.uri.to_s, 'http://localhost/verb')
    assert_equal(page.body, "method: GET")
  end
end