Specs for If-Match header

This commit is contained in:
Garret Alfert
2013-10-26 03:31:54 +02:00
parent 189d202d66
commit 67435157ed

View File

@@ -239,6 +239,29 @@ describe "App with Riak backend" do
last_response.headers["ETag"].wont_be_nil last_response.headers["ETag"].wont_be_nil
last_response.headers["ETag"].wont_equal old_etag last_response.headers["ETag"].wont_equal old_etag
end end
describe "when If-Match header is set" do
it "allows the request if the header matches the current ETag" do
old_etag = last_response.headers["ETag"]
header "If-Match", old_etag
put "/jimmy/documents/archive/foo", "some awesome content"
last_response.status.must_equal 200
get "/jimmy/documents/archive/foo"
last_response.body.must_equal "some awesome content"
end
it "fails the request if the header does not match the current ETag" do
header "If-Match", "WONTMATCH"
put "/jimmy/documents/archive/foo", "some awesome content"
last_response.status.must_equal 412
get "/jimmy/documents/archive/foo"
last_response.body.must_equal "lorem ipsum"
end
end
end end
describe "exsting content without serializer registered for the given content-type" do describe "exsting content without serializer registered for the given content-type" do
@@ -396,6 +419,10 @@ describe "App with Riak backend" do
describe "DELETE" do describe "DELETE" do
before do before do
header "Authorization", "Bearer 123" header "Authorization", "Bearer 123"
end
describe "basics" do
before do
delete "/jimmy/documents/foo" delete "/jimmy/documents/foo"
end end
@@ -419,16 +446,46 @@ describe "App with Riak backend" do
it "sets the ETag header" do it "sets the ETag header" do
last_response.headers["ETag"].wont_be_nil last_response.headers["ETag"].wont_be_nil
end end
end
context "non-existing object" do context "non-existing object" do
before do before do
delete "/jimmy/documents/foozius" delete "/jimmy/documents/foozius"
end end
it "responds with 404" do
last_response.status.must_equal 404
end
it "doesn't log the operation" do it "doesn't log the operation" do
objects = [] objects = []
opslog_bucket.keys.each { |k| objects << opslog_bucket.get(k) rescue nil } opslog_bucket.keys.each { |k| objects << opslog_bucket.get(k) rescue nil }
objects.select{|o| o.data["count"] == -1}.size.must_equal 1 objects.select{|o| o.data["count"] == -1}.size.must_equal 0
end
end
context "when an If-Match header is given" do
it "allows the request if it matches the current ETag" do
get "/jimmy/documents/foo"
old_etag = last_response.headers["ETag"]
header "If-Match", old_etag
delete "/jimmy/documents/foo"
last_response.status.must_equal 204
get "/jimmy/documents/foo"
last_response.status.must_equal 404
end
it "fails the request if it does not match the current ETag" do
header "If-Match", "WONTMATCH"
delete "/jimmy/documents/foo"
last_response.status.must_equal 412
get "/jimmy/documents/foo"
last_response.status.must_equal 200
last_response.body.must_equal "some private text data"
end end
end end