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,28 +0,0 @@
1
-
2
- $:.unshift('lib')
3
-
4
- require 'patron'
5
- require 'yajl'
6
- require 'rufus/jig'
7
-
8
- C0 = Rufus::Jig::Couch.new('127.0.0.1', 5984, 'test0', :re_put_ok => false)
9
- C1 = Rufus::Jig::Couch.new('127.0.0.1', 5984, 'test0', :re_put_ok => false)
10
-
11
- d = C0.get('nada')
12
- C0.delete(d) if d
13
-
14
- C0.put({ '_id' => 'nada', 'where' => 'London' })
15
- d = C0.get('nada')
16
-
17
- t1 = Thread.new do
18
- p [ Thread.current.object_id, :delete, d['_rev'], C1.delete(d) ]
19
- end
20
- t0 = Thread.new do
21
- p [ Thread.current.object_id, :put, d['_rev'], C0.put(d) ]
22
- end
23
-
24
- sleep 0.500
25
-
26
- p C0.get('nada')
27
- p C1.get('nada')
28
-
@@ -1,52 +0,0 @@
1
-
2
- lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- $:.unshift(lib) unless $:.include?(lib)
4
-
5
- require 'rubygems'
6
- require 'yajl'
7
-
8
- # Our default
9
- transport_library = 'net/http'
10
-
11
- if ARGV.include?( '--em' )
12
- require 'openssl'
13
- transport_library = 'em-http'
14
- elsif ARGV.include?( '--netp' )
15
- transport_library = 'net/http/persistent'
16
- elsif ARGV.include?( '--patron' )
17
- transport_library = 'patron'
18
- end
19
-
20
- require transport_library
21
-
22
- unless $advertised
23
- p transport_library
24
- $advertised = true
25
- end
26
-
27
- require 'rufus/jig'
28
-
29
- require 'test/unit'
30
-
31
- if transport_library == 'em-http'
32
- Thread.new { EM.run {} }
33
- Thread.pass until EM.reactor_running?
34
- end
35
-
36
-
37
- begin
38
- Rufus::Jig::Http.new('127.0.0.1', 5984).get('/_all_dbs')
39
- rescue Exception => e
40
- p e
41
- puts
42
- puts "couch not running..."
43
- puts
44
- exit(1)
45
- end
46
-
47
- class Test::Unit::TestCase
48
- def couch_url
49
- File.read('test/couch_url.txt').strip
50
- end
51
- end
52
-
@@ -1 +0,0 @@
1
- http://admin:admin@127.0.0.1:5984
@@ -1,64 +0,0 @@
1
-
2
- #
3
- # testing rufus-jig
4
- #
5
- # Sun Nov 1 21:42:34 JST 2009
6
- #
7
-
8
- require File.join(File.dirname(__FILE__), 'couch_base')
9
-
10
-
11
- class CtCouchTest < 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
- ensure
21
- h.close rescue nil
22
- end
23
-
24
- @c = Rufus::Jig::Couch.new(couch_url)
25
- end
26
-
27
- def teardown
28
-
29
- @c.close
30
- end
31
-
32
- def test_welcome
33
-
34
- assert_equal 'Welcome', @c.get('.')['couchdb']
35
- end
36
-
37
- def test_put_db
38
-
39
- @c.put('rufus_jig_test')
40
-
41
- assert_not_nil Rufus::Jig::Http.new(couch_url).get('/rufus_jig_test')
42
- end
43
-
44
- def test_delete_db
45
-
46
- Rufus::Jig::Http.new(couch_url).put('/rufus_jig_test', '')
47
-
48
- @c.delete('rufus_jig_test')
49
-
50
- assert_nil Rufus::Jig::Http.new(couch_url).get('/rufus_jig_test')
51
- end
52
-
53
- # def test_uuids
54
- #
55
- # uuids = @c.get_uuids
56
- #
57
- # assert_equal 1, uuids.size
58
- #
59
- # uuids = @c.get_uuids(5)
60
- #
61
- # assert_equal 5, uuids.size
62
- # end
63
- end
64
-
@@ -1,204 +0,0 @@
1
- # encoding: utf-8
2
-
3
- #
4
- # testing rufus-jig
5
- #
6
- # Sun Dec 13 15:03:36 JST 2009
7
- #
8
-
9
- require File.join(File.dirname(__FILE__), 'couch_base')
10
-
11
-
12
- class CtCouchDbTest < 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
-
24
- h.put('/rufus_jig_test', '')
25
- h.put('/rufus_jig_test/coffee1', '{"_id":"coffee1","type":"ristretto"}')
26
-
27
- h.close
28
-
29
- @c = Rufus::Jig::Couch.new(couch_url, 'rufus_jig_test')
30
- end
31
-
32
- def teardown
33
-
34
- @c.close
35
- end
36
-
37
- def test_path
38
-
39
- assert_equal 'rufus_jig_test', @c.path
40
- assert_equal 'rufus_jig_test', @c.name
41
- end
42
-
43
- def test_put
44
-
45
- r = @c.put('_id' => 'coffee0', 'type' => 'espresso')
46
-
47
- assert_nil r
48
-
49
- doc = Rufus::Jig::Http.new(couch_url).get('/rufus_jig_test/coffee0')
50
-
51
- assert_not_nil doc['_rev']
52
- end
53
-
54
- def test_put_fail
55
-
56
- r = @c.put('_id' => 'coffee1', 'type' => 'espresso')
57
-
58
- assert_match /^1-.+$/, r['_rev']
59
- end
60
-
61
- def test_put_conflict
62
-
63
- r = @c.put(
64
- '_id' => 'coffee1',
65
- 'type' => 'espresso',
66
- '_rev' => '2-47844552aae09c41a0ffffffffffffff')
67
-
68
- assert_match /^1-.+$/, r['_rev']
69
- end
70
-
71
- def test_put_update_rev
72
-
73
- doc = { '_id' => 'soda0', 'type' => 'lemon' }
74
-
75
- r = @c.put(doc, :update_rev => true)
76
-
77
- assert_nil r
78
- assert_not_nil doc['_rev']
79
- end
80
-
81
- def test_put_update_rev_2nd_time
82
-
83
- @c.put({ '_id' => 'soda0b', 'type' => 'lemon' })
84
- doc = @c.get('soda0b')
85
- rev = doc['_rev']
86
-
87
- r = @c.put(doc, :update_rev => true)
88
-
89
- assert_nil r
90
- assert_not_equal rev, doc['_rev']
91
- end
92
-
93
- def test_re_put
94
-
95
- doc = @c.get('coffee1')
96
- @c.delete(doc)
97
-
98
- assert_nil @c.get('coffee1')
99
-
100
- doc['whatever'] = 'else'
101
-
102
- r = @c.put(doc)
103
-
104
- assert_equal true, r
105
- assert_nil @c.get('coffee1')
106
-
107
- #assert_not_nil @c.get('coffee1')['_rev']
108
- # CouchDB < 0.11
109
- end
110
-
111
- def test_get
112
-
113
- doc = @c.get('coffee1')
114
-
115
- assert_not_nil doc['_rev']
116
- end
117
-
118
- def test_get_404
119
-
120
- doc = @c.get('tea0')
121
-
122
- assert_nil doc
123
- end
124
-
125
- def test_delete
126
-
127
- doc = @c.get('coffee1')
128
-
129
- r = @c.delete(doc)
130
-
131
- assert_nil r
132
-
133
- assert_nil(
134
- Rufus::Jig::Http.new(couch_url).get('/rufus_jig_test/coffee1'))
135
- end
136
-
137
- def test_delete_2_args
138
-
139
- doc = @c.get('coffee1')
140
-
141
- @c.delete(doc['_id'], doc['_rev'])
142
-
143
- assert_nil(
144
- Rufus::Jig::Http.new(couch_url).get('/rufus_jig_test/coffee1'))
145
- end
146
-
147
- def test_delete_conflict
148
-
149
- doc = @c.get('coffee1')
150
-
151
- rev = doc['_rev']
152
-
153
- doc['_rev'] = rev + '99'
154
-
155
- r = @c.delete(doc)
156
-
157
- assert_equal rev, r['_rev']
158
- end
159
-
160
- def test_get_doc_304
161
-
162
- doc = @c.get('coffee1')
163
- assert_equal 200, @c.http.last_response.status
164
-
165
- doc = @c.get('coffee1')
166
- assert_equal 304, @c.http.last_response.status
167
- end
168
-
169
- def test_delete_path
170
-
171
- r = @c.delete('coffee1')
172
-
173
- assert_equal(@c.get('coffee1'), r)
174
- end
175
-
176
- def test_delete_path_missing
177
-
178
- r = @c.delete('missing')
179
-
180
- assert_equal(true, r)
181
- end
182
-
183
- def test_put_in_missing_db
184
-
185
- @c.delete('.')
186
-
187
- r = @c.put('_id' => 'coffee2', 'type' => 'chevere')
188
-
189
- assert_equal true, r
190
- end
191
-
192
- def test_put_utf8_id
193
-
194
- r = @c.put('_id' => 'コーヒー', 'type' => 'espresso')
195
-
196
- assert_nil r
197
-
198
- doc =
199
- Rufus::Jig::Http.new(couch_url).get('/rufus_jig_test/コーヒー')
200
-
201
- assert_not_nil doc['_rev']
202
- end
203
- end
204
-
@@ -1,50 +0,0 @@
1
-
2
- #
3
- # testing rufus-jig
4
- #
5
- # Tue Dec 29 14:45:22 JST 2009
6
- #
7
-
8
- require File.join(File.dirname(__FILE__), 'couch_base')
9
-
10
-
11
- class CtCouchDbOptionsTest < Test::Unit::TestCase
12
-
13
- def setup
14
-
15
- h = Rufus::Jig::Http.new(couch_url)
16
-
17
- begin
18
- h.delete('/rufus_jig_test')
19
- rescue Exception => e
20
- #p e
21
- end
22
-
23
- h.put('/rufus_jig_test', '')
24
- h.put('/rufus_jig_test/coffee2_0', '{"_id":"coffee2_0","type":"ristretto"}')
25
-
26
- h.close
27
-
28
- @c = Rufus::Jig::Couch.new(couch_url, 'rufus_jig_test')
29
- end
30
-
31
- def teardown
32
-
33
- @c.close
34
- end
35
-
36
- def test_put_gone
37
-
38
- doc = @c.get('coffee2_0')
39
- @c.delete(doc)
40
-
41
- assert_nil @c.get('coffee2_0')
42
-
43
- doc['whatever'] = 'else'
44
-
45
- r = @c.put(doc)
46
-
47
- assert_equal true, r
48
- end
49
- end
50
-
@@ -1,106 +0,0 @@
1
-
2
- #
3
- # testing rufus-jig
4
- #
5
- # Fri Feb 12 13:17:18 JST 2010
6
- #
7
-
8
- require File.join(File.dirname(__FILE__), 'couch_base')
9
-
10
-
11
- class CtCouchDbViewsTest < Test::Unit::TestCase
12
-
13
- def setup
14
-
15
- h = Rufus::Jig::Http.new(couch_url)
16
-
17
- begin
18
- h.delete('/rufus_jig_test')
19
- rescue Exception => e
20
- #p e
21
- end
22
-
23
- h.put('/rufus_jig_test', '')
24
-
25
- h.put('/rufus_jig_test/c0', '{"_id":"c0","type":"espresso"}')
26
- h.put('/rufus_jig_test/c1', '{"_id":"c1","type":"ristretto"}')
27
- h.put('/rufus_jig_test/c2', '{"_id":"c2","type":"macchiato"}')
28
- h.put('/rufus_jig_test/c3', '{"_id":"c3","type":"capuccino"}')
29
- h.put('/rufus_jig_test/c4', '{"_id":"c4","type":"macchiato"}')
30
-
31
- h.put(
32
- '/rufus_jig_test/_design/my_test',
33
- {
34
- '_id' => '_design/my_test',
35
- 'views' => {
36
- 'my_view' => {
37
- 'map' => "function (doc) { emit(doc['type'], null); }"
38
- }
39
- }
40
- },
41
- :content_type => :json)
42
-
43
- h.close
44
-
45
- @c = Rufus::Jig::Couch.new(couch_url, 'rufus_jig_test')
46
- end
47
-
48
- def teardown
49
-
50
- @c.close
51
- end
52
-
53
- def test_get
54
-
55
- #"_design/ruote/_view/by_wfid?key=%22#{m[1]}%22" +
56
-
57
- #p @c.get('_design/my_test/_view/my_view?limit=2')
58
- assert_equal(
59
- {"total_rows"=>5, "rows"=>[{"id"=>"c3", "value"=>nil, "key"=>"capuccino"}, {"id"=>"c0", "value"=>nil, "key"=>"espresso"}], "offset"=>0},
60
- @c.get('_design/my_test/_view/my_view?limit=2'))
61
- end
62
-
63
- def test_get_key
64
-
65
- #p @c.get('_design/my_test/_view/my_view?key=%22macchiato%22')
66
- assert_equal(
67
- {"total_rows"=>5, "rows"=>[{"id"=>"c2", "value"=>nil, "key"=>"macchiato"}, {"id"=>"c4", "value"=>nil, "key"=>"macchiato"}], "offset"=>2},
68
- @c.get('_design/my_test/_view/my_view?key=%22macchiato%22'))
69
- end
70
-
71
- def test_post_keys
72
-
73
- #p @c.post('_design/my_test/_view/my_view', { 'keys' => [ 'espresso', 'macchiato' ] })
74
- assert_equal(
75
- {"total_rows"=>5, "rows"=>[{"id"=>"c0", "value"=>nil, "key"=>"espresso"}, {"id"=>"c2", "value"=>nil, "key"=>"macchiato"}, {"id"=>"c4", "value"=>nil, "key"=>"macchiato"}], "offset"=>1},
76
- @c.post('_design/my_test/_view/my_view', { 'keys' => [ 'espresso', 'macchiato' ] }))
77
- end
78
-
79
- #def test_put_views
80
- # p @c.get('_design/my_test_2')
81
- # @c.put(
82
- # {
83
- # '_id' => '_design/my_test_2',
84
- # 'views' => {
85
- # 'my_view' => {
86
- # 'map' => "function (doc) { emit(doc['type'], null); }"
87
- # }
88
- # }
89
- # })
90
- # p @c.http.cache.keys
91
- # p @c.get('_design/my_test_2/_view/my_view?key=%22macchiato%22')
92
- # p @c.http.cache.keys
93
- # p @c.get('_design/my_test_2/_view/my_view?key=%22macchiato%22')
94
- # p @c.http.cache.keys
95
- #end
96
-
97
- def test_nuke_design_documents
98
-
99
- assert_not_nil @c.get('_design/my_test')
100
-
101
- @c.nuke_design_documents
102
-
103
- assert_nil @c.get('_design/my_test')
104
- end
105
- end
106
-