Set indexes for binary objects
This commit is contained in:
		
							parent
							
								
									5384e3d355
								
							
						
					
					
						commit
						44d276a387
					
				| @ -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") | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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} | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user