Permalink
Browse files

Allow to pass option to COPY instead of REPLACE objects.

  • Loading branch information...
1 parent 51576d1 commit bb0b6f9660846b1514062b51094baac7d1216f54 @miloops committed Nov 18, 2010
Showing with 15 additions and 6 deletions.
  1. +1 −1 lib/s3/object.rb
  2. +14 −5 test/object_test.rb
View
@@ -150,7 +150,7 @@ def copy_object(options = {})
headers[:content_disposition] = options[:content_disposition] if options[:content_disposition]
headers[:cache_control] = options[:cache_control] if options[:cache_control]
headers[:x_amz_copy_source] = full_key
- headers[:x_amz_metadata_directive] = "REPLACE"
+ headers[:x_amz_metadata_directive] = options[:replace] == false ? "COPY" : "REPLACE"
headers[:x_amz_copy_source_if_match] = options[:if_match] if options[:if_match]
headers[:x_amz_copy_source_if_none_match] = options[:if_none_match] if options[:if_none_match]
headers[:x_amz_copy_source_if_unmodified_since] = options[:if_modified_since] if options[:if_modified_since]
View
@@ -157,31 +157,40 @@ def setup
actual = @object_lena.acl
assert_equal expected, actual
end
-
+
test "storage-class writer" do
expected = nil
actual = @object_lena.storage_class
assert_equal expected, actual
-
+
assert @object_lena.storage_class = :standard
-
+
expected = "STANDARD"
actual = @object_lena.storage_class
assert_equal expected, actual
-
+
assert @object_lena.storage_class = :reduced_redundancy
expected = "REDUCED_REDUNDANCY"
actual = @object_lena.storage_class
assert_equal expected, actual
end
- test "copy" do
+ test "replace" do
@bucket_images.expects(:bucket_request).with(:put, :path => "Lena-copy.png", :headers => { :x_amz_acl => "public-read", :content_type => "application/octet-stream", :x_amz_copy_source => "images/Lena.png", :x_amz_metadata_directive => "REPLACE" }).returns(@response_xml)
new_object = @object_lena.copy(:key => "Lena-copy.png")
assert_equal "Lena-copy.png", new_object.key
assert_equal "Lena.png", @object_lena.key
end
+
+ test "copy" do
+ @bucket_images.expects(:bucket_request).with(:put, :path => "Lena-copy.png", :headers => { :x_amz_acl => "public-read", :content_type => "application/octet-stream", :x_amz_copy_source => "images/Lena.png", :x_amz_metadata_directive => "COPY" }).returns(@response_xml)
+
+ new_object = @object_lena.copy(:key => "Lena-copy.png", :replace => false)
+
+ assert_equal "Lena-copy.png", new_object.key
+ assert_equal "Lena.png", @object_lena.key
+ end
end

0 comments on commit bb0b6f9

Please sign in to comment.