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,126 +0,0 @@
1
-
2
- #
3
- # testing rufus-jig
4
- #
5
- # Wed Feb 24 17:29:39 JST 2010
6
- #
7
-
8
- require File.join(File.dirname(__FILE__), 'couch_base')
9
-
10
-
11
- class CtAttachmentsTest < Test::Unit::TestCase
12
-
13
- def setup
14
-
15
- h = Rufus::Jig::Http.new(couch_url)
16
- begin
17
- h.delete('/rufus_jig_test')
18
- rescue Exception => e
19
- #p e
20
- end
21
-
22
- h.put('/rufus_jig_test', '')
23
- h.close
24
-
25
- @c = Rufus::Jig::Couch.new(couch_url, 'rufus_jig_test')
26
-
27
- @c.put('_id' => 'thedoc', 'function' => 'recipient for attachements')
28
- @d = @c.get('thedoc')
29
- end
30
-
31
- def teardown
32
-
33
- @c.close
34
- end
35
-
36
- def test_missing_content_type
37
-
38
- assert_raise ArgumentError do
39
-
40
- @c.attach(
41
- 'thedoc/message', 'this is a message', :content_type => 'text/plain')
42
- end
43
- end
44
-
45
- def test_attach
46
-
47
- r = @c.attach(
48
- 'thedoc', @d['_rev'], 'message', 'this is a message',
49
- :content_type => 'text/plain')
50
-
51
- #assert_not_equal @d['_rev'], r['_rev']
52
-
53
- assert_equal 'this is a message', @c.get('thedoc/message')
54
-
55
- assert_not_equal @d['_rev'], @c.get('thedoc')['_rev']
56
-
57
- r = @c.http.get('/rufus_jig_test/thedoc/message', :raw => true)
58
-
59
- assert_equal 200, r.status
60
- assert_equal 'text/plain', r.headers['Content-Type']
61
- end
62
-
63
- def test_attach_with_doc
64
-
65
- @c.attach(
66
- @d, 'message', 'this is a message', :content_type => 'text/plain')
67
-
68
- assert_equal 'this is a message', @c.get('thedoc/message')
69
- end
70
-
71
- def test_wrong_rev_on_attach
72
-
73
- assert_raise Rufus::Jig::HttpError do
74
- @c.attach(
75
- 'thedoc', '1-745aeb1d8eccafa88e635b813507608c',
76
- 'message', 'this is a message',
77
- :content_type => 'text/plain')
78
- end
79
- end
80
-
81
- def test_attach_image
82
-
83
- image = File.read(File.join(File.dirname(__FILE__), 'tweet.png'))
84
-
85
- @c.attach(
86
- 'thedoc', @d['_rev'], 'image', image, :content_type => 'image/png')
87
-
88
- r = @c.http.get('/rufus_jig_test/thedoc/image', :raw => true)
89
-
90
- assert_equal 200, r.status
91
- assert_equal 'image/png', r.headers['Content-Type']
92
-
93
- #File.open('out.png', 'wb') { |f| f.write(r.body) }
94
- end
95
-
96
- def test_detach
97
-
98
- attach_image
99
-
100
- d = @c.get('thedoc')
101
-
102
- r = @c.detach('thedoc', d['_rev'], 'image')
103
-
104
- assert_not_equal d['_rev'], r['_rev']
105
-
106
- assert_nil @c.get('thedoc/image')
107
- end
108
-
109
- def test_detach_fail
110
-
111
- attach_image
112
-
113
- assert_equal true, @c.detach(@d, 'image')
114
- end
115
-
116
- protected
117
-
118
- def attach_image
119
-
120
- image = File.read(File.join(File.dirname(__FILE__), 'tweet.png'))
121
-
122
- @c.attach(
123
- 'thedoc', @d['_rev'], 'image', image, :content_type => 'image/png')
124
- end
125
- end
126
-
@@ -1,92 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- #
4
- # testing rufus-jig
5
- #
6
- # Tue May 11 09:52:37 JST 2010
7
- #
8
-
9
- require File.join(File.dirname(__FILE__), 'couch_base')
10
-
11
-
12
- class CtCouchDbContinuousTest < Test::Unit::TestCase
13
-
14
- def setup
15
-
16
- h = Rufus::Jig::Http.new(couch_url)
17
-
18
- begin
19
- h.delete('/rufus_jig_test')
20
- rescue Exception => e
21
- #p e
22
- end
23
- h.put('/rufus_jig_test', '')
24
- h.close
25
-
26
- @c = Rufus::Jig::Couch.new(couch_url, 'rufus_jig_test')
27
- end
28
-
29
- def teardown
30
-
31
- @c.close
32
- end
33
-
34
- def test_on_change
35
-
36
- stack = []
37
-
38
- t = Thread.new do
39
- @c.on_change { |doc_id, deleted| stack << doc_id }
40
- end
41
-
42
- @c.put('_id' => 'angel0', 'name' => 'samael')
43
- @c.put('_id' => 'angel1', 'name' => 'raphael')
44
-
45
- sleep 0.150
46
- t.kill
47
-
48
- assert_equal 2, stack.size
49
- end
50
-
51
- def test_on_change_include_docs
52
-
53
- stack = []
54
-
55
- Thread.abort_on_exception = true
56
-
57
- t = Thread.new do
58
- @c.on_change { |doc_id, deleted, doc| stack << doc }
59
- end
60
-
61
- @c.put('_id' => 'angel2', 'name' => 'samael')
62
- @c.put('_id' => 'angel3', 'name' => 'ゆきひろ')
63
-
64
- sleep 0.150
65
- t.kill
66
-
67
- assert_equal 'ゆきひろ', stack[1]['name']
68
- end
69
-
70
- def test_on_change_include_docs_with_deleted
71
-
72
- stack = []
73
-
74
- Thread.abort_on_exception = true
75
-
76
- t = Thread.new do
77
- @c.on_change { |doc_id, deleted, doc| stack << [ doc_id, deleted ] }
78
- end
79
-
80
- @c.put('_id' => 'angel4', 'name' => 'samael')
81
- sleep 0.077
82
- @c.delete(@c.get('angel4'))
83
-
84
- sleep 0.154
85
- t.kill
86
-
87
- assert(
88
- [["angel4", false], ["angel4", true]] == stack ||
89
- [["angel4", true]] == stack)
90
- end
91
- end
92
-
@@ -1,62 +0,0 @@
1
-
2
- #
3
- # testing rufus-jig
4
- #
5
- # Sun Sep 26 18:26:15 JST 2010
6
- #
7
-
8
- require File.join(File.dirname(__FILE__), 'base')
9
-
10
-
11
- class UtAuthTest < Test::Unit::TestCase
12
-
13
- def setup
14
- @c = Rufus::Jig::Couch.new(
15
- '127.0.0.1', 4567, 'tcouch', :basic_auth => %w[ admin nimda ])
16
- end
17
- def teardown
18
- @c.close
19
- end
20
-
21
- def test_denied
22
-
23
- c = Rufus::Jig::Couch.new('127.0.0.1', 4567, 'tcouch')
24
-
25
- assert_raise Rufus::Jig::HttpError do
26
- c.get('.')
27
- end
28
- end
29
-
30
- def test_authorized
31
-
32
- assert_equal({ 'id' => 'nada' }, @c.get('.'))
33
- end
34
-
35
- def test_on_change
36
-
37
- res = nil
38
-
39
- t = Thread.new {
40
- @c.on_change do |id, deleted, doc|
41
- res = [ id, deleted, doc ]
42
- end
43
- }
44
-
45
- sleep 0.200
46
-
47
- t.kill
48
-
49
- assert_equal [ 'x', false, { 'hello' => 'world' } ], res
50
- end
51
-
52
- def test_on_change_denied
53
-
54
- c = Rufus::Jig::Couch.new('127.0.0.1', 4567, 'tcouch')
55
-
56
- assert_raise Rufus::Jig::HttpError do
57
- c.on_change do |id, deleted, doc|
58
- end
59
- end
60
- end
61
- end
62
-
@@ -1,28 +0,0 @@
1
-
2
- #
3
- # testing rufus-jig
4
- #
5
- # Sat Oct 31 22:44:08 JST 2009
6
- #
7
-
8
- def load_tests (prefix)
9
-
10
- dp = File.dirname(__FILE__)
11
-
12
- Dir.new(dp).entries.select { |e|
13
- e.match(/^#{prefix}\_.*\.rb$/)
14
- }.sort.each { |e|
15
- load("#{dp}/#{e}")
16
- }
17
- end
18
-
19
- set = if ARGV.include?('--all')
20
- %w[ ut ct ]
21
- elsif ARGV.include?('--couch')
22
- %w[ ct ]
23
- else
24
- %w[ ut cut ]
25
- end
26
-
27
- set.each { |prefix| load_tests(prefix) }
28
-
data/test/to.sh DELETED
@@ -1,25 +0,0 @@
1
- #!/bin/bash
2
-
3
- echo
4
- echo "================================================================================"
5
- echo "ruby test/ut_7_http_get_timeout.rb -- --patron"
6
- ruby -v
7
- echo
8
- ruby test/ut_7_http_get_timeout.rb -- --patron
9
-
10
- echo
11
- echo "================================================================================"
12
- echo "ruby test/ut_7_http_get_timeout.rb -- --net"
13
- ruby -v
14
- echo
15
- ruby test/ut_7_http_get_timeout.rb -- --net
16
-
17
- echo
18
- echo "================================================================================"
19
- echo "ruby test/ut_7_http_get_timeout.rb -- --em"
20
- ruby -v
21
- echo
22
- ruby test/ut_7_http_get_timeout.rb -- --em
23
-
24
- echo
25
-
@@ -1,92 +0,0 @@
1
-
2
- #
3
- # testing rufus-jig
4
- #
5
- # Tue Mar 9 11:09:43 JST 2010
6
- #
7
-
8
- require File.join(File.dirname(__FILE__), 'base')
9
-
10
-
11
- class UtHttpGetTimeoutTest < Test::Unit::TestCase
12
-
13
- #def setup
14
- #end
15
- def teardown
16
- @h.close
17
- end
18
-
19
- def test_timeout_after_1
20
-
21
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567, :timeout => 1)
22
-
23
- t = nil
24
-
25
- assert_raise Rufus::Jig::TimeoutError do
26
- t = Time.now
27
- @h.get('/later')
28
- end
29
-
30
- d = Time.now - t; dd = 4.0; assert d < dd, "after #{d} seconds (#{dd})"
31
- # grr, em-http-request forces me to use 4.0 (2.0 for the others)
32
- end
33
-
34
- def test_timeout_after_5
35
-
36
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567)
37
-
38
- t = nil
39
-
40
- assert_raise Rufus::Jig::TimeoutError do
41
- t = Time.now
42
- @h.get('/later')
43
- end
44
-
45
- d = Time.now - t; dd = 6.0; assert d < dd, "after #{d} seconds (#{dd})"
46
- end
47
-
48
- def test_timeout_after_15
49
-
50
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567, :timeout => 15)
51
-
52
- t = Time.now
53
-
54
- r = begin
55
- @h.get('/later')
56
- rescue Rufus::Jig::TimeoutError => e
57
- puts " :( timed out after #{Time.now - t} seconds"
58
- flunk
59
- end
60
-
61
- assert_equal 'later', r
62
- d = Time.now - t; dd = 8.0; assert d < dd, "after #{d} seconds (#{dd})"
63
- end
64
-
65
- def test_never_timeout
66
-
67
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567, :timeout => -1)
68
-
69
- t = Time.now
70
-
71
- r = @h.get('/later')
72
-
73
- assert_equal 'later', r
74
- d = Time.now - t; dd = 8.0; assert d < dd, "after #{d} seconds (#{dd})"
75
- end
76
-
77
- def test_request_timeout_after_1
78
-
79
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567, :timeout => 15)
80
-
81
- t = nil
82
-
83
- assert_raise Rufus::Jig::TimeoutError do
84
- t = Time.now
85
- @h.get('/later', :timeout => 1)
86
- end
87
-
88
- d = Time.now - t; dd = 4.0; assert d < dd, "after #{d} seconds (#{dd})"
89
- # grr, em-http-request forces me to use 4.0 (2.0 for the others)
90
- end
91
- end
92
-
@@ -1,191 +0,0 @@
1
- # encoding: utf-8
2
-
3
- #
4
- # testing rufus-jig
5
- #
6
- # Fri Oct 30 17:57:15 JST 2009
7
- #
8
-
9
- require File.join(File.dirname(__FILE__), 'base')
10
-
11
-
12
- class UtHttpGetTest < Test::Unit::TestCase
13
-
14
- def setup
15
- @h = Rufus::Jig::Http.new('127.0.0.1', 4567)
16
- end
17
- def teardown
18
- @h.close
19
- end
20
-
21
- def test_get_root
22
-
23
- r = @h.get('/')
24
-
25
- assert_equal 'hello', r
26
- end
27
-
28
- def test_get
29
-
30
- r = @h.get('/document')
31
-
32
- assert_equal Hash, r.class
33
- assert_equal 'Mercedes-Benz', r['car']
34
-
35
- assert_equal 0, @h.cache.size
36
- end
37
-
38
- def test_get_raw
39
-
40
- r = @h.get('/document', :raw => true)
41
-
42
- assert_equal 200, r.status
43
- assert_equal "{\"car\":\"Mercedes-Benz\"}", r.body
44
- end
45
-
46
- def test_get_404
47
-
48
- r = @h.get('/missing')
49
-
50
- assert_nil r
51
- end
52
-
53
- def test_get_404_raw
54
-
55
- r = @h.get('/missing', :raw => true)
56
-
57
- assert_equal 404, r.status
58
- end
59
-
60
- def test_get_500
61
-
62
- assert_raise Rufus::Jig::HttpError do
63
- @h.get('/server_error')
64
- end
65
-
66
- assert_equal 500, @h.last_response.status
67
- end
68
-
69
- def test_get_500_raw
70
-
71
- r = @h.get('/server_error', :raw => true)
72
-
73
- assert_equal 500, r.status
74
- end
75
-
76
- def test_get_with_accept
77
-
78
- r = @h.get('/document_accept', :accept => 'text/plain')
79
-
80
- assert_equal '{"car":"Saab"}', r
81
-
82
- r = @h.get('/document_accept', :accept => 'application/json')
83
-
84
- assert_equal Hash, r.class
85
- assert_equal 'Saab', r['car']
86
-
87
- assert_equal 0, @h.cache.size
88
-
89
- r = @h.get('/document_accept', :accept => :json)
90
-
91
- assert_equal Hash, r.class
92
- end
93
-
94
- def test_get_force_json
95
-
96
- r = @h.get('/document_json_plain', :accept => :json)
97
-
98
- assert_equal('{"car":"Peugeot"}', r)
99
-
100
- r = @h.get('/document_json_plain', :force_json => true)
101
-
102
- assert_equal({ 'car' => 'Peugeot' }, r)
103
- end
104
-
105
- def test_conditional_get
106
-
107
- b = @h.get('/document_with_etag')
108
-
109
- etag = @h.last_response.headers['Etag']
110
-
111
- assert_equal Hash, b.class
112
- assert_equal 'Peugeot', b['car']
113
-
114
- assert_equal 200, @h.last_response.status
115
-
116
- assert_equal({"/document_with_etag"=>["\"123456123456\"", {"car"=>"Peugeot"}]}, @h.cache)
117
-
118
- r = @h.get('/document_with_etag', :etag => etag)
119
-
120
- assert_equal Hash, r.class
121
- assert_equal 'Peugeot', r['car']
122
-
123
- assert_equal 304, @h.last_response.status
124
-
125
- assert_equal 1, @h.cache.size
126
-
127
- r = @h.get('/document_with_etag', :etag => etag, :raw => true)
128
-
129
- assert_equal 304, r.status
130
- end
131
-
132
- def test_cget_dup_body
133
-
134
- b = @h.get('/document_with_etag')
135
- etag = @h.last_response.headers['Etag']
136
- b['year'] = 1977
137
-
138
- assert_equal({"/document_with_etag"=>["\"123456123456\"", {"car"=>"Peugeot"}]}, @h.cache)
139
-
140
- b = @h.get('/document_with_etag', :etag => etag)
141
-
142
- assert_equal 304, @h.last_response.status
143
-
144
- b['year'] = 1977
145
-
146
- assert_equal({"/document_with_etag"=>["\"123456123456\"", {"car"=>"Peugeot"}]}, @h.cache)
147
- end
148
-
149
- def test_cget_dont_cache
150
-
151
- b = @h.get('/document_with_etag', :cache => false)
152
-
153
- assert_equal 0, @h.cache.size
154
- end
155
-
156
- def test_get_params
157
-
158
- assert_equal(
159
- {},
160
- @h.get('/params'))
161
- assert_equal(
162
- { 'a' => 'b' },
163
- @h.get('/params?a=b'))
164
- assert_equal(
165
- { 'a' => 'b', 'c' => 'd' },
166
- @h.get('/params?a=b', :params => { :c => 'd' }))
167
- assert_equal(
168
- { 'a' => 'b', 'c' => 'd' },
169
- @h.get('/params', :params => { 'a' => :b, :c => 'd' }))
170
- assert_equal(
171
- {},
172
- @h.get('/params', :params => {}))
173
- end
174
-
175
- def test_etag_but_missing
176
-
177
- b = @h.get('/document_with_etag', :etag => '"123456123456"')
178
-
179
- assert_equal 'Peugeot', b['car']
180
- assert_equal 200, @h.last_response.status
181
- end
182
-
183
- def test_get_utf8_uri
184
-
185
- b = @h.get('/川崎')
186
-
187
- assert_nil b
188
- assert_equal 404, @h.last_response.status
189
- end
190
- end
191
-