diff --git a/lib/remote_storage/riak.rb b/lib/remote_storage/riak.rb index 37debbb..45f6c9d 100644 --- a/lib/remote_storage/riak.rb +++ b/lib/remote_storage/riak.rb @@ -105,6 +105,12 @@ module RemoteStorage end def delete_data(user, directory, key) + object = data_bucket.get("#{user}:#{directory}:#{key}") + + if binary_link = object.links.select {|l| l.tag == "binary"}.first + client[binary_link.bucket].delete(binary_link.key) + end + riak_response = data_bucket.delete("#{user}:#{directory}:#{key}") timestamp = (Time.now.to_f * 1000).to_i diff --git a/spec/riak_spec.rb b/spec/riak_spec.rb index 7d4ff3b..5c2e352 100644 --- a/spec/riak_spec.rb +++ b/spec/riak_spec.rb @@ -248,8 +248,11 @@ describe "App with Riak backend" do end describe "DELETE" do - it "removes the key" do + before do header "Authorization", "Bearer 123" + end + + it "removes the key" do delete "/jimmy/documents/foo" last_response.status.must_equal 204 @@ -257,6 +260,33 @@ describe "App with Riak backend" do data_bucket.get("jimmy:documents:foo") }.must_raise Riak::HTTPFailedRequest end + + context "binary data" do + before do + header "Content-Type", "image/jpeg; charset=binary" + filename = File.join(File.expand_path(File.dirname(__FILE__)), "fixtures", "rockrule.jpeg") + @image = File.open(filename, "r").read + put "/jimmy/documents/jaypeg", @image + end + + it "removes the main object" do + delete "/jimmy/documents/jaypeg" + + last_response.status.must_equal 204 + lambda { + data_bucket.get("jimmy:documents:jaypeg") + }.must_raise Riak::HTTPFailedRequest + end + + it "removes the binary object" do + delete "/jimmy/documents/jaypeg" + + last_response.status.must_equal 204 + lambda { + binary_bucket.get("jimmy:documents:jaypeg") + }.must_raise Riak::HTTPFailedRequest + end + end end end