Add support for the root directory
This commit is contained in:
@@ -8,7 +8,7 @@ describe "Directories" do
|
||||
purge_all_buckets
|
||||
|
||||
auth = auth_bucket.new("jimmy:123")
|
||||
auth.data = ["documents:r", "tasks:rw"]
|
||||
auth.data = [":r", "documents:r", "tasks:rw"]
|
||||
auth.store
|
||||
|
||||
header "Authorization", "Bearer 123"
|
||||
@@ -107,7 +107,7 @@ describe "Directories" do
|
||||
end
|
||||
end
|
||||
|
||||
describe "for an empty or absent directory" do
|
||||
context "for an empty or absent directory" do
|
||||
it "returns an empty listing" do
|
||||
get "/jimmy/documents/notfound/"
|
||||
|
||||
@@ -115,6 +115,30 @@ describe "Directories" do
|
||||
last_response.body.must_equal "{}"
|
||||
end
|
||||
end
|
||||
|
||||
context "for the root directory" do
|
||||
before do
|
||||
auth = auth_bucket.new("jimmy:123")
|
||||
auth.data = [":rw"]
|
||||
auth.store
|
||||
|
||||
put "/jimmy/root-1", "Put my root down"
|
||||
put "/jimmy/root-2", "Back to the roots"
|
||||
end
|
||||
|
||||
it "lists the containing objects and direct sub-directories" do
|
||||
get "/jimmy/"
|
||||
|
||||
last_response.status.must_equal 200
|
||||
|
||||
content = JSON.parse(last_response.body)
|
||||
content.must_include "root-1"
|
||||
content.must_include "root-2"
|
||||
content.must_include "tasks/"
|
||||
content["tasks/"].to_s.must_match /\d+/
|
||||
content["tasks/"].to_s.length.must_be :>=, 10
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "directory object" do
|
||||
@@ -133,6 +157,18 @@ describe "Directories" do
|
||||
object = directory_bucket.get("jimmy:tasks/home")
|
||||
object.indexes["directory_bin"].must_include "tasks"
|
||||
end
|
||||
|
||||
it "creates directory objects for the parent directories" do
|
||||
put "/jimmy/tasks/home/trash", "take out the trash"
|
||||
|
||||
object = directory_bucket.get("jimmy:tasks")
|
||||
object.indexes["directory_bin"].must_include "/"
|
||||
object.last_modified.wont_be_nil
|
||||
|
||||
object = directory_bucket.get("jimmy:")
|
||||
object.indexes["directory_bin"].must_be_empty
|
||||
object.last_modified.wont_be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "existing directory object" do
|
||||
@@ -177,6 +213,18 @@ describe "Directories" do
|
||||
last_response.headers["Access-Control-Allow-Headers"].must_equal "Authorization, Content-Type, Origin"
|
||||
end
|
||||
end
|
||||
|
||||
context "root directory" do
|
||||
it "has CORS headers set" do
|
||||
options "/jimmy/"
|
||||
|
||||
last_response.status.must_equal 200
|
||||
|
||||
last_response.headers["Access-Control-Allow-Origin"].must_equal "*"
|
||||
last_response.headers["Access-Control-Allow-Methods"].must_equal "GET, PUT, DELETE"
|
||||
last_response.headers["Access-Control-Allow-Headers"].must_equal "Authorization, Content-Type, Origin"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE file" do
|
||||
|
||||
@@ -245,6 +245,42 @@ describe "Permissions" do
|
||||
data_bucket.get("jimmy:documents/very/interesting:text")
|
||||
}.must_raise Riak::HTTPFailedRequest
|
||||
end
|
||||
|
||||
context "root directory" do
|
||||
before do
|
||||
object = data_bucket.new("jimmy::root")
|
||||
object.content_type = "text/plain"
|
||||
object.data = "Back to the roots"
|
||||
object.store
|
||||
end
|
||||
|
||||
it "allows GET requests" do
|
||||
get "/jimmy/root"
|
||||
|
||||
last_response.status.must_equal 200
|
||||
last_response.body.must_equal "Back to the roots"
|
||||
end
|
||||
|
||||
it "allows PUT requests" do
|
||||
put "/jimmy/1", "Gonna kick it root down"
|
||||
|
||||
# File.open('response.html', 'w') do |f|
|
||||
# f.write last_response.body
|
||||
# end
|
||||
|
||||
last_response.status.must_equal 200
|
||||
data_bucket.get("jimmy::1").data.must_equal "Gonna kick it root down"
|
||||
end
|
||||
|
||||
it "allows DELETE requests" do
|
||||
delete "/jimmy/root"
|
||||
|
||||
last_response.status.must_equal 204
|
||||
lambda {
|
||||
data_bucket.get("jimmy::root")
|
||||
}.must_raise Riak::HTTPFailedRequest
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "read all" do
|
||||
|
||||
Reference in New Issue
Block a user