diff --git a/spec/directories_spec.rb b/spec/directories_spec.rb index 56763be..8b7e806 100644 --- a/spec/directories_spec.rb +++ b/spec/directories_spec.rb @@ -65,6 +65,30 @@ describe "Directories" do last_response.headers["Access-Control-Allow-Headers"].must_equal "Authorization, Content-Type, Origin" end + context "when If-None-Match header is set" do + before do + get "/jimmy/tasks/" + + @etag = last_response.headers["ETag"] + end + + it "responds with 'not modified' when it matches the current ETag" do + header "If-None-Match", @etag + get "/jimmy/tasks/" + + last_response.status.must_equal 304 + last_response.body.must_be_empty + end + + it "responds normally when it does not match the current ETag" do + header "If-None-Match", "FOO" + get "/jimmy/tasks/" + + last_response.status.must_equal 200 + last_response.body.wont_be_empty + end + end + context "with sub-directories" do before do get "/jimmy/tasks/" diff --git a/spec/riak_spec.rb b/spec/riak_spec.rb index f70cc72..d908150 100644 --- a/spec/riak_spec.rb +++ b/spec/riak_spec.rb @@ -63,19 +63,42 @@ describe "App with Riak backend" do object.data = "some private text data" object.store + @etag = object.etag + auth = auth_bucket.new("jimmy:123") auth.data = ["documents", "public"] auth.store end describe "GET" do - it "returns the value" do + before do header "Authorization", "Bearer 123" + end + + it "returns the value" do get "/jimmy/documents/foo" last_response.status.must_equal 200 last_response.body.must_equal "some private text data" end + + describe "when If-None-Match header is set" do + it "responds with 'not modified' when it matches the current ETag" do + header "If-None-Match", @etag + get "/jimmy/documents/foo" + + last_response.status.must_equal 304 + last_response.body.must_be_empty + end + + it "responds normally when it does not match the current ETag" do + header "If-None-Match", "FOO" + get "/jimmy/documents/foo" + + last_response.status.must_equal 200 + last_response.body.must_equal "some private text data" + end + end end describe "GET nonexisting key" do