seomoz-riak-client 1.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +27 -0
- data/Guardfile +14 -0
- data/Rakefile +76 -0
- data/erl_src/riak_kv_test_backend.beam +0 -0
- data/erl_src/riak_kv_test_backend.erl +174 -0
- data/erl_src/riak_search_test_backend.beam +0 -0
- data/erl_src/riak_search_test_backend.erl +175 -0
- data/lib/active_support/cache/riak_store.rb +2 -0
- data/lib/riak.rb +21 -0
- data/lib/riak/bucket.rb +215 -0
- data/lib/riak/cache_store.rb +84 -0
- data/lib/riak/client.rb +415 -0
- data/lib/riak/client/beefcake/messages.rb +147 -0
- data/lib/riak/client/beefcake/object_methods.rb +92 -0
- data/lib/riak/client/beefcake_protobuffs_backend.rb +176 -0
- data/lib/riak/client/excon_backend.rb +65 -0
- data/lib/riak/client/http_backend.rb +203 -0
- data/lib/riak/client/http_backend/configuration.rb +46 -0
- data/lib/riak/client/http_backend/key_streamer.rb +43 -0
- data/lib/riak/client/http_backend/object_methods.rb +94 -0
- data/lib/riak/client/http_backend/request_headers.rb +34 -0
- data/lib/riak/client/http_backend/transport_methods.rb +218 -0
- data/lib/riak/client/net_http_backend.rb +79 -0
- data/lib/riak/client/protobuffs_backend.rb +97 -0
- data/lib/riak/client/pump.rb +30 -0
- data/lib/riak/client/search.rb +94 -0
- data/lib/riak/core_ext.rb +6 -0
- data/lib/riak/core_ext/blank.rb +53 -0
- data/lib/riak/core_ext/extract_options.rb +7 -0
- data/lib/riak/core_ext/json.rb +15 -0
- data/lib/riak/core_ext/slice.rb +18 -0
- data/lib/riak/core_ext/stringify_keys.rb +10 -0
- data/lib/riak/core_ext/symbolize_keys.rb +10 -0
- data/lib/riak/core_ext/to_param.rb +31 -0
- data/lib/riak/encoding.rb +6 -0
- data/lib/riak/failed_request.rb +81 -0
- data/lib/riak/i18n.rb +3 -0
- data/lib/riak/json.rb +28 -0
- data/lib/riak/link.rb +85 -0
- data/lib/riak/locale/en.yml +48 -0
- data/lib/riak/map_reduce.rb +206 -0
- data/lib/riak/map_reduce/filter_builder.rb +94 -0
- data/lib/riak/map_reduce/phase.rb +98 -0
- data/lib/riak/map_reduce_error.rb +7 -0
- data/lib/riak/robject.rb +290 -0
- data/lib/riak/search.rb +3 -0
- data/lib/riak/serializers.rb +74 -0
- data/lib/riak/stamp.rb +77 -0
- data/lib/riak/test_server.rb +252 -0
- data/lib/riak/util/escape.rb +45 -0
- data/lib/riak/util/fiber1.8.rb +48 -0
- data/lib/riak/util/headers.rb +53 -0
- data/lib/riak/util/multipart.rb +52 -0
- data/lib/riak/util/multipart/stream_parser.rb +62 -0
- data/lib/riak/util/tcp_socket_extensions.rb +58 -0
- data/lib/riak/util/translation.rb +19 -0
- data/lib/riak/walk_spec.rb +105 -0
- data/riak-client.gemspec +55 -0
- data/seomoz-riak-client.gemspec +55 -0
- data/spec/fixtures/cat.jpg +0 -0
- data/spec/fixtures/multipart-blank.txt +7 -0
- data/spec/fixtures/multipart-mapreduce.txt +10 -0
- data/spec/fixtures/multipart-with-body.txt +16 -0
- data/spec/fixtures/server.cert.crt +15 -0
- data/spec/fixtures/server.cert.key +15 -0
- data/spec/fixtures/test.pem +1 -0
- data/spec/integration/riak/cache_store_spec.rb +154 -0
- data/spec/integration/riak/http_backends_spec.rb +58 -0
- data/spec/integration/riak/protobuffs_backends_spec.rb +32 -0
- data/spec/integration/riak/test_server_spec.rb +161 -0
- data/spec/riak/beefcake_protobuffs_backend_spec.rb +59 -0
- data/spec/riak/bucket_spec.rb +205 -0
- data/spec/riak/client_spec.rb +517 -0
- data/spec/riak/core_ext/to_param_spec.rb +15 -0
- data/spec/riak/escape_spec.rb +69 -0
- data/spec/riak/excon_backend_spec.rb +64 -0
- data/spec/riak/headers_spec.rb +38 -0
- data/spec/riak/http_backend/configuration_spec.rb +51 -0
- data/spec/riak/http_backend/object_methods_spec.rb +217 -0
- data/spec/riak/http_backend/transport_methods_spec.rb +117 -0
- data/spec/riak/http_backend_spec.rb +269 -0
- data/spec/riak/link_spec.rb +71 -0
- data/spec/riak/map_reduce/filter_builder_spec.rb +32 -0
- data/spec/riak/map_reduce/phase_spec.rb +136 -0
- data/spec/riak/map_reduce_spec.rb +310 -0
- data/spec/riak/multipart_spec.rb +23 -0
- data/spec/riak/net_http_backend_spec.rb +16 -0
- data/spec/riak/robject_spec.rb +427 -0
- data/spec/riak/search_spec.rb +178 -0
- data/spec/riak/serializers_spec.rb +93 -0
- data/spec/riak/stamp_spec.rb +54 -0
- data/spec/riak/stream_parser_spec.rb +53 -0
- data/spec/riak/walk_spec_spec.rb +195 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/support/drb_mock_server.rb +39 -0
- data/spec/support/http_backend_implementation_examples.rb +266 -0
- data/spec/support/integration_setup.rb +10 -0
- data/spec/support/mock_server.rb +81 -0
- data/spec/support/mocks.rb +4 -0
- data/spec/support/test_server.yml.example +2 -0
- data/spec/support/unified_backend_examples.rb +255 -0
- metadata +271 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
describe Riak do
|
3
|
+
require 'riak/core_ext/to_param'
|
4
|
+
|
5
|
+
it "should do param conversion correctly" do
|
6
|
+
{ :name => 'David', :nationality => 'Danish' }.to_param.should == "name=David&nationality=Danish"
|
7
|
+
end
|
8
|
+
|
9
|
+
# Based on the activesupport implementation.
|
10
|
+
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/to_param.rb
|
11
|
+
it "should do param conversion correctly with a namespace" do
|
12
|
+
{ :name => 'David', :nationality => 'Danish' }.to_param('user').should == "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Riak::Util::Escape do
|
5
|
+
before :each do
|
6
|
+
@object = Object.new
|
7
|
+
@object.extend(Riak::Util::Escape)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should use URI by default for escaping" do
|
11
|
+
Riak.escaper.should == URI
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when using CGI for escaping" do
|
15
|
+
before { @oldesc, Riak.escaper = Riak.escaper, CGI }
|
16
|
+
after { Riak.escaper = @oldesc }
|
17
|
+
|
18
|
+
it "should escape standard non-safe characters" do
|
19
|
+
@object.escape("some string").should == "some%20string"
|
20
|
+
@object.escape("another^one").should == "another%5Eone"
|
21
|
+
@object.escape("bracket[one").should == "bracket%5Bone"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should escape slashes" do
|
25
|
+
@object.escape("some/inner/path").should == "some%2Finner%2Fpath"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should convert the bucket or key to a string before escaping" do
|
29
|
+
@object.escape(125).should == '125'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should unescape escaped strings" do
|
33
|
+
@object.unescape("some%20string").should == "some string"
|
34
|
+
@object.unescape("another%5Eone").should == "another^one"
|
35
|
+
@object.unescape("bracket%5Bone").should == "bracket[one"
|
36
|
+
@object.unescape("some%2Finner%2Fpath").should == "some/inner/path"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when using URI for escaping" do
|
41
|
+
before { @oldesc, Riak.escaper = Riak.escaper, URI }
|
42
|
+
after { Riak.escaper = @oldesc }
|
43
|
+
|
44
|
+
it "should escape standard non-safe characters" do
|
45
|
+
@object.escape("some string").should == "some%20string"
|
46
|
+
@object.escape("another^one").should == "another%5Eone"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should allow URI-safe characters" do
|
50
|
+
@object.escape("bracket[one").should == "bracket[one"
|
51
|
+
@object.escape("sean@basho").should == "sean@basho"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should escape slashes" do
|
55
|
+
@object.escape("some/inner/path").should == "some%2Finner%2Fpath"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should convert the bucket or key to a string before escaping" do
|
59
|
+
@object.escape(125).should == '125'
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should unescape escaped strings" do
|
63
|
+
@object.unescape("some%20string").should == "some string"
|
64
|
+
@object.unescape("another%5Eone").should == "another^one"
|
65
|
+
@object.unescape("bracket%5Bone").should == "bracket[one"
|
66
|
+
@object.unescape("some%2Finner%2Fpath").should == "some/inner/path"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'excon'
|
5
|
+
rescue LoadError
|
6
|
+
warn "Skipping ExconBackend specs, excon library not found."
|
7
|
+
else
|
8
|
+
$mock_server = DrbMockServer
|
9
|
+
$mock_server.maybe_start
|
10
|
+
|
11
|
+
describe Riak::Client::ExconBackend do
|
12
|
+
def setup_http_mock(method, uri, options={})
|
13
|
+
method = method.to_s.upcase
|
14
|
+
uri = URI.parse(uri)
|
15
|
+
path = uri.path || "/"
|
16
|
+
query = uri.query || ""
|
17
|
+
body = options[:body] || []
|
18
|
+
headers = options[:headers] || {}
|
19
|
+
headers['Content-Type'] ||= "text/plain"
|
20
|
+
status = options[:status] ? Array(options[:status]).first.to_i : 200
|
21
|
+
@_mock_set = [status, headers, method, path, query, body]
|
22
|
+
$mock_server.expect(*@_mock_set)
|
23
|
+
end
|
24
|
+
|
25
|
+
before :each do
|
26
|
+
@client = Riak::Client.new(:http_port => $mock_server.port, :http_backend => :Excon) # Point to our mock
|
27
|
+
@backend = @client.http
|
28
|
+
@_mock_set = false
|
29
|
+
end
|
30
|
+
|
31
|
+
after :each do
|
32
|
+
if @_mock_set
|
33
|
+
$mock_server.satisfied.should be_true("Expected #{@_mock_set.inspect}, failed")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it_should_behave_like "HTTP backend"
|
38
|
+
|
39
|
+
it "should split long headers into 8KB chunks" do
|
40
|
+
# TODO: This doesn't actually inspect the emitted headers. How
|
41
|
+
# can it?
|
42
|
+
setup_http_mock(:put, @backend.path("/riak/","foo").to_s, :body => "ok")
|
43
|
+
lambda do
|
44
|
+
@backend.put(200, "/riak/", "foo", "body",{"Long-Header" => (["12345678"*10]*100).join(", ") })
|
45
|
+
end.should_not raise_error
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should support IO objects as the request body" do
|
49
|
+
file = File.open(File.expand_path("../../fixtures/cat.jpg", __FILE__), 'rb')
|
50
|
+
lambda do
|
51
|
+
setup_http_mock(:put, @backend.path("/riak/","foo").to_s, :body => "ok")
|
52
|
+
@backend.put(200, "/riak/", "foo", file, {})
|
53
|
+
$mock_server.satisfied.should be_true
|
54
|
+
end.should_not raise_error
|
55
|
+
file.rewind # Have to rewind the file or we hang
|
56
|
+
lambda do
|
57
|
+
setup_http_mock(:post, @backend.path("/riak/","foo").to_s, :body => "ok")
|
58
|
+
@backend.post(200, "/riak/", "foo", file, {})
|
59
|
+
$mock_server.satisfied.should be_true
|
60
|
+
end.should_not raise_error
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riak::Util::Headers do
|
4
|
+
it "should include the Net::HTTPHeader module" do
|
5
|
+
Riak::Util::Headers.included_modules.should include(Net::HTTPHeader)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be initially empty" do
|
9
|
+
Riak::Util::Headers.new.to_hash.should == {}
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should parse a header line into the key and value" do
|
13
|
+
Riak::Util::Headers.parse("Content-Type: text/plain\r\n").should == ["Content-Type", "text/plain"]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should parse a header line and add it to the collection" do
|
17
|
+
h = Riak::Util::Headers.new
|
18
|
+
h.parse("Content-Type: text/plain\r\n")
|
19
|
+
h.to_hash.should == {"content-type" => ["text/plain"]}
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should split headers larger than 8KB" do
|
23
|
+
# This really tests Net::HTTPHeader#each_capitalized, which is
|
24
|
+
# used by Net::HTTP to write the headers to the socket. It does
|
25
|
+
# not cover the case where a single value is larger than 8KB. If
|
26
|
+
# you're doing that, you have something else wrong.
|
27
|
+
h = Riak::Util::Headers.new
|
28
|
+
10.times do
|
29
|
+
h.add_field "Link", "f" * 820
|
30
|
+
end
|
31
|
+
count = 0
|
32
|
+
h.each_capitalized do |k,v|
|
33
|
+
count += 1
|
34
|
+
"#{k}: #{v}\r\n".length.should < 8192
|
35
|
+
end
|
36
|
+
count.should > 1
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riak::Client::HTTPBackend::Configuration do
|
4
|
+
before do
|
5
|
+
@client = Riak::Client.new
|
6
|
+
@backend = Riak::Client::HTTPBackend.new(@client)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should memoize the server config" do
|
10
|
+
@backend.should_receive(:get).with(200, "/", {}, {}).once.and_return(:headers => {'link' => ['</riak>; rel="riak_kv_wm_link_walker",</mapred>; rel="riak_kv_wm_mapred",</ping>; rel="riak_kv_wm_ping",</riak>; rel="riak_kv_wm_raw",</stats>; rel="riak_kv_wm_stats"']})
|
11
|
+
@backend.send(:riak_kv_wm_link_walker).should == "/riak"
|
12
|
+
@backend.send(:riak_kv_wm_raw).should == "/riak"
|
13
|
+
end
|
14
|
+
|
15
|
+
{
|
16
|
+
:riak_kv_wm_raw => :prefix,
|
17
|
+
:riak_kv_wm_link_walker => :prefix,
|
18
|
+
:riak_kv_wm_mapred => :mapred
|
19
|
+
}.each do |resource, alternate|
|
20
|
+
it "should detect the #{resource} resource from the configuration URL" do
|
21
|
+
@backend.should_receive(:get).with(200, "/", {}, {}).and_return(:headers => {'link' => [%Q{</path>; rel="#{resource}"}]})
|
22
|
+
@backend.send(resource).should == "/path"
|
23
|
+
end
|
24
|
+
it "should fallback to client.#{alternate} if the #{resource} resource is not found" do
|
25
|
+
@backend.should_receive(:get).with(200, "/", {}, {}).and_return(:headers => {'link' => ['</>; rel="top"']})
|
26
|
+
@backend.send(resource).should == @client.send(alternate)
|
27
|
+
end
|
28
|
+
it "should fallback to client.#{alternate} if request fails" do
|
29
|
+
@backend.should_receive(:get).with(200, "/", {}, {}).and_raise(Riak::HTTPFailedRequest.new(:get, 200, 404, {}, ""))
|
30
|
+
@backend.send(resource).should == @client.send(alternate)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
{
|
35
|
+
:riak_kv_wm_ping => "/ping",
|
36
|
+
:riak_kv_wm_stats => "/stats"
|
37
|
+
}.each do |resource, default|
|
38
|
+
it "should detect the #{resource} resource from the configuration URL" do
|
39
|
+
@backend.should_receive(:get).with(200, "/", {}, {}).and_return(:headers => {'link' => [%Q{</path>; rel="#{resource}"}]})
|
40
|
+
@backend.send(resource).should == "/path"
|
41
|
+
end
|
42
|
+
it "should fallback to #{default.inspect} if the #{resource} resource is not found" do
|
43
|
+
@backend.should_receive(:get).with(200, "/", {}, {}).and_return(:headers => {'link' => ['</>; rel="top"']})
|
44
|
+
@backend.send(resource).should == default
|
45
|
+
end
|
46
|
+
it "should fallback to #{default.inspect} if request fails" do
|
47
|
+
@backend.should_receive(:get).with(200, "/", {}, {}).and_raise(Riak::HTTPFailedRequest.new(:get, 200, 404, {}, ""))
|
48
|
+
@backend.send(resource).should == default
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riak::Client::HTTPBackend::ObjectMethods do
|
4
|
+
before :each do
|
5
|
+
@client = Riak::Client.new
|
6
|
+
@backend = Riak::Client::HTTPBackend.new(@client)
|
7
|
+
@bucket = Riak::Bucket.new(@client, "bucket")
|
8
|
+
@object = Riak::RObject.new(@bucket, "bar")
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "loading object data from the response" do
|
12
|
+
it "should load the content type" do
|
13
|
+
@backend.load_object(@object, {:headers => {"content-type" => ["application/json"]}})
|
14
|
+
@object.content_type.should == "application/json"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should load the body data" do
|
18
|
+
@backend.load_object(@object, {:headers => {"content-type" => ["application/json"]}, :body => '{"foo":"bar"}'})
|
19
|
+
@object.raw_data.should be_present
|
20
|
+
@object.data.should be_present
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should handle raw data properly" do
|
24
|
+
@object.should_not_receive(:deserialize) # optimize for the raw_data case, don't penalize people for using raw_data
|
25
|
+
@backend.load_object(@object, {:headers => {"content-type" => ["application/json"]}, :body => body = '{"foo":"bar"}'})
|
26
|
+
@object.raw_data.should == body
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should deserialize the body data" do
|
30
|
+
@object.should_receive(:deserialize).with("{}").and_return({})
|
31
|
+
@backend.load_object(@object, {:headers => {"content-type" => ["application/json"]}, :body => "{}"})
|
32
|
+
@object.data.should == {}
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should leave the object data unchanged if the response body is blank" do
|
36
|
+
@object.data = "Original data"
|
37
|
+
@backend.load_object(@object, {:headers => {"content-type" => ["application/json"]}, :body => ""})
|
38
|
+
@object.data.should == "Original data"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should load the vclock from the headers" do
|
42
|
+
@backend.load_object(@object, {:headers => {"content-type" => ["application/json"], 'x-riak-vclock' => ["somereallylongbase64string=="]}, :body => "{}"})
|
43
|
+
@object.vclock.should == "somereallylongbase64string=="
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should load links from the headers" do
|
47
|
+
@backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "link" => ['</riak/bar>; rel="up"']}, :body => "{}"})
|
48
|
+
@object.links.should have(1).item
|
49
|
+
@object.links.first.url.should == "/riak/bar"
|
50
|
+
@object.links.first.rel.should == "up"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should load the ETag from the headers" do
|
54
|
+
@backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "etag" => ["32748nvas83572934"]}, :body => "{}"})
|
55
|
+
@object.etag.should == "32748nvas83572934"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should load the modified date from the headers" do
|
59
|
+
time = Time.now
|
60
|
+
@backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "last-modified" => [time.httpdate]}, :body => "{}"})
|
61
|
+
@object.last_modified.to_s.should == time.to_s # bah, times are not equivalent unless equal
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should load meta information from the headers" do
|
65
|
+
@backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "x-riak-meta-some-kind-of-robot" => ["for AWESOME"]}, :body => "{}"})
|
66
|
+
@object.meta["some-kind-of-robot"].should == ["for AWESOME"]
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should parse the location header into the key when present" do
|
70
|
+
@backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "location" => ["/riak/foo/baz"]}})
|
71
|
+
@object.key.should == "baz"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should parse and escape the location header into the key when present" do
|
75
|
+
@backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "location" => ["/riak/foo/%5Bbaz%5D?vtag=1234"]}})
|
76
|
+
@object.key.should == "[baz]"
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when the response code is 300 and the content-type is multipart/mixed" do
|
80
|
+
let(:http_response) { {:headers => {"content-type" => ["multipart/mixed; boundary=foo"]}, :code => 300 } }
|
81
|
+
let(:other_object) { Riak::RObject.new(@bucket, "bar2") }
|
82
|
+
|
83
|
+
it 'marks the object as in conflict' do
|
84
|
+
@backend.load_object(@object, http_response)
|
85
|
+
@object.should be_conflict
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'attempts to resolve the conflict' do
|
89
|
+
@object.should respond_to(:attempt_conflict_resolution)
|
90
|
+
@object.should_receive(:attempt_conflict_resolution).and_return(other_object)
|
91
|
+
@backend.load_object(@object, http_response).should be(other_object)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should unescape the key given in the location header" do
|
96
|
+
@backend.load_object(@object, {:headers => {"content-type" => ["application/json"], "location" => ["/riak/foo/baz%20"]}})
|
97
|
+
@object.key.should == "baz "
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "extracting siblings" do
|
101
|
+
before :each do
|
102
|
+
@backend.load_object(@object, {:headers => {"x-riak-vclock" => ["merged"], "content-type" => ["multipart/mixed; boundary=foo"]}, :code => 300, :body => "\n--foo\nContent-Type: text/plain\n\nbar\n--foo\nContent-Type: text/plain\n\nbaz\n--foo--\n"})
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should extract the siblings" do
|
106
|
+
@object.should have(2).siblings
|
107
|
+
siblings = @object.siblings
|
108
|
+
siblings[0].data.should == "bar"
|
109
|
+
siblings[1].data.should == "baz"
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should set the key on both siblings" do
|
113
|
+
@object.siblings.should be_all {|s| s.key == "bar" }
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should set the vclock on both siblings to the merged vclock" do
|
117
|
+
@object.siblings.should be_all {|s| s.vclock == "merged" }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "headers used for storing the object" do
|
123
|
+
it "should include the content type" do
|
124
|
+
@object.content_type = "application/json"
|
125
|
+
@backend.store_headers(@object)["Content-Type"].should == "application/json"
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should include the vclock when present" do
|
129
|
+
@object.vclock = "123445678990"
|
130
|
+
@backend.store_headers(@object)["X-Riak-Vclock"].should == "123445678990"
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should exclude the vclock when nil" do
|
134
|
+
@object.vclock = nil
|
135
|
+
@backend.store_headers(@object).should_not have_key("X-Riak-Vclock")
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "when conditional PUTs are requested" do
|
139
|
+
before :each do
|
140
|
+
@object.prevent_stale_writes = true
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should include an If-None-Match: * header" do
|
144
|
+
@backend.store_headers(@object).should have_key("If-None-Match")
|
145
|
+
@backend.store_headers(@object)["If-None-Match"].should == "*"
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should include an If-Match header with the etag when an etag is present" do
|
149
|
+
@object.etag = "foobar"
|
150
|
+
@backend.store_headers(@object).should have_key("If-Match")
|
151
|
+
@backend.store_headers(@object)["If-Match"].should == @object.etag
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe "when links are defined" do
|
156
|
+
before :each do
|
157
|
+
@object.links << Riak::Link.new("/riak/foo/baz", "next")
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should include a Link header with references to other objects" do
|
161
|
+
@backend.store_headers(@object).should have_key("Link")
|
162
|
+
@backend.store_headers(@object)["Link"].should include('</riak/foo/baz>; riaktag="next"')
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should exclude the 'up' link to the bucket from the header" do
|
166
|
+
@object.links << Riak::Link.new("/riak/foo", "up")
|
167
|
+
@backend.store_headers(@object).should have_key("Link")
|
168
|
+
@backend.store_headers(@object)["Link"].should_not include('riaktag="up"')
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should exclude the Link header when no links are present" do
|
173
|
+
@object.links = Set.new
|
174
|
+
@backend.store_headers(@object).should_not have_key("Link")
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "when meta fields are present" do
|
178
|
+
before :each do
|
179
|
+
@object.meta = {"some-kind-of-robot" => true, "powers" => "for awesome", "cold-ones" => 10}
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should include X-Riak-Meta-* headers for each meta key" do
|
183
|
+
@backend.store_headers(@object).should have_key("X-Riak-Meta-some-kind-of-robot")
|
184
|
+
@backend.store_headers(@object).should have_key("X-Riak-Meta-cold-ones")
|
185
|
+
@backend.store_headers(@object).should have_key("X-Riak-Meta-powers")
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should turn non-string meta values into strings" do
|
189
|
+
@backend.store_headers(@object)["X-Riak-Meta-some-kind-of-robot"].should == "true"
|
190
|
+
@backend.store_headers(@object)["X-Riak-Meta-cold-ones"].should == "10"
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should leave string meta values unchanged in the header" do
|
194
|
+
@backend.store_headers(@object)["X-Riak-Meta-powers"].should == "for awesome"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "headers used for reloading the object" do
|
200
|
+
it "should be blank when the etag and last_modified properties are blank" do
|
201
|
+
@object.etag.should be_blank
|
202
|
+
@object.last_modified.should be_blank
|
203
|
+
@backend.reload_headers(@object).should be_blank
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should include the If-None-Match key when the etag is present" do
|
207
|
+
@object.etag = "etag!"
|
208
|
+
@backend.reload_headers(@object)['If-None-Match'].should == "etag!"
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should include the If-Modified-Since header when the last_modified time is present" do
|
212
|
+
time = Time.now
|
213
|
+
@object.last_modified = time
|
214
|
+
@backend.reload_headers(@object)['If-Modified-Since'].should == time.httpdate
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|