aws-ext 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,13 +8,17 @@ Extensions for the aws-s3 gem
8
8
 
9
9
  == S3Object
10
10
 
11
- === .copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, acl_policy)
11
+ === .copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, acl_policy = :public_read)
12
12
 
13
- Copies arbitrary S3Object across buckets using the Amazon S3 copy option. ACLs default to :public_read. Passing :copy as the ACL will copy the sources ACL.
13
+ Copies arbitrary S3Object across buckets using the Amazon S3 copy option. ACLs
14
+ default to :public_read. Passing :copy as the ACL will copy the ACL from the
15
+ source.
14
16
 
15
17
  === #copy_to_bucket(dest_bucket, dest_key = nil, acl_policy = :copy)
16
18
 
17
- Copies this S3Object across buckets using the Amazon S3 copy option. Destination key defaults to Source key.ACLs default to :public_read. Passing :copy as the ACL will copy the sources ACL.
19
+ Copies this S3Object across buckets using the Amazon S3 copy option.
20
+ Destination key defaults to Source key. Passing :copy as the ACL will copy the
21
+ ACL form the source.
18
22
 
19
23
  == Bucket
20
24
 
@@ -41,7 +45,8 @@ Paginates over all objects in the bucket. :max_keys defaults to 100.
41
45
  * Add tests for it. This is important so I don't break it in a
42
46
  future version unintentionally.
43
47
  * Commit, do not mess with rakefile, version, or history.
44
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
48
+ (if you want to have your own version, that is fine but bump version in a
49
+ commit by itself I can ignore when I pull)
45
50
  * Send me a pull request. Bonus points for topic branches.
46
51
 
47
52
  == Copyright
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{aws-ext}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Les Hill"]
@@ -3,7 +3,7 @@ require 'aws/s3'
3
3
  module AWS
4
4
  module S3
5
5
  class S3Object
6
- def self.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, acl_policy)
6
+ def self.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, acl_policy = :public_read)
7
7
  headers = {'x-amz-copy-source' => path!(src_bucket, src_key)}
8
8
  if acl_policy == :copy
9
9
  returning put(path!(dest_bucket, dest_key), headers) do
@@ -47,54 +47,56 @@ describe 'aws_ext' do
47
47
  end
48
48
 
49
49
  context "AWS::S3::S3Object" do
50
- it "#copy_to_bucket delegates to S3Object.copy_across_buckets with defaults" do
51
- key = 'key'
52
- src_bucket_name = 'src_bucket'
53
- src_bucket = AWS::S3::Bucket.new(:name => src_bucket_name)
54
- dest_bucket_name = 'dest_bucket'
55
- dest_bucket = AWS::S3::Bucket.new(:name => dest_bucket_name)
56
- AWS::S3::S3Object.should_receive(:copy_across_buckets).with(src_bucket_name, key, dest_bucket_name, key, :copy)
57
- AWS::S3::S3Object.new(:bucket => src_bucket, 'key' => key).copy_to_bucket(dest_bucket)
58
- end
50
+ let(:src_key) { 'src_key' }
51
+ let(:dest_key) { 'dest_key' }
52
+ let(:src_bucket) { 'src_bucket' }
53
+ let(:dest_bucket) { 'dest_bucket' }
59
54
 
60
- it "#copy_to_bucket delegates to S3Object.copy_across_buckets without defaults" do
61
- acl = :public_read
62
- src_key = 'src_key'
63
- dest_key = 'dest_key'
64
- src_bucket_name = 'src_bucket'
65
- src_bucket = AWS::S3::Bucket.new(:name => src_bucket_name)
66
- dest_bucket_name = 'dest_bucket'
67
- dest_bucket = AWS::S3::Bucket.new(:name => dest_bucket_name)
68
- AWS::S3::S3Object.should_receive(:copy_across_buckets).with(src_bucket_name, src_key, dest_bucket_name, dest_key, acl)
69
- AWS::S3::S3Object.new(:bucket => src_bucket, 'key' => src_key).copy_to_bucket(dest_bucket, dest_key, acl)
70
- end
55
+ describe "#copy_to_bucket" do
56
+ let(:s3bucket_src) { AWS::S3::Bucket.new(:name => src_bucket) }
57
+ let(:s3bucket_dest) { AWS::S3::Bucket.new(:name => dest_bucket) }
58
+ let(:s3object) { AWS::S3::S3Object.new(:bucket => s3bucket_src, 'key' => src_key) }
59
+
60
+ it "#copy_to_bucket delegates to S3Object.copy_across_buckets with defaults" do
61
+ AWS::S3::S3Object.should_receive(:copy_across_buckets).with(src_bucket, src_key, dest_bucket, src_key, :copy)
62
+ s3object.copy_to_bucket(s3bucket_dest)
63
+ end
71
64
 
