Merge branch 'master' into rs_spec_02

Conflicts:
	lib/remote_storage/riak.rb
	spec/directories_spec.rb
This commit is contained in:
Garret Alfert 2014-09-23 17:58:21 +02:00
commit 1603d3d2ff
6 changed files with 59 additions and 25 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
config.yml
cs_credentials.json
pids
.bundle
vendor/bundle

View File

@ -1,8 +1,8 @@
source "http://rubygems.org"
source "https://rubygems.org"
gem "sinatra"
gem "sinatra-contrib"
gem "activesupport"
gem "activesupport", '~> 3.2'
gem "riak-client", :github => "5apps/riak-ruby-client", :branch => "invalid_uri_error"
gem "fog"

View File

@ -11,10 +11,10 @@ GIT
multi_json (~> 1.0)
GEM
remote: http://rubygems.org/
remote: https://rubygems.org/
specs:
activesupport (3.2.13)
i18n (= 0.6.1)
activesupport (3.2.18)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
backports (3.3.0)
beefcake (0.3.7)
@ -32,20 +32,20 @@ GEM
nokogiri (~> 1.5.0)
ruby-hmac
formatador (0.2.4)
i18n (0.6.1)
i18n (0.6.9)
innertube (1.0.2)
kgio (2.7.4)
kgio (2.9.2)
m (1.2.1)
method_source (>= 0.6.7)
rake (>= 0.9.2.2, < 1.0.0)
method_source (0.8)
mime-types (1.23)
minitest (2.10.0)
multi_json (1.8.0)
multi_json (1.10.0)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-ssh (2.6.7)
nokogiri (1.5.10)
nokogiri (1.5.11)
purdytest (1.0.0)
minitest (~> 2.2)
rack (1.5.2)
@ -53,11 +53,11 @@ GEM
rack
rack-test (0.6.2)
rack (>= 1.0)
rainbows (4.4.3)
rainbows (4.6.1)
kgio (~> 2.5)
rack (~> 1.1)
unicorn (~> 4.1)
raindrops (0.10.0)
unicorn (~> 4.8)
raindrops (0.13.0)
rake (0.9.2.2)
ruby-hmac (0.4.0)
sinatra (1.4.3)
@ -72,7 +72,7 @@ GEM
sinatra (~> 1.4.2)
tilt (~> 1.3)
tilt (1.4.1)
unicorn (4.3.1)
unicorn (4.8.2)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
@ -81,7 +81,7 @@ PLATFORMS
ruby
DEPENDENCIES
activesupport
activesupport (~> 3.2)
fog
m
purdytest

View File

@ -289,17 +289,19 @@ module RemoteStorage
map_query = <<-EOH
function(v){
var values = v.values[0];
var metadata = values['metadata'];
var keys = v.key.split(':');
keys.splice(0, 2);
var key_name = keys.join(':');
var metadata = v.values[0]['metadata'];
var dir_name = metadata['index']['directory_bin'];
if (dir_name === '/') {
dir_name = '';
}
var name = v.key.match(/^[^:]*:(.*)/)[1]; // strip username from key
name = name.replace(dir_name + ':', ''); // strip directory from key
var etag = metadata['X-Riak-VTag'];
var contentType = metadata['content-type'];
var contentLength = metadata['X-Riak-Meta']['X-Riak-Meta-Content_length'] || 0;
return [{
name: key_name,
name: name,
etag: etag,
contentType: contentType,
contentLength: contentLength
@ -316,12 +318,11 @@ module RemoteStorage
map_query = <<-EOH
function(v){
var keys = v.key.split(':');
var key_name = keys[keys.length-1];
var name = v.key.match(/^[^:]*:(.*)/)[1]; // strip username from key
var etag = v.values[0]['metadata']['X-Riak-VTag'];
return [{
name: key_name,
name: name,
etag: etag
}];
}

View File

@ -57,6 +57,7 @@ describe "Directories" do
before do
put "/jimmy/tasks/foo", "do the laundry"
put "/jimmy/tasks/http%3A%2F%2F5apps.com", "prettify design"
put "/jimmy/tasks/%3A/foo%3Abar%40foo.org", "hello world"
end
it "lists the objects with version, length and content-type" do
@ -69,6 +70,7 @@ describe "Directories" do
content = JSON.parse(last_response.body)
content["items"]["http://5apps.com"].wont_be_nil
content["items"][":/"].wont_be_nil
content["items"]["foo"].wont_be_nil
content["items"]["foo"]["ETag"].must_equal foo.etag.gsub(/"/, "")
content["items"]["foo"]["Content-Type"].must_equal "text/plain"
@ -104,6 +106,16 @@ describe "Directories" do
last_response.headers["Expires"].must_equal "0"
end
it "doesn't choke on colons in the directory name" do
get "/jimmy/tasks/%3A/"
last_response.status.must_equal 200
last_response.content_type.must_equal "application/json"
content = JSON.parse(last_response.body)
content["items"]["foo:bar@foo.org"].wont_be_nil
end
context "when If-None-Match header is set" do
before do
get "/jimmy/tasks/"

View File

@ -543,17 +543,36 @@ describe "App with Riak backend" do
context "with escaped key" do
before do
put "/jimmy/documents/http%3A%2F%2F5apps.com", "super website"
put "/jimmy/documents/bar%3Abaz/http%3A%2F%2F5apps.com", "super website"
end
it "delivers the data correctly" do
header "Authorization", "Bearer 123"
get "/jimmy/documents/http%3A%2F%2F5apps.com"
get "/jimmy/documents/bar%3Abaz/http%3A%2F%2F5apps.com"
last_response.body.must_equal 'super website'
end
end
context "with unescaped key" do
before do
put "/jimmy/documents/bar:baz/john@doe.com", "John Doe"
end
it "lists the document in the directory" do
get "/jimmy/documents/bar:baz/"
content = JSON.parse(last_response.body)
content["items"]["john@doe.com"].wont_be_nil
end
it "delivers the data correctly" do
get "/jimmy/documents/bar:baz/john@doe.com"
last_response.body.must_equal "John Doe"
end
end
context "escaped square brackets in key" do
before do
put "/jimmy/documents/gracehopper%5B1%5D.jpg", "super image"