Skip to content

Commit

Permalink
Allow to pass option to COPY instead of REPLACE objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
miloops committed Nov 18, 2010
1 parent 51576d1 commit bb0b6f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/s3/object.rb
Expand Up @@ -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]
Expand Down
19 changes: 14 additions & 5 deletions test/object_test.rb
Expand Up @@ -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.