ripple 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/Rakefile +61 -48
  2. data/lib/ripple.rb +5 -1
  3. data/lib/ripple/core_ext/casting.rb +3 -0
  4. data/lib/ripple/document.rb +6 -2
  5. data/lib/ripple/document/associations.rb +154 -0
  6. data/lib/ripple/document/{persistence/callbacks.rb → associations/embedded.rb} +20 -24
  7. data/lib/ripple/document/associations/instantiators.rb +41 -0
  8. data/lib/{riak/util/translation.rb → ripple/document/associations/linked.rb} +14 -11
  9. data/lib/ripple/document/associations/many.rb +52 -0
  10. data/lib/ripple/document/associations/many_embedded_proxy.rb +49 -0
  11. data/lib/{riak/i18n.rb → ripple/document/associations/one.rb} +18 -2
  12. data/lib/ripple/document/associations/one_embedded_proxy.rb +41 -0
  13. data/lib/ripple/document/associations/proxy.rb +125 -0
  14. data/lib/ripple/document/attribute_methods.rb +8 -1
  15. data/lib/ripple/document/attribute_methods/read.rb +4 -0
  16. data/lib/ripple/document/attribute_methods/write.rb +4 -0
  17. data/lib/ripple/document/bucket_access.rb +1 -1
  18. data/lib/ripple/document/callbacks.rb +75 -0
  19. data/lib/ripple/document/finders.rb +50 -3
  20. data/lib/ripple/document/persistence.rb +14 -6
  21. data/lib/ripple/document/validations.rb +35 -7
  22. data/lib/ripple/document/validations/associated_validator.rb +37 -0
  23. data/lib/ripple/embedded_document.rb +8 -2
  24. data/lib/{riak/map_reduce_error.rb → ripple/embedded_document/conversion.rb} +19 -5
  25. data/lib/{riak/invalid_response.rb → ripple/embedded_document/finders.rb} +17 -8
  26. data/lib/ripple/embedded_document/persistence.rb +75 -13
  27. data/lib/ripple/locale/en.yml +7 -1
  28. data/{spec/riak/net_http_backend_spec.rb → lib/ripple/railtie.rb} +17 -13
  29. data/spec/fixtures/config.yml +3 -0
  30. data/spec/integration/ripple/associations_spec.rb +81 -0
  31. data/spec/integration/ripple/persistence_spec.rb +54 -0
  32. data/spec/ripple/associations/many_embedded_proxy_spec.rb +124 -0
  33. data/spec/ripple/associations/one_embedded_proxy_spec.rb +130 -0
  34. data/spec/ripple/associations/proxy_spec.rb +78 -0
  35. data/spec/ripple/associations_spec.rb +111 -0
  36. data/spec/ripple/attribute_methods_spec.rb +37 -16
  37. data/spec/ripple/bucket_access_spec.rb +3 -14
  38. data/spec/ripple/callbacks_spec.rb +53 -9
  39. data/spec/ripple/document_spec.rb +22 -6
  40. data/spec/ripple/embedded_document/conversion_spec.rb +35 -0
  41. data/spec/{riak/headers_spec.rb → ripple/embedded_document/finders_spec.rb} +17 -14
  42. data/spec/ripple/embedded_document/persistence_spec.rb +86 -0
  43. data/spec/ripple/embedded_document_spec.rb +1 -26
  44. data/spec/ripple/finders_spec.rb +66 -30
  45. data/spec/ripple/persistence_spec.rb +33 -21
  46. data/spec/ripple/properties_spec.rb +1 -7
  47. data/spec/ripple/ripple_spec.rb +10 -0
  48. data/spec/ripple/timestamps_spec.rb +12 -19
  49. data/spec/ripple/validations_spec.rb +48 -6
  50. data/spec/spec_helper.rb +4 -10
  51. data/spec/support/associations/proxies.rb +16 -0
  52. data/spec/support/integration.rb +4 -0
  53. data/spec/support/mocks.rb +3 -0
  54. data/spec/support/models/address.rb +8 -0
  55. data/spec/support/models/box.rb +6 -0
  56. data/spec/support/models/cardboard_box.rb +3 -0
  57. data/spec/support/models/clock.rb +6 -0
  58. data/spec/support/models/customer.rb +4 -0
  59. data/spec/support/models/email.rb +4 -0
  60. data/spec/support/models/family.rb +14 -0
  61. data/spec/support/models/favorite.rb +4 -0
  62. data/spec/support/models/invoice.rb +6 -0
  63. data/spec/support/models/late_invoice.rb +3 -0
  64. data/spec/support/models/note.rb +4 -0
  65. data/spec/support/models/page.rb +4 -0
  66. data/spec/support/models/paid_invoice.rb +4 -0
  67. data/spec/support/models/tree.rb +3 -0
  68. data/spec/support/models/user.rb +6 -0
  69. data/spec/support/models/widget.rb +6 -0
  70. metadata +111 -138
  71. data/.document +0 -5
  72. data/.gitignore +0 -26
  73. data/CONTRIBUTORS.textile +0 -5
  74. data/LICENSE +0 -13
  75. data/README.textile +0 -128
  76. data/RELEASE_NOTES.textile +0 -68
  77. data/VERSION +0 -1
  78. data/lib/riak.rb +0 -46
  79. data/lib/riak/bucket.rb +0 -157
  80. data/lib/riak/client.rb +0 -139
  81. data/lib/riak/client/curb_backend.rb +0 -82
  82. data/lib/riak/client/http_backend.rb +0 -209
  83. data/lib/riak/client/net_http_backend.rb +0 -49
  84. data/lib/riak/failed_request.rb +0 -37
  85. data/lib/riak/link.rb +0 -73
  86. data/lib/riak/locale/en.yml +0 -37
  87. data/lib/riak/map_reduce.rb +0 -248
  88. data/lib/riak/robject.rb +0 -258
  89. data/lib/riak/util/escape.rb +0 -12
  90. data/lib/riak/util/fiber1.8.rb +0 -48
  91. data/lib/riak/util/headers.rb +0 -44
  92. data/lib/riak/util/multipart.rb +0 -52
  93. data/lib/riak/walk_spec.rb +0 -117
  94. data/ripple.gemspec +0 -169
  95. data/spec/fixtures/cat.jpg +0 -0
  96. data/spec/fixtures/multipart-blank.txt +0 -7
  97. data/spec/fixtures/multipart-with-body.txt +0 -16
  98. data/spec/riak/bucket_spec.rb +0 -230
  99. data/spec/riak/client_spec.rb +0 -174
  100. data/spec/riak/curb_backend_spec.rb +0 -50
  101. data/spec/riak/escape_spec.rb +0 -17
  102. data/spec/riak/http_backend_spec.rb +0 -131
  103. data/spec/riak/link_spec.rb +0 -82
  104. data/spec/riak/map_reduce_spec.rb +0 -352
  105. data/spec/riak/multipart_spec.rb +0 -36
  106. data/spec/riak/object_spec.rb +0 -532
  107. data/spec/riak/walk_spec_spec.rb +0 -208
  108. data/spec/spec.opts +0 -1
  109. data/spec/support/http_backend_implementation_examples.rb +0 -215
  110. data/spec/support/mock_server.rb +0 -58
