rufus-jig 0.1.23 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.rspec +1 -0
  2. data/CHANGELOG.txt +8 -0
  3. data/README.rdoc +41 -11
  4. data/Rakefile +37 -12
  5. data/TODO.txt +6 -3
  6. data/lib/rufus/jig/adapters/em.rb +21 -24
  7. data/lib/rufus/jig/adapters/net.rb +3 -4
  8. data/lib/rufus/jig/adapters/net_persistent.rb +26 -7
  9. data/lib/rufus/jig/adapters/patron.rb +25 -10
  10. data/lib/rufus/jig/couch.rb +199 -36
  11. data/lib/rufus/jig/http.rb +183 -90
  12. data/lib/rufus/jig/path.rb +4 -4
  13. data/lib/rufus/jig/version.rb +1 -1
  14. data/rufus-jig.gemspec +55 -34
  15. data/spec/couch/attachements_spec.rb +113 -0
  16. data/spec/couch/basic_auth_spec.rb +75 -0
  17. data/spec/couch/conditional_spec.rb +178 -0
  18. data/spec/couch/continuous.rb +97 -0
  19. data/spec/couch/couch_spec.rb +64 -0
  20. data/spec/couch/db_spec.rb +366 -0
  21. data/{test → spec/couch}/tweet.png +0 -0
  22. data/spec/couch/views_spec.rb +326 -0
  23. data/spec/couch_url.txt +2 -0
  24. data/spec/jig/basic_auth_spec.rb +51 -0
  25. data/spec/jig/conditional_spec.rb +76 -0
  26. data/spec/jig/delete_spec.rb +32 -0
  27. data/spec/jig/get_spec.rb +116 -0
  28. data/spec/jig/misc_spec.rb +120 -0
  29. data/spec/jig/new_spec.rb +95 -0
  30. data/spec/jig/parse_uri_spec.rb +139 -0
  31. data/spec/jig/post_spec.rb +79 -0
  32. data/spec/jig/prefix_spec.rb +51 -0
  33. data/spec/jig/put_spec.rb +68 -0
  34. data/spec/jig/timeout_spec.rb +94 -0
  35. data/{test → spec}/server.rb +14 -4
  36. data/spec/spec_helper.rb +61 -0
  37. data/spec/support/couch_helper.rb +14 -0
  38. data/spec/support/server_helper.rb +32 -0
  39. metadata +98 -43
  40. data/lib/rufus/jig/adapters/net_response.rb +0 -42
  41. data/test/base.rb +0 -53
  42. data/test/bm/bm0.rb +0 -49
  43. data/test/bm/bm1.rb +0 -43
  44. data/test/conc/put_vs_delete.rb +0 -28
  45. data/test/couch_base.rb +0 -52
  46. data/test/couch_url.txt +0 -1
  47. data/test/ct_0_couch.rb +0 -64
  48. data/test/ct_1_couchdb.rb +0 -204
  49. data/test/ct_2_couchdb_options.rb +0 -50
  50. data/test/ct_3_couchdb_views.rb +0 -106
  51. data/test/ct_4_attachments.rb +0 -126
  52. data/test/ct_5_couchdb_continuous.rb +0 -92
  53. data/test/cut_0_auth_couch.rb +0 -62
  54. data/test/test.rb +0 -28
  55. data/test/to.sh +0 -25
  56. data/test/tt_0_get_timeout.rb +0 -92
  57. data/test/ut_0_http_get.rb +0 -191
  58. data/test/ut_1_http_post.rb +0 -81
  59. data/test/ut_2_http_delete.rb +0 -42
  60. data/test/ut_3_http_put.rb +0 -105
  61. data/test/ut_4_http_prefix.rb +0 -50
  62. data/test/ut_5_http_misc.rb +0 -65
  63. data/test/ut_6_args.rb +0 -98
  64. data/test/ut_7_parse_uri.rb +0 -79
  65. data/test/ut_8_auth.rb +0 -37