72
- it ".copy_across_buckets when passed an acl_policy that is not :copy just puts the copy" do
73
- acl = :public_read
74
- src_key = 'src_key'
75
- dest_key = 'dest_key'
76
- src_bucket = 'src_bucket'
77
- dest_bucket = 'dest_bucket'
78
- headers = {}
79
- headers['x-amz-copy-source'] = AWS::S3::S3Object.path!(src_bucket, src_key)
80
- headers['x-amz-acl'] = acl
81
- AWS::S3::S3Object.should_receive(:put).with(AWS::S3::S3Object.path!(dest_bucket, dest_key), headers)
82
- AWS::S3::S3Object.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, :public_read)
65
+ it "#copy_to_bucket delegates to S3Object.copy_across_buckets without defaults" do
66
+ acl = :public_read
67
+ AWS::S3::S3Object.should_receive(:copy_across_buckets).with(src_bucket, src_key, dest_bucket, dest_key, acl)
68
+ s3object.copy_to_bucket(s3bucket_dest, dest_key, acl)
69
+ end
83
70
  end
84
71
 
85
- it ".copy_across_buckets when passed a :copy acl_policy puts the copy and copies the acl" do
86
- acl = :copy
87
- src_key = 'src_key'
88
- dest_key = 'dest_key'
89
- src_bucket = 'src_bucket'
90
- dest_bucket = 'dest_bucket'
91
- headers = {}
92
- headers['x-amz-copy-source'] = AWS::S3::S3Object.path!(src_bucket, src_key)
93
- returned_acl = 'returned_acl'
94
- AWS::S3::S3Object.should_receive(:acl).with(src_key, src_bucket).and_return(returned_acl)
95
- AWS::S3::S3Object.should_receive(:acl).with(dest_key, dest_bucket, returned_acl)
96
- AWS::S3::S3Object.should_receive(:put).with(AWS::S3::S3Object.path!(dest_bucket, dest_key), headers)
97
- AWS::S3::S3Object.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, acl)
72
+ describe ".copy_across_buckets" do
73
+ let(:dest_path) { AWS::S3::S3Object.path!(dest_bucket, dest_key) }
74
+ let(:copy_header) { {'x-amz-copy-source' => AWS::S3::S3Object.path!(src_bucket, src_key)} }
75
+
76
+ it "delegates to put with the destination path" do
77
+ AWS::S3::S3Object.should_receive(:put).with(dest_path, anything)
78
+ AWS::S3::S3Object.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key)
79
+ end
80
+
81
+ it "delegates to put with copy source set" do
82
+ AWS::S3::S3Object.should_receive(:put).with(anything, hash_including(copy_header))
83
+ AWS::S3::S3Object.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key)
84
+ end
85
+
86
+ it "delegates to put with the requested canned acl policy" do
87
+ acl = :private
88
+ acl_header = {'x-amz-acl' => acl }
89
+ AWS::S3::S3Object.should_receive(:put).with(anything, hash_including(acl_header))
90
+ AWS::S3::S3Object.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, acl)
91
+ end
92
+
93
+ it "when acl is :copy, copies the existing acl policy" do
94
+ returned_acl = 'returned_acl'
95
+ AWS::S3::S3Object.should_receive(:acl).with(src_key, src_bucket).and_return(returned_acl)
96
+ AWS::S3::S3Object.should_receive(:acl).with(dest_key, dest_bucket, returned_acl)
97
+ AWS::S3::S3Object.stub(:put)
98
+ AWS::S3::S3Object.copy_across_buckets(src_bucket, src_key, dest_bucket, dest_key, :copy)
99
+ end
98
100
  end
99
101
 
100
102
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Les Hill