Binary file
@@ -1,7 +0,0 @@
1
-
2
- --73NmmA8dJxSB5nL2dVerpFIi8ze
3
- Content-Type: multipart/mixed; boundary=8fPXq9XfV15txMoV1IbA3hovEij
4
-
5
- --8fPXq9XfV15txMoV1IbA3hovEij--
6
-
7
- --73NmmA8dJxSB5nL2dVerpFIi8ze--
@@ -1,16 +0,0 @@
1
-
2
- --5EiMOjuGavQ2IbXAqsJPLLfJNlA
3
- Content-Type: multipart/mixed; boundary=7extjTzvYIKVMVHowUiTn0LfvSs
4
-
5
- --7extjTzvYIKVMVHowUiTn0LfvSs
6
- X-Riak-Vclock: a85hYGBgyWDKBVHMr9s3ZzAlMuaxMtyZcPAIH1RYyObHDqiwxIZjcOG1M98chAq3bUQIz7SSFQEKM4FUbwMKZwEA
7
- Location: /riak/foo/baz
8
- Content-Type: text/plain
9
- Link: </riak/foo>; rel="up"
10
- Etag: 6JdI51eFrvv5lDwY6un7a2
11
- Last-Modified: Sat, 16 Jan 2010 22:13:44 GMT
12
-
13
- SCP sloooow....
14
- --7extjTzvYIKVMVHowUiTn0LfvSs--
15
-
16
- --5EiMOjuGavQ2IbXAqsJPLLfJNlA--
@@ -1,230 +0,0 @@
1
- # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- require File.expand_path("../spec_helper", File.dirname(__FILE__))
15
-
16
- describe Riak::Bucket do
17
- before :each do
18
- @client = Riak::Client.new
19
- @bucket = Riak::Bucket.new(@client, "foo")
20
- end
21
-
22
- def do_load(overrides={})
23
- @bucket.load({
24
- :body => '{"props":{"name":"foo","allow_mult":false,"big_vclock":50,"chash_keyfun":{"mod":"riak_util","fun":"chash_std_keyfun"},"linkfun":{"mod":"jiak_object","fun":"mapreduce_linkfun"},"n_val":3,"old_vclock":86400,"small_vclock":10,"young_vclock":20},"keys":["bar"]}',
25
- :headers => {
26
- "vary" => ["Accept-Encoding"],
27
- "server" => ["MochiWeb/1.1 WebMachine/1.5.1 (hack the charles gibson)"],
28
- "link" => ['</riak/foo/bar>; riaktag="contained"'],
29
- "date" => ["Tue, 12 Jan 2010 15:30:43 GMT"],
30
- "content-type" => ["application/json"],
31
- "content-length" => ["257"]
32
- }
33
- }.merge(overrides))
34
- end
35
-
36
-
37
- describe "when initializing" do
38
- it "should require a client and a name" do
39
- lambda { Riak::Bucket.new }.should raise_error
40
- lambda { Riak::Bucket.new(@client) }.should raise_error
41
- lambda { Riak::Bucket.new("foo") }.should raise_error
42
- lambda { Riak::Bucket.new("foo", @client) }.should raise_error
43
- lambda { Riak::Bucket.new(@client, "foo") }.should_not raise_error
44
- end
45
-
46
- it "should set the client and name attributes" do
47
- bucket = Riak::Bucket.new(@client, "foo")
48
- bucket.client.should == @client
49
- bucket.name.should == "foo"
50
- end
51
- end
52
-
53
- describe "when loading data from an HTTP response" do
54
- it "should load the bucket properties from the response body" do
55
- do_load
56
- @bucket.props.should == {"name"=>"foo","allow_mult" => false,"big_vclock" => 50,"chash_keyfun" => {"mod" =>"riak_util","fun"=>"chash_std_keyfun"},"linkfun"=>{"mod"=>"jiak_object","fun"=>"mapreduce_linkfun"},"n_val"=>3,"old_vclock"=>86400,"small_vclock"=>10,"young_vclock"=>20}
57
- end
58
-
59
- it "should load the keys from the response body" do
60
- do_load
61
- @bucket.keys.should == ["bar"]
62
- end
63
-
64
- it "should raise an error for a response that is not JSON" do
65
- lambda do
66
- do_load(:headers => {"content-type" => ["text/plain"]})
67
- end.should raise_error(Riak::InvalidResponse)
68
- end
69
-
70
- it "should unescape key names" do
71
- do_load(:body => '{"keys":["foo", "bar%20baz"]}')
72
- @bucket.keys.should == ["foo", "bar baz"]
73
- end
74
- end
75
-
76
- describe "accessing keys" do
77
- before :each do
78
- @http = mock("HTTPBackend")
79
- @client.stub!(:http).and_return(@http)
80
- end
81
-
82
- it "should load the keys if not present" do
83
- @http.should_receive(:get).with(200, "/riak/", "foo", {:props => false}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"keys":["bar"]}'})
84
- @bucket.keys.should == ["bar"]
85
- end
86
-
87
- it "should allow reloading of the keys" do
88
- @http.should_receive(:get).with(200, "/riak/","foo", {:props => false}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"keys":["bar"]}'})
89
- do_load # Ensures they're already loaded
90
- @bucket.keys(:reload => true).should == ["bar"]
91
- end
92
-
93
- it "should allow streaming keys through block" do
94
- # pending "Needs support in the raw_http_resource"
95
- @http.should_receive(:get).with(200, "/riak/","foo", {:props => false}, {}).and_yield("{}").and_yield('{"keys":[]}').and_yield('{"keys":["bar"]}').and_yield('{"keys":["baz"]}')
96
- all_keys = []
97
- @bucket.keys do |list|
98
- all_keys.concat(list)
99
- end
100
- all_keys.should == ["bar", "baz"]
101
- end
102
-
103
- it "should unescape key names" do
104
- @http.should_receive(:get).with(200, "/riak/","foo", {:props => false}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"keys":["bar%20baz"]}'})
105
- @bucket.keys.should == ["bar baz"]
106
- end
107
-
108
- it "should escape the bucket name" do
109
- @bucket.instance_variable_set :@name, "unescaped "
110
- @http.should_receive(:get).with(200, "/riak/","unescaped%20", {:props => false}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"keys":["bar"]}'})
111
- @bucket.keys.should == ["bar"]
112
- end
113
- end
114
-
115
- describe "setting the bucket properties" do
116
- before :each do
117
- @http = mock("HTTPBackend")
118
- @client.stub!(:http).and_return(@http)
119
- end
120
-
121
- it "should PUT the new properties to the bucket" do
122
- @http.should_receive(:put).with(204, "/riak/","foo", '{"props":{"name":"foo"}}', {"Content-Type" => "application/json"}).and_return({:body => "", :headers => {}})
123
- @bucket.props = { :name => "foo" }
124
- end
125
-
126
- it "should raise an error if an invalid property is given" do
127
- lambda { @bucket.props = "blah" }.should raise_error(ArgumentError)
128
- end
129
-
130
- it "should escape the bucket name" do
131
- @bucket.instance_variable_set :@name, "foo bar"
132
- @http.should_receive(:put).with(204, "/riak/","foo%20bar", '{"props":{"n_val":2}}', {"Content-Type" => "application/json"}).and_return({:body => "", :headers => {}})
133
- @bucket.props = {:n_val => 2}
134
- end
135
- end
136
-
137
- describe "fetching an object" do
138
- before :each do
139
- @http = mock("HTTPBackend")
140
- @client.stub!(:http).and_return(@http)
141
- end
142
-
143
- it "should load the object from the server as a Riak::RObject" do
144
- @http.should_receive(:get).with(200, "/riak/","foo", "db", {}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"name":"Riak","company":"Basho"}'})
145
- @bucket.get("db").should be_kind_of(Riak::RObject)
146
- end
147
-
148
- it "should use the given query parameters (for R value, etc)" do
149
- @http.should_receive(:get).with(200, "/riak/","foo", "db", {:r => 2}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"name":"Riak","company":"Basho"}'})
150
- @bucket.get("db", :r => 2).should be_kind_of(Riak::RObject)
151
- end
152
-
153
- it "should allow 300 responses if allow_mult is set" do
154
- @bucket.instance_variable_set(:@props, {'allow_mult' => true})
155
- @http.should_receive(:get).with([200,300], "/riak/","foo", "db", {}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"name":"Riak","company":"Basho"}'})
156
- @bucket.get('db')
157
- end
158
-
159
- it "should escape the bucket and key names" do
160
- @bucket.instance_variable_set(:@name, "foo ")
161
- @http.should_receive(:get).with(200, "/riak/","foo%20", "%20bar", {}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"name":"Riak","company":"Basho"}'})
162
- @bucket.get(' bar')
163
- end
164
- end
165
-
166
- describe "creating a new blank object" do
167
- it "should instantiate the object with the given key, default to JSON" do
168
- obj = @bucket.new('bar')
169
- obj.should be_kind_of(Riak::RObject)
170
- obj.key.should == 'bar'
171
- obj.content_type.should == 'application/json'
172
- end
173
- end
174
-
175
- describe "fetching or creating a new object" do
176
- before :each do
177
- @http = mock("HTTPBackend")
178
- @client.stub!(:http).and_return(@http)
179
- end
180
-
181
- it "should return the existing object if present" do
182
- @http.should_receive(:get).with(200, "/riak/","foo", "db", {}, {}).and_return({:headers => {"content-type" => ["application/json"]}, :body => '{"name":"Riak","company":"Basho"}'})
183
- obj = @bucket.get_or_new('db')
184
- obj.key.should == 'db'
185
- obj.data['name'].should == "Riak"
186
- end
187
-
188
- it "should create a new blank object if the key does not exist" do
189
- @http.should_receive(:get).and_raise(Riak::FailedRequest.new(:get, 200, 404, {}, "File not found"))
190
- obj = @bucket.get_or_new('db')
191
- obj.key.should == 'db'
192
- obj.data.should be_blank
193
- end
194
-
195
- it "should bubble up non-ok non-missing errors" do
196
- @http.should_receive(:get).and_raise(Riak::FailedRequest.new(:get, 200, 500, {}, "File not found"))
197
- lambda { @bucket.get_or_new('db') }.should raise_error(Riak::FailedRequest)
198
- end
199
- end
200
-
201
- describe "get/set allow_mult property" do
202
- before :each do
203
- do_load
204
- end
205
-
206
- it "should extract the allow_mult property" do
207
- @bucket.allow_mult.should be_false
208
- end
209
-
210
- it "should set the allow_mult property" do
211
- @bucket.should_receive(:props=).with(hash_including('allow_mult' => true))
212
- @bucket.allow_mult = true
213
- end
214
- end
215
-
216
- describe "get/set the N value" do
217
- before :each do
218
- do_load
219
- end
220
-
221
- it "should extract the N value" do
222
- @bucket.n_value.should == 3
223
- end
224
-
225
- it "should set the N value" do
226
- @bucket.should_receive(:props=).with(hash_including('n_val' => 1))
227
- @bucket.n_value = 1
228
- end
229
- end
230
- end
@@ -1,174 +0,0 @@
1
- # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- require File.expand_path("../spec_helper", File.dirname(__FILE__))
15
-
16
- describe Riak::Client do
17
- describe "when initializing" do
18
- it "should default to the local interface on port 8098" do
19
- client = Riak::Client.new
20
- client.host.should == "127.0.0.1"
21
- client.port.should == 8098
22
- end
23
-
24
- it "should accept a host" do
25
- client = Riak::Client.new :host => "riak.basho.com"
26
- client.host.should == "riak.basho.com"
27
- end
28
-
29
- it "should accept a port" do
30
- client = Riak::Client.new :port => 9000
31
- client.port.should == 9000
32
- end
33
-
34
- it "should accept a client ID" do
35
- client = Riak::Client.new :client_id => "AAAAAA=="
36
- client.client_id.should == "AAAAAA=="
37
- end
38
-
39
- it "should turn an integer client ID into a base64-encoded string" do
40
- client = Riak::Client.new :client_id => 1
41
- client.client_id.should == "AAAAAQ=="
42
- end
43
-
44
- it "should create a client ID if not specified" do
45
- Riak::Client.new.client_id.should be_kind_of(String)
46
- end
47
-
48
- it "should accept a path prefix" do
49
- client = Riak::Client.new(:prefix => "/jiak/")
50
- client.prefix.should == "/jiak/"
51
- end
52
-
53
- it "should default the prefix to /riak/ if not specified" do
54
- Riak::Client.new.prefix.should == "/riak/"
55
- end
56
-
57
- it "should accept a mapreduce path" do
58
- client = Riak::Client.new(:mapred => "/mr")
59
- client.mapred.should == "/mr"
60
- end
61
-
62
- it "should default the mapreduce path to /mapred if not specified" do
63
- Riak::Client.new.mapred.should == "/mapred"
64
- end
65
- end
66
-
67
- describe "reconfiguring" do
68
- before :each do
69
- @client = Riak::Client.new
70
- end
71
-
72
- describe "setting the host" do
73
- it "should allow setting the host" do
74
- @client.should respond_to(:host=)
75
- @client.host = "riak.basho.com"
76
- @client.host.should == "riak.basho.com"
77
- end
78
-
79
- it "should require the host to be an IP or hostname" do
80
- [238472384972, ""].each do |invalid|
81
- lambda { @client.host = invalid }.should raise_error(ArgumentError)
82
- end
83
- ["127.0.0.1", "10.0.100.5", "localhost", "otherhost.local", "riak.basho.com"].each do |valid|
84
- lambda { @client.host = valid }.should_not raise_error
85
- end
86
- end
87
- end
88
-
89
- describe "setting the port" do
90
- it "should allow setting the port" do
91
- @client.should respond_to(:port=)
92
- @client.port = 9000
93
- @client.port.should == 9000
94
- end
95
-
96
- it "should require the port to be a valid number" do
97
- [-1,65536,"foo"].each do |invalid|
98
- lambda { @client.port = invalid }.should raise_error(ArgumentError)
99
- end
100
- [0,1,65535,8098].each do |valid|
101
- lambda { @client.port = valid }.should_not raise_error
102
- end
103
- end
104
- end
105
-
106
- it "should allow setting the prefix (although we prefer the raw interface)" do
107
- @client.should respond_to(:prefix=)
108
- @client.prefix = "/another-prefix"
109
- @client.prefix.should == "/another-prefix"
110
- end
111
-
112
- describe "setting the client id" do
113
- it "should accept a string unmodified" do
114
- @client.client_id = "foo"
115
- @client.client_id.should == "foo"
116
- end
117
-
118
- it "should base64-encode an integer" do
119
- @client.client_id = 1
120
- @client.client_id.should == "AAAAAQ=="
121
- end
122
-
123
- it "should reject an integer equal to the maximum client id" do
124
- lambda { @client.client_id = Riak::Client::MAX_CLIENT_ID }.should raise_error(ArgumentError)
125
- end
126
-
127
- it "should reject an integer larger than the maximum client id" do
128
- lambda { @client.client_id = Riak::Client::MAX_CLIENT_ID + 1 }.should raise_error(ArgumentError)
129
- end
130
- end
131
- end
132
-
133
- describe "choosing an HTTP backend" do
134
- before :each do
135
- @client = Riak::Client.new
136
- end
137
-
138
- it "should choose the Curb backend if Curb is available" do
139
- @client.should_receive(:require).with('curb').and_return(true)
140
- @client.http.should be_instance_of(Riak::Client::CurbBackend)
141
- end
142
-
143
- it "should choose the Net::HTTP backend if Curb is unavailable" do
144
- @client.should_receive(:require).with('curb').and_raise(LoadError)
145
- @client.should_receive(:warn).and_return(true)
146
- @client.http.should be_instance_of(Riak::Client::NetHTTPBackend)
147
- end
148
- end
149
-
150
- describe "retrieving a bucket" do
151
- before :each do
152
- @client = Riak::Client.new
153
- @http = mock(Riak::Client::HTTPBackend)
154
- @client.stub!(:http).and_return(@http)
155
- @payload = {:headers => {"content-type" => ["application/json"]}, :body => "{}"}
156
- @http.stub!(:get).and_return(@payload)
157
- end
158
-
159
- it "should send a GET request to the bucket name and return a Riak::Bucket" do
160
- @http.should_receive(:get).with(200, "/riak/", "foo", {}, {}).and_return(@payload)
161
- @client.bucket("foo").should be_kind_of(Riak::Bucket)
162
- end
163
-
164
- it "should allow requesting bucket properties without the keys" do
165
- @http.should_receive(:get).with(200, "/riak/", "foo", {:keys => false}, {}).and_return(@payload)
166
- @client.bucket("foo", :keys => false)
167
- end
168
-
169
- it "should escape bucket names with invalid characters" do
170
- @http.should_receive(:get).with(200, "/riak/", "foo%2Fbar%20", {:keys => false}, {}).and_return(@payload)
171
- @client.bucket("foo/bar ", :keys => false)
172
- end
173
- end
174
- end
@@ -1,50 +0,0 @@
1
- # Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- require File.expand_path("../spec_helper", File.dirname(__FILE__))
15
-
16
- begin
17
- require 'curb'
18
- rescue LoadError
19
- warn "Skipping CurbBackend specs, curb library not found."
20
- else
21
- describe Riak::Client::CurbBackend do
22
- def setup_http_mock(method, uri, options={})
23
- method = method.to_s.upcase
24
- uri = URI.parse(uri)
25
- path = uri.path || "/"
26
- query = uri.query || ""
27
- status = options[:status] ? Array(options[:status]).first.to_i : 200
28
- body = options[:body] || []
29
- headers = options[:headers] || {}
30
- headers['Content-Type'] ||= "text/plain"
31
- $server.attach do |env|
32
- env["REQUEST_METHOD"].should == method
33
- env["PATH_INFO"].should == path
34
- env["QUERY_STRING"].should == query
35
- [status, headers, Array(body)]
36
- end
37
- end
38
-
39
- before :each do
40
- @client = Riak::Client.new(:port => 4000) # Point to our mock
41
- @backend = Riak::Client::CurbBackend.new(@client)
42
- end
43
-
44
- it_should_behave_like "HTTP backend"
45
-
46
- after :each do
47
- $server.detach
48
- end
49
- end
50
- end