@@ -1,81 +0,0 @@
1
-
2
- #
3
- # testing rufus-jig
4
- #
5
- # Sat Oct 31 23:27:02 JST 2009
6
- #
7
-
8
- require File.join(File.dirname(__FILE__), 'base')
9
-
10
-
11
- class UtHttpPostTest < Test::Unit::TestCase
12
-
13
- def setup
14
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567)
15
- @h.delete('/documents')
16
- end
17
- def teardown
18
- @h.close
19
- end
20
-
21
- def test_post
22
-
23
- b = @h.post(
24
- '/documents', '{"msg":"hello"}', :content_type => 'application/json')
25
-
26
- r = @h.last_response
27
-
28
- l = r.headers['Location']
29
-
30
- assert_equal 'created.', b
31
- assert_equal 201, r.status
32
- assert_not_nil l
33
-
34
- if l.match(/^http:\/\//)
35
- l = '/' + l.split('/')[3..-1].join('/')
36
- end
37
-
38
- assert_equal({ 'msg' => 'hello' }, @h.get(l))
39
- end
40
-
41
- def test_post_and_decode_body
42
-
43
- b = @h.post(
44
- '/documents?mirror=true', '{"msg":"hello world"}', :content_type => :json)
45
-
46
- assert_equal({ 'msg' => 'hello world' }, b)
47
-
48
- assert_equal 0, @h.cache.size
49
- end
50
-
51
- def test_post_and_cache
52
-
53
- b = @h.post(
54
- '/documents?etag=true', '{"msg":"hello world"}', :content_type => :json)
55
-
56
- assert_equal({ 'msg' => 'hello world' }, b)
57
-
58
- assert_equal 0, @h.cache.size
59
- end
60
-
61
- def test_post_long_stuff
62
-
63
- data = 'x' * 1000
64
-
65
- b = @h.post('/documents', data, :content_type => 'text/plain')
66
-
67
- r = @h.last_response
68
-
69
- assert_equal 201, r.status
70
- end
71
-
72
- def test_post_image
73
-
74
- data = File.read(File.join(File.dirname(__FILE__), 'tweet.png'))
75
-
76
- b = @h.post('/documents', data, :content_type => 'image/png')
77
-
78
- assert_equal 201, @h.last_response.status
79
- end
80
- end
81
-
@@ -1,42 +0,0 @@
1
-
2
- #
3
- # testing rufus-jig
4
- #
5
- # Sun Nov 1 11:59:20 JST 2009
6
- #
7
-
8
- require File.join(File.dirname(__FILE__), 'base')
9
-
10
-
11
- class UtHttpDeleteTest < Test::Unit::TestCase
12
-
13
- def setup
14
-
15
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567)
16
-
17
- r = @h.put(
18
- '/documents/xyz', 'data', :content_type => 'text/plain', :raw => true)
19
- end
20
-
21
- def teardown
22
-
23
- @h.close
24
- end
25
-
26
- def test_delete
27
-
28
- b = @h.delete('/documents/xyz')
29
-
30
- assert_equal 200, @h.last_response.status
31
- assert_equal({ 'deleted' => 'xyz' }, b)
32
- end
33
-
34
- def test_delete_raw
35
-
36
- r = @h.delete('/documents/xyz', :raw => true)
37
-
38
- assert_equal 200, r.status
39
- assert_equal "{\"deleted\":\"xyz\"}", r.body
40
- end
41
- end
42
-
@@ -1,105 +0,0 @@
1
-
2
- #
3
- # testing rufus-jig
4
- #
5
- # Sat Oct 31 23:27:02 JST 2009
6
- #
7
-
8
- require File.join(File.dirname(__FILE__), 'base')
9
-
10
-
11
- class UtHttpPutTest < Test::Unit::TestCase
12
-
13
- def setup
14
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567)
15
- @h.delete('/documents')
16
- end
17
- def teardown
18
- @h.close
19
- end
20
-
21
- def test_clean
22
-
23
- assert_nil @h.get('/documents/1234')
24
- end
25
-
26
- def test_put
27
-
28
- b = @h.put('/documents/1234', '{"msg":"hello"}', :content_type => 'application/json')
29
-
30
- assert_equal 201, @h.last_response.status
31
-
32
- assert_equal({ 'msg' => 'hello' }, @h.get('/documents/1234'))
33
- end
34
-
35
- def test_put_json
36
-
37
- r = @h.put(
38
- '/documents/5678',
39
- { 'msg' => 'hello' },
40
- :content_type => 'application/json')
41
-
42
- assert_equal 201, @h.last_response.status
43
-
44
- assert_equal({ 'msg' => 'hello' }, @h.get('/documents/5678'))
45
- end
46
-
47
- def test_put_colon_json
48
-
49
- b = @h.put(
50
- '/documents/abcd',
51
- { 'msg' => 'hello' },
52
- :content_type => :json)
53
-
54
- assert_equal 201, @h.last_response.status
55
-
56
- assert_equal({ 'msg' => 'hello' }, @h.get('/documents/abcd'))
57
- end
58
-
59
- def test_put_and_decode_body
60
-
61
- b = @h.put(
62
- '/documents/yyyy?mirror=true',
63
- '{"msg":"hello world"}',
64
- :content_type => :json)
65
-
66
- assert_equal({ 'msg' => 'hello world' }, b)
67
- assert_equal 0, @h.cache.size
68
- end
69
-
70
- def test_put_and_cache
71
-
72
- b = @h.put(
73
- '/documents/yyyy?etag=true',
74
- '{"msg":"hello world"}',
75
- :content_type => :json)
76
-
77
- assert_equal({ 'msg' => 'hello world' }, b)
78
- assert_equal 0, @h.cache.size
79
- end
80
-
81
- def test_put_conflict
82
-
83
- r = @h.put('/conflict', '')
84
-
85
- assert_equal true, r
86
- end
87
-
88
- def test_put_long_stuff
89
-
90
- data = 'x' * 5000
91
-
92
- b = @h.put('/documents/abcd', data, :content_type => 'image/png')
93
-
94
- assert_equal 201, @h.last_response.status
95
- end
96
-
97
- #def test_put_image
98
- # data = File.read(File.join(File.dirname(__FILE__), 'tweet.png'))
99
- # b = @h.put('/documents/img0', data, :content_type => 'image/png')
100
- # assert_equal 201, @h.last_response.status
101
- #end
102
- #
103
- # currently disabled since Patron 0.4.5 times out on that one
104
- end
105
-
@@ -1,50 +0,0 @@
1
-
2
- #
3
- # testing rufus-jig
4
- #
5
- # Sun Nov 1 13:00:46 JST 2009
6
- #
7
-
8
- require File.join(File.dirname(__FILE__), 'base')
9
-
10
-
11
- class UtHttpPrefixTest < Test::Unit::TestCase
12
-
13
- def setup
14
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567, :prefix => '/a/b/')
15
- end
16
- def teardown
17
- @h.close
18
- end
19
-
20
- def test_get
21
-
22
- b = @h.get('c')
23
-
24
- assert_equal 'C', b
25
-
26
- assert_equal({"/a/b/c"=>["\"123456123456\"", "C"]}, @h.cache)
27
- end
28
-
29
- def test_put
30
-
31
- b = @h.put('c', 'data')
32
-
33
- assert_equal 201, @h.last_response.status
34
- end
35
-
36
- def test_post
37
-
38
- b = @h.post('c', 'data')
39
-
40
- assert_equal 201, @h.last_response.status
41
- end
42
-
43
- def test_delete
44
-
45
- b = @h.delete('c')
46
-
47
- assert_equal 200, @h.last_response.status
48
- end
49
- end
50
-
@@ -1,65 +0,0 @@
1
-
2
- #
3
- # testing rufus-jig
4
- #
5
- # Sun Nov 1 13:00:46 JST 2009
6
- #
7
-
8
- require File.join(File.dirname(__FILE__), 'base')
9
-
10
-
11
- class UtHttpMiscTest < Test::Unit::TestCase
12
-
13
- def teardown
14
- @h.close if @h
15
- end
16
-
17
- def test_prefix_with_slash
18
-
19
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567, :prefix => '/a/b')
20
-
21
- assert_equal 'c', @h.get('/c')
22
- assert_equal 'C', @h.get('c')
23
- end
24
-
25
- def test_prefix_without_slash
26
-
27
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567, :prefix => 'a/b')
28
-
29
- assert_equal 'c', @h.get('/c')
30
- assert_equal 'C', @h.get('c')
31
- end
32
-
33
- def test_without_prefix
34
-
35
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567)
36
-
37
- assert_equal 'C', @h.get('/a/b/c')
38
- assert_equal 'C', @h.get('a/b/c')
39
- end
40
-
41
- def test_with_single_slash_prefix
42
-
43
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567, :prefix => '/')
44
-
45
- assert_equal 'C', @h.get('/a/b/c')
46
- assert_equal 'C', @h.get('a/b/c')
47
- end
48
-
49
- def test_with_empty_prefix
50
-
51
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567, :prefix => '')
52
-
53
- assert_equal 'C', @h.get('/a/b/c')
54
- assert_equal 'C', @h.get('a/b/c')
55
- end
56
-
57
- def test_no_prefix
58
-
59
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567, :prefix => '/a/b')
60
-
61
- assert_equal({ 'car' => 'Mercedes-Benz' }, @h.get('/document'))
62
- assert_equal(nil, @h.get('document'))
63
- end
64
- end
65
-
@@ -1,98 +0,0 @@
1
-
2
- #
3
- # testing rufus-jig
4
- #
5
- # Sun Nov 8 11:57:39 JST 2009
6
- #
7
-
8
- require File.join(File.dirname(__FILE__), 'base')
9
-
10
-
11
- class UtArgsTest < Test::Unit::TestCase
12
-
13
- def test_simple_uri
14
-
15
- h = Rufus::Jig::Http.new('http://127.0.0.1:5984')
16
-
17
- assert_equal 'http', h.scheme
18
- assert_equal '127.0.0.1', h.host
19
- assert_equal 5984, h.port
20
- assert_equal '', h._path
21
- assert_equal nil, h._query
22
- assert_equal nil, h.options[:basic_auth]
23
- end
24
-
25
- def test_uri_with_path_and_query
26
-
27
- h = Rufus::Jig::Http.new('http://127.0.0.1:5984/nada?a=b&c=d')
28
-
29
- assert_equal 'http', h.scheme
30
- assert_equal '127.0.0.1', h.host
31
- assert_equal 5984, h.port
32
- assert_equal '/nada', h._path
33
- assert_equal 'a=b&c=d', h._query
34
- assert_equal nil, h.options[:basic_auth]
35
- end
36
-
37
- def test_uri_with_basic_auth
38
-
39
- h = Rufus::Jig::Http.new('http://u:p@127.0.0.1:5984')
40
-
41
- assert_equal 'http', h.scheme
42
- assert_equal '127.0.0.1', h.host
43
- assert_equal 5984, h.port
44
- assert_equal '', h._path
45
- assert_equal nil, h._query
46
- assert_equal %w[ u p ], h.options[:basic_auth]
47
- end
48
-
49
- def test_host_port
50
-
51
- h = Rufus::Jig::Http.new('127.0.0.1', 5984)
52
-
53
- assert_equal 'http', h.scheme
54
- assert_equal '127.0.0.1', h.host
55
- assert_equal 5984, h.port
56
- assert_equal nil, h._path
57
- assert_equal nil, h._query
58
- assert_equal nil, h.options[:basic_auth]
59
- end
60
-
61
- def test_host_port_path
62
-
63
- h = Rufus::Jig::Http.new('127.0.0.1', 5984, '/banana')
64
-
65
- assert_equal 'http', h.scheme
66
- assert_equal '127.0.0.1', h.host
67
- assert_equal 5984, h.port
68
- assert_equal '/banana', h._path
69
- assert_equal nil, h._query
70
- assert_equal nil, h.options[:basic_auth]
71
- end
72
-
73
- def test_host_port_path_options
74
-
75
- h = Rufus::Jig::Http.new(
76
- '127.0.0.1', 5984, '/banana', :basic_auth => %w[ u p ])
77
-
78
- assert_equal 'http', h.scheme
79
- assert_equal '127.0.0.1', h.host
80
- assert_equal 5984, h.port
81
- assert_equal '/banana', h._path
82
- assert_equal nil, h._query
83
- assert_equal %w[ u p ], h.options[:basic_auth]
84
- end
85
-
86
- def test_uri_plus_path
87
-
88
- h = Rufus::Jig::Http.new('http://127.0.0.1:5984', '/banana')
89
-
90
- assert_equal 'http', h.scheme
91
- assert_equal '127.0.0.1', h.host
92
- assert_equal 5984, h.port
93
- assert_equal '/banana', h._path
94
- assert_equal nil, h._query
95
- assert_equal nil, h.options[:basic_auth]
96
- end
97
- end
98
-
@@ -1,79 +0,0 @@
1
- # encoding: utf-8
2
-
3
- #
4
- # testing rufus-jig
5
- #
6
- # Tue Jun 22 12:31:35 JST 2010
7
- #
8
-
9
- #require File.join(File.dirname(__FILE__), 'base')
10
- lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
11
- $:.unshift(lib) unless $:.include?(lib)
12
-
13
- require 'test/unit'
14
- require 'rufus/jig'
15
-
16
-
17
- class UtParseUriTest < Test::Unit::TestCase
18
-
19
- def test_parse_host
20
-
21
- assert_equal 'www.unifr.ch', Rufus::Jig.parse_host('http://www.unifr.ch')
22
- assert_equal 'mufg.jp', Rufus::Jig.parse_host('http://mufg.jp/大和')
23
- end
24
-
25
- def test_parse_uri
26
-
27
- assert_equal(
28
- 'http',
29
- Rufus::Jig.parse_uri('http://www.unifr.ch').scheme)
30
- assert_equal(
31
- 'https',
32
- Rufus::Jig.parse_uri('https://www.unifr.ch').scheme)
33
- assert_equal(
34
- 'www.unifr.ch',
35
- Rufus::Jig.parse_uri('http://www.unifr.ch').host)
36
- assert_equal(
37
- 'www.unifr.ch',
38
- Rufus::Jig.parse_uri('http://www.unifr.ch/').host)
39
- assert_equal(
40
- 'mufg.jp',
41
- Rufus::Jig.parse_uri('http://mufg.jp/大和').host)
42
- assert_equal(
43
- 8080,
44
- Rufus::Jig.parse_uri('http://mufg.jp:8080/大和').port)
45
- assert_equal(
46
- '/大和',
47
- Rufus::Jig.parse_uri('http://mufg.jp:8080/大和').path)
48
- assert_equal(
49
- 'nada=surf&rock=roll',
50
- Rufus::Jig.parse_uri('http://mufg.jp:8080/大和?nada=surf&rock=roll').query)
51
- assert_equal(
52
- '脳=電',
53
- Rufus::Jig.parse_uri('http://mufg.jp:8080/大和?脳=電').query)
54
- end
55
-
56
- def test_parse_uri_with_path
57
-
58
- assert_equal(
59
- nil,
60
- Rufus::Jig.parse_uri('/').host)
61
- end
62
-
63
- def test_parse_uri_with_auth
64
-
65
- assert_equal(
66
- 'admin',
67
- Rufus::Jig.parse_uri('http://admin:nimda@example.com').username)
68
- assert_equal(
69
- 'nimda',
70
- Rufus::Jig.parse_uri('http://admin:nimda@example.com').password)
71
- assert_equal(
72
- 'http',
73
- Rufus::Jig.parse_uri('http://admin:nimda@example.com').scheme)
74
- assert_equal(
75
- 'example.com',
76
- Rufus::Jig.parse_uri('http://admin:nimda@example.com').host)
77
- end
78
- end
79
-