diff --git a/lib/remote_storage/riak.rb b/lib/remote_storage/riak.rb index 45f6c9d..3ab09ea 100644 --- a/lib/remote_storage/riak.rb +++ b/lib/remote_storage/riak.rb @@ -84,17 +84,19 @@ module RemoteStorage object = data_bucket.new("#{user}:#{directory}:#{key}") object.content_type = content_type || "text/plain; charset=utf-8" + directory_index = directory == "" ? "/" : directory + object.indexes.merge!({:user_id_bin => [user], + :directory_bin => [CGI.escape(directory_index)]}) + + timestamp = (Time.now.to_f * 1000).to_i + object.meta["timestamp"] = timestamp + if binary_data?(content_type) save_binary_data(object, data) or halt 422 else set_object_data(object, data) or halt 422 end - directory_index = directory == "" ? "/" : directory - object.indexes.merge!({:user_id_bin => [user], - :directory_bin => [CGI.escape(directory_index)]}) - timestamp = (Time.now.to_f * 1000).to_i - object.meta["timestamp"] = timestamp object.store update_all_directory_objects(user, directory, timestamp) @@ -299,6 +301,7 @@ module RemoteStorage binary_object = binary_bucket.new(object.key) binary_object.content_type = object.content_type binary_object.raw_data = data + binary_object.indexes = object.indexes binary_object.store link = ::Riak::Link.new(binary_bucket.name, binary_object.key, "binary") diff --git a/spec/riak_spec.rb b/spec/riak_spec.rb index 5c2e352..82ec497 100644 --- a/spec/riak_spec.rb +++ b/spec/riak_spec.rb @@ -205,6 +205,14 @@ describe "App with Riak backend" do last_response.status.must_equal 200 last_response.body.must_equal @image end + + it "indexes the binary set" do + indexes = binary_bucket.get("jimmy:documents:jaypeg").indexes + indexes["user_id_bin"].must_be_kind_of Set + indexes["user_id_bin"].must_include "jimmy" + + indexes["directory_bin"].must_include "documents" + end end context "with escaped key" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 23b086f..05aceed 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,6 +38,10 @@ def directory_bucket @directory_bucket ||= storage_client.bucket(settings.bucket_config['directories']) end +def binary_bucket + @binary_bucket ||= storage_client.bucket(settings.bucket_config['binaries']) +end + def purge_all_buckets [data_bucket, directory_bucket, auth_bucket].each do |bucket| bucket.keys.each {|key| bucket.delete key}