Do collision detection via Redis metadata

This commit is contained in:
Garret Alfert
2016-01-28 19:06:24 +01:00
parent 4e7c8f68bb
commit 4ca67c7ea9
2 changed files with 92 additions and 0 deletions

View File

@@ -64,6 +64,46 @@ describe "App" do
root_items = redis.smembers "rs_meta:phil:/:items"
root_items.must_equal ["food/"]
end
describe "name collision checks" do
it "is successful when there is no name collision" do
put_stub = OpenStruct.new(headers: {etag: "bla"})
RestClient.stub :put, put_stub do
put "/phil/food/aguacate", "si"
end
last_response.status.must_equal 200
metadata = redis.hgetall "rs_meta:phil:food/aguacate"
metadata["size"].must_equal "2"
end
it "conflicts when there is a directory with same name as document" do
put_stub = OpenStruct.new(headers: {etag: "bla"})
RestClient.stub :put, put_stub do
put "/phil/food/aguacate", "si"
put "/phil/food", "wontwork"
end
last_response.status.must_equal 409
metadata = redis.hgetall "rs_meta:phil:food"
metadata.must_be_empty
end
it "conflicts when there is a document with same name as directory" do
put_stub = OpenStruct.new(headers: {etag: "bla"})
RestClient.stub :put, put_stub do
put "/phil/food/aguacate", "si"
put "/phil/food/aguacate/empanado", "wontwork"
end
last_response.status.must_equal 409
metadata = redis.hgetall "rs_meta:phil:food/aguacate/empanado"
metadata.must_be_empty
end
end
end
end