kt-paperclip 5.4.0 → 7.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  4. data/.github/ISSUE_TEMPLATE/custom.md +10 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.hound.yml +3 -1055
  7. data/.rubocop.yml +1061 -1
  8. data/.travis.yml +23 -4
  9. data/Appraisals +23 -0
  10. data/CONTRIBUTING.md +4 -5
  11. data/Gemfile +10 -7
  12. data/NEWS +52 -0
  13. data/README.md +58 -46
  14. data/Rakefile +29 -21
  15. data/UPGRADING +3 -3
  16. data/features/basic_integration.feature +4 -0
  17. data/features/migration.feature +10 -51
  18. data/features/step_definitions/attachment_steps.rb +23 -13
  19. data/features/step_definitions/html_steps.rb +5 -5
  20. data/features/step_definitions/rails_steps.rb +29 -9
  21. data/features/step_definitions/s3_steps.rb +3 -3
  22. data/features/step_definitions/web_steps.rb +5 -6
  23. data/features/support/env.rb +4 -4
  24. data/features/support/fakeweb.rb +3 -5
  25. data/features/support/file_helpers.rb +2 -2
  26. data/features/support/paths.rb +4 -4
  27. data/features/support/rails.rb +7 -7
  28. data/features/support/selectors.rb +1 -1
  29. data/gemfiles/4.2.gemfile +7 -4
  30. data/gemfiles/5.0.gemfile +7 -4
  31. data/gemfiles/5.1.gemfile +20 -0
  32. data/gemfiles/5.2.gemfile +20 -0
  33. data/gemfiles/6.0.gemfile +20 -0
  34. data/gemfiles/6.1.gemfile +21 -0
  35. data/gemfiles/7.0.gemfile +21 -0
  36. data/lib/generators/paperclip/paperclip_generator.rb +6 -8
  37. data/lib/paperclip/attachment.rb +103 -105
  38. data/lib/paperclip/attachment_registry.rb +2 -2
  39. data/lib/paperclip/content_type_detector.rb +10 -5
  40. data/lib/paperclip/file_command_content_type_detector.rb +1 -3
  41. data/lib/paperclip/filename_cleaner.rb +0 -1
  42. data/lib/paperclip/geometry.rb +18 -19
  43. data/lib/paperclip/geometry_detector_factory.rb +13 -16
  44. data/lib/paperclip/geometry_parser_factory.rb +5 -5
  45. data/lib/paperclip/glue.rb +3 -3
  46. data/lib/paperclip/has_attached_file.rb +5 -4
  47. data/lib/paperclip/helpers.rb +3 -3
  48. data/lib/paperclip/interpolations.rb +42 -38
  49. data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
  50. data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
  51. data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
  52. data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
  53. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
  54. data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
  55. data/lib/paperclip/io_adapters/registry.rb +1 -1
  56. data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
  57. data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
  58. data/lib/paperclip/io_adapters/uri_adapter.rb +21 -9
  59. data/lib/paperclip/logger.rb +1 -1
  60. data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
  61. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
  62. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
  63. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
  64. data/lib/paperclip/matchers.rb +4 -4
  65. data/lib/paperclip/media_type_spoof_detector.rb +13 -13
  66. data/lib/paperclip/missing_attachment_styles.rb +11 -6
  67. data/lib/paperclip/processor.rb +13 -6
  68. data/lib/paperclip/processor_helpers.rb +3 -1
  69. data/lib/paperclip/rails_environment.rb +1 -5
  70. data/lib/paperclip/railtie.rb +5 -5
  71. data/lib/paperclip/schema.rb +16 -12
  72. data/lib/paperclip/storage/filesystem.rb +6 -8
  73. data/lib/paperclip/storage/fog.rb +36 -32
  74. data/lib/paperclip/storage/s3.rb +68 -76
  75. data/lib/paperclip/style.rb +3 -6
  76. data/lib/paperclip/tempfile.rb +4 -5
  77. data/lib/paperclip/tempfile_factory.rb +0 -1
  78. data/lib/paperclip/thumbnail.rb +11 -11
  79. data/lib/paperclip/url_generator.rb +5 -5
  80. data/lib/paperclip/validators/attachment_content_type_validator.rb +11 -4
  81. data/lib/paperclip/validators/attachment_file_name_validator.rb +14 -12
  82. data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
  83. data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
  84. data/lib/paperclip/validators/attachment_size_validator.rb +28 -11
  85. data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
  86. data/lib/paperclip/validators.rb +16 -17
  87. data/lib/paperclip/version.rb +1 -3
  88. data/lib/paperclip.rb +49 -48
  89. data/lib/tasks/paperclip.rake +23 -24
  90. data/paperclip.gemspec +29 -33
  91. data/shoulda_macros/paperclip.rb +16 -16
  92. data/spec/paperclip/attachment_definitions_spec.rb +5 -5
  93. data/spec/paperclip/attachment_processing_spec.rb +22 -23
  94. data/spec/paperclip/attachment_registry_spec.rb +15 -15
  95. data/spec/paperclip/attachment_spec.rb +238 -196
  96. data/spec/paperclip/content_type_detector_spec.rb +18 -12
  97. data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
  98. data/spec/paperclip/filename_cleaner_spec.rb +3 -4
  99. data/spec/paperclip/geometry_detector_spec.rb +7 -8
  100. data/spec/paperclip/geometry_parser_spec.rb +31 -31
  101. data/spec/paperclip/geometry_spec.rb +24 -24
  102. data/spec/paperclip/glue_spec.rb +3 -5
  103. data/spec/paperclip/has_attached_file_spec.rb +46 -126
  104. data/spec/paperclip/integration_spec.rb +111 -77
  105. data/spec/paperclip/interpolations_spec.rb +101 -93
  106. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
  107. data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
  108. data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
  109. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
  110. data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
  111. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +58 -37
  112. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
  113. data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
  114. data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
  115. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
  116. data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
  117. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +90 -31
  118. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
  119. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
  120. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
  121. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
  122. data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
  123. data/spec/paperclip/meta_class_spec.rb +3 -3
  124. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
  125. data/spec/paperclip/paperclip_spec.rb +15 -11
  126. data/spec/paperclip/plural_cache_spec.rb +8 -8
  127. data/spec/paperclip/processor_helpers_spec.rb +35 -35
  128. data/spec/paperclip/processor_spec.rb +8 -8
  129. data/spec/paperclip/rails_environment_spec.rb +7 -10
  130. data/spec/paperclip/rake_spec.rb +39 -39
  131. data/spec/paperclip/schema_spec.rb +57 -53
  132. data/spec/paperclip/storage/filesystem_spec.rb +29 -6
  133. data/spec/paperclip/storage/fog_spec.rb +122 -82
  134. data/spec/paperclip/storage/s3_live_spec.rb +22 -22
  135. data/spec/paperclip/storage/s3_spec.rb +649 -583
  136. data/spec/paperclip/style_spec.rb +67 -71
  137. data/spec/paperclip/tempfile_factory_spec.rb +5 -5
  138. data/spec/paperclip/thumbnail_spec.rb +68 -67
  139. data/spec/paperclip/url_generator_spec.rb +18 -19
  140. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +115 -27
  141. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +105 -16
  142. data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
  143. data/spec/paperclip/validators/attachment_size_validator_spec.rb +111 -21
  144. data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
  145. data/spec/paperclip/validators_spec.rb +61 -46
  146. data/spec/spec_helper.rb +21 -23
  147. data/spec/support/assertions.rb +8 -6
  148. data/spec/support/fake_model.rb +1 -2
  149. data/spec/support/fake_rails.rb +1 -1
  150. data/spec/support/fixtures/aws_s3.yml +13 -0
  151. data/spec/support/fixtures/sample.xlsm +0 -0
  152. data/spec/support/matchers/exist.rb +1 -1
  153. data/spec/support/matchers/have_column.rb +1 -1
  154. data/spec/support/mock_url_generator_builder.rb +2 -3
  155. data/spec/support/model_reconstruction.rb +16 -12
  156. data/spec/support/reporting.rb +1 -1
  157. data/spec/support/test_data.rb +2 -2
  158. metadata +58 -106
  159. data/spec/support/conditional_filter_helper.rb +0 -5
@@ -1,5 +1,5 @@
1
- require 'spec_helper'
2
- require 'aws-sdk'
1
+ require "spec_helper"
2
+ require "aws-sdk-s3"
3
3
 
4
4
  describe Paperclip::Storage::S3 do
5
5
  before do
@@ -7,39 +7,39 @@ describe Paperclip::Storage::S3 do
7
7
  end
8
8
 
9
9
  def aws2_add_region
10
- { s3_region: 'us-east-1' }
10
+ { s3_region: "us-east-1" }
11
11
  end
12
12
 
13
13
  context "Parsing S3 credentials" do
14
14
  before do
15
- @proxy_settings = {host: "127.0.0.1", port: 8888, user: "foo", password: "bar"}
16
- rebuild_model (aws2_add_region).merge storage: :s3,
17
- bucket: "testing",
18
- http_proxy: @proxy_settings,
19
- s3_credentials: {not: :important}
15
+ @proxy_settings = { host: "127.0.0.1", port: 8888, user: "foo", password: "bar" }
16
+ rebuild_model aws2_add_region.merge storage: :s3,
17
+ bucket: "testing",
18
+ http_proxy: @proxy_settings,
19
+ s3_credentials: { not: :important }
20
20
  @dummy = Dummy.new
21
21
  @avatar = @dummy.avatar
22
22
  end
23
23
 
24
24
  it "gets the correct credentials when RAILS_ENV is production" do
25
25
  rails_env("production") do
26
- assert_equal({key: "12345"},
27
- @avatar.parse_credentials('production' => {key: '12345'},
28
- development: {key: "54321"}))
26
+ assert_equal({ key: "12345" },
27
+ @avatar.parse_credentials("production" => { key: "12345" },
28
+ development: { key: "54321" }))
29
29
  end
30
30
  end
31
31
 
32
32
  it "gets the correct credentials when RAILS_ENV is development" do
33
33
  rails_env("development") do
34
- assert_equal({key: "54321"},
35
- @avatar.parse_credentials('production' => {key: '12345'},
36
- development: {key: "54321"}))
34
+ assert_equal({ key: "54321" },
35
+ @avatar.parse_credentials("production" => { key: "12345" },
36
+ development: { key: "54321" }))
37
37
  end
38
38
  end
39
39
 
40
40
  it "returns the argument if the key does not exist" do
41
41
  rails_env("not really an env") do
42
- assert_equal({test: "12345"}, @avatar.parse_credentials(test: "12345"))
42
+ assert_equal({ test: "12345" }, @avatar.parse_credentials(test: "12345"))
43
43
  end
44
44
  end
45
45
 
@@ -52,65 +52,57 @@ describe Paperclip::Storage::S3 do
52
52
  assert_equal(@proxy_settings[:password], @avatar.http_proxy_password)
53
53
  end
54
54
  end
55
-
56
55
  end
57
56
 
58
57
  context ":bucket option via :s3_credentials" do
59
-
60
58
  before do
61
- rebuild_model (aws2_add_region).merge storage: :s3,
62
- s3_credentials: {bucket: 'testing'}
59
+ rebuild_model aws2_add_region.merge storage: :s3,
60
+ s3_credentials: { bucket: "testing" }
63
61
  @dummy = Dummy.new
64
62
  end
65
63
 
66
64
  it "populates #bucket_name" do
67
- assert_equal @dummy.avatar.bucket_name, 'testing'
65
+ assert_equal @dummy.avatar.bucket_name, "testing"
68
66
  end
69
-
70
67
  end
71
68
 
72
69
  context ":bucket option" do
73
-
74
70
  before do
75
- rebuild_model (aws2_add_region).merge storage: :s3,
76
- bucket: "testing", s3_credentials: {}
71
+ rebuild_model aws2_add_region.merge storage: :s3,
72
+ bucket: "testing", s3_credentials: {}
77
73
  @dummy = Dummy.new
78
74
  end
79
75
 
80
76
  it "populates #bucket_name" do
81
- assert_equal @dummy.avatar.bucket_name, 'testing'
77
+ assert_equal @dummy.avatar.bucket_name, "testing"
82
78
  end
83
-
84
79
  end
85
80
 
86
81
  context "missing :bucket option" do
87
-
88
82
  before do
89
- rebuild_model (aws2_add_region).merge storage: :s3,
90
- http_proxy: @proxy_settings,
91
- s3_credentials: {not: :important}
83
+ rebuild_model aws2_add_region.merge storage: :s3,
84
+ http_proxy: @proxy_settings,
85
+ s3_credentials: { not: :important }
92
86
 
93
87
  @dummy = Dummy.new
94
88
  @dummy.avatar = stringy_file
95
-
96
89
  end
97
90
 
98
91
  it "raises an argument error" do
99
92
  expect { @dummy.save }.to raise_error(ArgumentError, /missing required :bucket option/)
100
93
  end
101
-
102
94
  end
103
95
 
104
96
  context "" do
105
97
  before do
106
- rebuild_model (aws2_add_region).merge storage: :s3,
107
- s3_credentials: {},
108
- bucket: "bucket",
109
- path: ":attachment/:basename:dotextension",
110
- url: ":s3_path_url"
98
+ rebuild_model aws2_add_region.merge storage: :s3,
99
+ s3_credentials: {},
100
+ bucket: "bucket",
101
+ path: ":attachment/:basename:dotextension",
102
+ url: ":s3_path_url"
111
103
  @dummy = Dummy.new
112
104
  @dummy.avatar = stringy_file
113
- @dummy.stubs(:new_record?).returns(false)
105
+ allow(@dummy).to receive(:new_record?).and_return(false)
114
106
  end
115
107
 
116
108
  it "returns a url based on an S3 path" do
@@ -130,8 +122,8 @@ describe Paperclip::Storage::S3 do
130
122
  ["http", :http, ""].each do |protocol|
131
123
  context "as #{protocol.inspect}" do
132
124
  before do
133
- rebuild_model (aws2_add_region).merge storage: :s3,
134
- s3_protocol: protocol
125
+ rebuild_model aws2_add_region.merge storage: :s3,
126
+ s3_protocol: protocol
135
127
  @dummy = Dummy.new
136
128
  end
137
129
 
@@ -144,14 +136,14 @@ describe Paperclip::Storage::S3 do
144
136
 
145
137
  context "s3_protocol: 'https'" do
146
138
  before do
147
- rebuild_model (aws2_add_region).merge storage: :s3,
148
- s3_credentials: {},
149
- s3_protocol: 'https',
150
- bucket: "bucket",
151
- path: ":attachment/:basename:dotextension"
139
+ rebuild_model aws2_add_region.merge storage: :s3,
140
+ s3_credentials: {},
141
+ s3_protocol: "https",
142
+ bucket: "bucket",
143
+ path: ":attachment/:basename:dotextension"
152
144
  @dummy = Dummy.new
153
145
  @dummy.avatar = stringy_file
154
- @dummy.stubs(:new_record?).returns(false)
146
+ allow(@dummy).to receive(:new_record?).and_return(false)
155
147
  end
156
148
 
157
149
  it "returns a url based on an S3 path" do
@@ -161,14 +153,14 @@ describe Paperclip::Storage::S3 do
161
153
 
162
154
  context "s3_protocol: ''" do
163
155
  before do
164
- rebuild_model (aws2_add_region).merge storage: :s3,
165
- s3_credentials: {},
166
- s3_protocol: '',
167
- bucket: "bucket",
168
- path: ":attachment/:basename:dotextension"
156
+ rebuild_model aws2_add_region.merge storage: :s3,
157
+ s3_credentials: {},
158
+ s3_protocol: "",
159
+ bucket: "bucket",
160
+ path: ":attachment/:basename:dotextension"
169
161
  @dummy = Dummy.new
170
162
  @dummy.avatar = stringy_file
171
- @dummy.stubs(:new_record?).returns(false)
163
+ allow(@dummy).to receive(:new_record?).and_return(false)
172
164
  end
173
165
 
174
166
  it "returns a protocol-relative URL" do
@@ -178,14 +170,14 @@ describe Paperclip::Storage::S3 do
178
170
 
179
171
  context "s3_protocol: :https" do
180
172
  before do
181
- rebuild_model (aws2_add_region).merge storage: :s3,
182
- s3_credentials: {},
183
- s3_protocol: :https,
184
- bucket: "bucket",
185
- path: ":attachment/:basename:dotextension"
173
+ rebuild_model aws2_add_region.merge storage: :s3,
174
+ s3_credentials: {},
175
+ s3_protocol: :https,
176
+ bucket: "bucket",
177
+ path: ":attachment/:basename:dotextension"
186
178
  @dummy = Dummy.new
187
179
  @dummy.avatar = stringy_file
188
- @dummy.stubs(:new_record?).returns(false)
180
+ allow(@dummy).to receive(:new_record?).and_return(false)
189
181
  end
190
182
 
191
183
  it "returns a url based on an S3 path" do
@@ -195,14 +187,14 @@ describe Paperclip::Storage::S3 do
195
187
 
196
188
  context "s3_protocol: ''" do
197
189
  before do
198
- rebuild_model (aws2_add_region).merge storage: :s3,
199
- s3_credentials: {},
200
- s3_protocol: '',
201
- bucket: "bucket",
202
- path: ":attachment/:basename:dotextension"
190
+ rebuild_model aws2_add_region.merge storage: :s3,
191
+ s3_credentials: {},
192
+ s3_protocol: "",
193
+ bucket: "bucket",
194
+ path: ":attachment/:basename:dotextension"
203
195
  @dummy = Dummy.new
204
196
  @dummy.avatar = stringy_file
205
- @dummy.stubs(:new_record?).returns(false)
197
+ allow(@dummy).to receive(:new_record?).and_return(false)
206
198
  end
207
199
 
208
200
  it "returns a url based on an S3 path" do
@@ -212,20 +204,20 @@ describe Paperclip::Storage::S3 do
212
204
 
213
205
  context "An attachment that uses S3 for storage and has the style in the path" do
214
206
  before do
215
- rebuild_model (aws2_add_region).merge storage: :s3,
216
- bucket: "testing",
217
- path: ":attachment/:style/:basename:dotextension",
218
- styles: {
219
- thumb: "80x80>"
220
- },
221
- s3_credentials: {
222
- 'access_key_id' => "12345",
223
- 'secret_access_key' => "54321"
224
- }
207
+ rebuild_model aws2_add_region.merge storage: :s3,
208
+ bucket: "testing",
209
+ path: ":attachment/:style/:basename:dotextension",
210
+ styles: {
211
+ thumb: "80x80>"
212
+ },
213
+ s3_credentials: {
214
+ "access_key_id" => "12345",
215
+ "secret_access_key" => "54321"
216
+ }
225
217
 
226
- @dummy = Dummy.new
227
- @dummy.avatar = stringy_file
228
- @avatar = @dummy.avatar
218
+ @dummy = Dummy.new
219
+ @dummy.avatar = stringy_file
220
+ @avatar = @dummy.avatar
229
221
  end
230
222
 
231
223
  it "uses an S3 object based on the correct path for the default style" do
@@ -237,18 +229,18 @@ describe Paperclip::Storage::S3 do
237
229
  end
238
230
  end
239
231
 
240
- # if using aws-sdk-v2, the s3_host_name will be defined by the s3_region
232
+ # the s3_host_name will be defined by the s3_region
241
233
  context "s3_host_name" do
242
234
  before do
243
235
  rebuild_model storage: :s3,
244
- s3_credentials: {},
245
- bucket: "bucket",
246
- path: ":attachment/:basename:dotextension",
247
- s3_host_name: "s3-ap-northeast-1.amazonaws.com",
248
- s3_region: "ap-northeast-1"
236
+ s3_credentials: {},
237
+ bucket: "bucket",
238
+ path: ":attachment/:basename:dotextension",
239
+ s3_host_name: "s3-ap-northeast-1.amazonaws.com",
240
+ s3_region: "ap-northeast-1"
249
241
  @dummy = Dummy.new
250
242
  @dummy.avatar = stringy_file
251
- @dummy.stubs(:new_record?).returns(false)
243
+ allow(@dummy).to receive(:new_record?).and_return(false)
252
244
  end
253
245
 
254
246
  it "returns a url based on an :s3_host_name path" do
@@ -257,23 +249,23 @@ describe Paperclip::Storage::S3 do
257
249
 
258
250
  it "uses the S3 bucket with the correct host name" do
259
251
  assert_equal "s3.ap-northeast-1.amazonaws.com",
260
- @dummy.avatar.s3_bucket.client.config.endpoint.host
252
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
261
253
  end
262
254
  end
263
255
 
264
256
  context "dynamic s3_host_name" do
265
257
  before do
266
- rebuild_model (aws2_add_region).merge storage: :s3,
267
- s3_credentials: {},
268
- bucket: "bucket",
269
- path: ":attachment/:basename:dotextension",
270
- s3_host_name: lambda {|a| a.instance.value }
258
+ rebuild_model aws2_add_region.merge storage: :s3,
259
+ s3_credentials: {},
260
+ bucket: "bucket",
261
+ path: ":attachment/:basename:dotextension",
262
+ s3_host_name: lambda { |a| a.instance.value }
271
263
  @dummy = Dummy.new
272
264
  class << @dummy
273
265
  attr_accessor :value
274
266
  end
275
267
  @dummy.avatar = stringy_file
276
- @dummy.stubs(:new_record?).returns(false)
268
+ allow(@dummy).to receive(:new_record?).and_return(false)
277
269
  end
278
270
 
279
271
  it "uses s3_host_name as a proc if available" do
@@ -282,7 +274,7 @@ describe Paperclip::Storage::S3 do
282
274
  end
283
275
  end
284
276
 
285
- context "use_accelerate_endpoint", if: aws_accelerate_available? do
277
+ context "use_accelerate_endpoint" do
286
278
  context "defaults to false" do
287
279
  before do
288
280
  rebuild_model(
@@ -291,16 +283,16 @@ describe Paperclip::Storage::S3 do
291
283
  bucket: "bucket",
292
284
  path: ":attachment/:basename:dotextension",
293
285
  s3_host_name: "s3-ap-northeast-1.amazonaws.com",
294
- s3_region: "ap-northeast-1",
286
+ s3_region: "ap-northeast-1"
295
287
  )
296
288
  @dummy = Dummy.new
297
289
  @dummy.avatar = stringy_file
298
- @dummy.stubs(:new_record?).returns(false)
290
+ allow(@dummy).to receive(:new_record?).and_return(false)
299
291
  end
300
292
 
301
293
  it "returns a url based on an :s3_host_name path" do
302
294
  assert_match %r{^//s3-ap-northeast-1.amazonaws.com/bucket/avatars/data[^\.]},
303
- @dummy.avatar.url
295
+ @dummy.avatar.url
304
296
  end
305
297
 
306
298
  it "uses the S3 client with the use_accelerate_endpoint config is false" do
@@ -308,7 +300,7 @@ describe Paperclip::Storage::S3 do
308
300
  end
309
301
  end
310
302
 
311
- context "set to true", if: aws_accelerate_available? do
303
+ context "set to true" do
312
304
  before do
313
305
  rebuild_model(
314
306
  storage: :s3,
@@ -317,16 +309,16 @@ describe Paperclip::Storage::S3 do
317
309
  path: ":attachment/:basename:dotextension",
318
310
  s3_host_name: "s3-accelerate.amazonaws.com",
319
311
  s3_region: "ap-northeast-1",
320
- use_accelerate_endpoint: true,
312
+ use_accelerate_endpoint: true
321
313
  )
322
314
  @dummy = Dummy.new
323
315
  @dummy.avatar = stringy_file
324
- @dummy.stubs(:new_record?).returns(false)
316
+ allow(@dummy).to receive(:new_record?).and_return(false)
325
317
  end
326
318
 
327
319
  it "returns a url based on an :s3_host_name path" do
328
320
  assert_match %r{^//s3-accelerate.amazonaws.com/bucket/avatars/data[^\.]},
329
- @dummy.avatar.url
321
+ @dummy.avatar.url
330
322
  end
331
323
 
332
324
  it "uses the S3 client with the use_accelerate_endpoint config is true" do
@@ -337,27 +329,27 @@ describe Paperclip::Storage::S3 do
337
329
 
338
330
  context "An attachment that uses S3 for storage and has styles that return different file types" do
339
331
  before do
340
- rebuild_model (aws2_add_region).merge storage: :s3,
341
- styles: { large: ['500x500#', :jpg] },
342
- bucket: "bucket",
343
- path: ":attachment/:basename:dotextension",
344
- s3_credentials: {
345
- 'access_key_id' => "12345",
346
- 'secret_access_key' => "54321"
347
- }
348
-
349
- File.open(fixture_file('5k.png'), 'rb') do |file|
350
- @dummy = Dummy.new
351
- @dummy.avatar = file
352
- @dummy.stubs(:new_record?).returns(false)
353
- end
332
+ rebuild_model aws2_add_region.merge storage: :s3,
333
+ styles: { large: ["500x500#", :jpg] },
334
+ bucket: "bucket",
335
+ path: ":attachment/:basename:dotextension",
336
+ s3_credentials: {
337
+ "access_key_id" => "12345",
338
+ "secret_access_key" => "54321"
339
+ }
340
+
341
+ File.open(fixture_file("5k.png"), "rb") do |file|
342
+ @dummy = Dummy.new
343
+ @dummy.avatar = file
344
+ allow(@dummy).to receive(:new_record?).and_return(false)
345
+ end
354
346
  end
355
347
 
356
348
  it "returns a url containing the correct original file mime type" do
357
349
  assert_match /.+\/5k.png/, @dummy.avatar.url
358
350
  end
359
351
 
360
- it 'uses the correct key for the original file mime type' do
352
+ it "uses the correct key for the original file mime type" do
361
353
  assert_match /.+\/5k.png/, @dummy.avatar.s3_object.key
362
354
  end
363
355
 
@@ -372,42 +364,44 @@ describe Paperclip::Storage::S3 do
372
364
 
373
365
  context "An attachment that uses S3 for storage and has a proc for styles" do
374
366
  before do
375
- rebuild_model (aws2_add_region).merge storage: :s3,
376
- styles: lambda { |attachment| attachment.instance.counter
377
- {thumbnail: { geometry: "50x50#",
378
- s3_headers: {'Cache-Control' => 'max-age=31557600'}} }},
379
- bucket: "bucket",
380
- path: ":attachment/:style/:basename:dotextension",
381
- s3_credentials: {
382
- 'access_key_id' => "12345",
383
- 'secret_access_key' => "54321"
384
- }
367
+ rebuild_model aws2_add_region.merge storage: :s3,
368
+ styles: lambda { |attachment|
369
+ attachment.instance.counter
370
+ { thumbnail: { geometry: "50x50#",
371
+ s3_headers: { "Cache-Control" => "max-age=31557600" } } }
372
+ },
373
+ bucket: "bucket",
374
+ path: ":attachment/:style/:basename:dotextension",
375
+ s3_credentials: {
376
+ "access_key_id" => "12345",
377
+ "secret_access_key" => "54321"
378
+ }
385
379
 
386
- @file = File.new(fixture_file('5k.png'), 'rb')
380
+ @file = File.new(fixture_file("5k.png"), "rb")
387
381
 
388
- Dummy.class_eval do
389
- def counter
390
- @counter ||= 0
391
- @counter += 1
392
- @counter
393
- end
382
+ Dummy.class_eval do
383
+ def counter
384
+ @counter ||= 0
385
+ @counter += 1
386
+ @counter
394
387
  end
388
+ end
395
389
 
396
- @dummy = Dummy.new
397
- @dummy.avatar = @file
390
+ @dummy = Dummy.new
391
+ @dummy.avatar = @file
398
392
 
399
- object = stub
400
- @dummy.avatar.stubs(:s3_object).with(:original).returns(object)
401
- @dummy.avatar.stubs(:s3_object).with(:thumbnail).returns(object)
402
-
403
- object.expects(:upload_file)
404
- .with(anything, content_type: 'image/png',
405
- acl: :"public-read")
406
- object.expects(:upload_file)
407
- .with(anything, content_type: 'image/png',
408
- acl: :"public-read",
409
- cache_control: 'max-age=31557600')
410
- @dummy.save
393
+ object = double
394
+ allow(@dummy.avatar).to receive(:s3_object).with(:original).and_return(object)
395
+ allow(@dummy.avatar).to receive(:s3_object).with(:thumbnail).and_return(object)
396
+
397
+ expect(object).to receive(:upload_file).
398
+ with(anything, content_type: "image/png",
399
+ acl: :"public-read")
400
+ expect(object).to receive(:upload_file).
401
+ with(anything, content_type: "image/png",
402
+ acl: :"public-read",
403
+ cache_control: "max-age=31557600")
404
+ @dummy.save
411
405
  end
412
406
 
413
407
  after { @file.close }
@@ -420,13 +414,14 @@ describe Paperclip::Storage::S3 do
420
414
  context "An attachment that uses S3 for storage and has styles" do
421
415
  before do
422
416
  rebuild_model(
423
- (aws2_add_region).merge(
417
+ aws2_add_region.merge(
424
418
  storage: :s3,
425
419
  styles: { thumb: ["90x90#", :jpg] },
426
420
  bucket: "bucket",
427
421
  s3_credentials: {
428
422
  "access_key_id" => "12345",
429
- "secret_access_key" => "54321" }
423
+ "secret_access_key" => "54321"
424
+ }
430
425
  )
431
426
  )
432
427
 
@@ -438,31 +433,36 @@ describe Paperclip::Storage::S3 do
438
433
 
439
434
  context "reprocess" do
440
435
  before do
441
- @object = stub
442
- @dummy.avatar.stubs(:s3_object).with(:original).returns(@object)
443
- @dummy.avatar.stubs(:s3_object).with(:thumb).returns(@object)
444
- @object.stubs(:get).yields(@file.read)
445
- @object.stubs(:exists?).returns(true)
436
+ @object = double
437
+ allow(@dummy.avatar).to receive(:s3_object).with(:original).and_return(@object)
438
+ allow(@dummy.avatar).to receive(:s3_object).with(:thumb).and_return(@object)
439
+ allow(@object).to receive(:get).and_yield(@file.read)
440
+ allow(@object).to receive(:exists?).and_return(true)
441
+ allow(@object).to receive(:download_file).with(anything)
446
442
  end
447
443
 
448
444
  it "uploads original" do
449
- @object.expects(:upload_file).with(
445
+ expect(@object).to receive(:upload_file).with(
450
446
  anything,
451
447
  content_type: "image/png",
452
- acl: :"public-read").returns(true)
453
- @object.expects(:upload_file).with(
448
+ acl: :"public-read"
449
+ ).and_return(true)
450
+ @dummy.avatar.reprocess!
451
+ expect(@object).to receive(:upload_file).with(
454
452
  anything,
455
- content_type: "image/jpeg",
456
- acl: :"public-read").returns(true)
453
+ content_type: "image/png",
454
+ acl: :"public-read"
455
+ ).and_return(true)
457
456
  @dummy.avatar.reprocess!
458
457
  end
459
458
 
460
459
  it "doesn't upload original" do
461
- @object.expects(:upload_file).with(
460
+ expect(@object).to receive(:upload_file).with(
462
461
  anything,
463
- content_type: "image/jpeg",
464
- acl: :"public-read").returns(true)
465
- @dummy.avatar.reprocess!(:thumb)
462
+ content_type: "image/png",
463
+ acl: :"public-read"
464
+ ).and_return(true)
465
+ @dummy.avatar.reprocess!
466
466
  end
467
467
  end
468
468
 
@@ -472,17 +472,17 @@ describe Paperclip::Storage::S3 do
472
472
  context "An attachment that uses S3 for storage and has spaces in file name" do
473
473
  before do
474
474
  rebuild_model(
475
- (aws2_add_region).merge storage: :s3,
476
- styles: { large: ["500x500#", :jpg] },
477
- bucket: "bucket",
478
- s3_credentials: { "access_key_id" => "12345",
479
- "secret_access_key" => "54321" }
480
- )
475
+ aws2_add_region.merge(storage: :s3,
476
+ styles: { large: ["500x500#", :jpg] },
477
+ bucket: "bucket",
478
+ s3_credentials: { "access_key_id" => "12345",
479
+ "secret_access_key" => "54321" })
480
+ )
481
481
 
482
482
  File.open(fixture_file("spaced file.png"), "rb") do |file|
483
483
  @dummy = Dummy.new
484
484
  @dummy.avatar = file
485
- @dummy.stubs(:new_record?).returns(false)
485
+ allow(@dummy).to receive(:new_record?).and_return(false)
486
486
  end
487
487
  end
488
488
 
@@ -497,13 +497,13 @@ describe Paperclip::Storage::S3 do
497
497
 
498
498
  context "An attachment that uses S3 for storage and has a question mark in file name" do
499
499
  before do
500
- rebuild_model (aws2_add_region).merge storage: :s3,
501
- styles: { large: ['500x500#', :jpg] },
502
- bucket: "bucket",
503
- s3_credentials: {
504
- 'access_key_id' => "12345",
505
- 'secret_access_key' => "54321"
506
- }
500
+ rebuild_model aws2_add_region.merge storage: :s3,
501
+ styles: { large: ["500x500#", :jpg] },
502
+ bucket: "bucket",
503
+ s3_credentials: {
504
+ "access_key_id" => "12345",
505
+ "secret_access_key" => "54321"
506
+ }
507
507
 
508
508
  stringio = stringy_file
509
509
  class << stringio
@@ -515,7 +515,7 @@ describe Paperclip::Storage::S3 do
515
515
  @dummy = Dummy.new
516
516
  @dummy.avatar = file
517
517
  @dummy.save
518
- @dummy.stubs(:new_record?).returns(false)
518
+ allow(@dummy).to receive(:new_record?).and_return(false)
519
519
  end
520
520
 
521
521
  it "returns a replaced version for path" do
@@ -529,14 +529,14 @@ describe Paperclip::Storage::S3 do
529
529
 
530
530
  context "" do
531
531
  before do
532
- rebuild_model (aws2_add_region).merge storage: :s3,
533
- s3_credentials: {},
534
- bucket: "bucket",
535
- path: ":attachment/:basename:dotextension",
536
- url: ":s3_domain_url"
532
+ rebuild_model aws2_add_region.merge storage: :s3,
533
+ s3_credentials: {},
534
+ bucket: "bucket",
535
+ path: ":attachment/:basename:dotextension",
536
+ url: ":s3_domain_url"
537
537
  @dummy = Dummy.new
538
538
  @dummy.avatar = stringy_file
539
- @dummy.stubs(:new_record?).returns(false)
539
+ allow(@dummy).to receive(:new_record?).and_return(false)
540
540
  end
541
541
 
542
542
  it "returns a url based on an S3 subdomain" do
@@ -547,19 +547,19 @@ describe Paperclip::Storage::S3 do
547
547
  context "" do
548
548
  before do
549
549
  rebuild_model(
550
- (aws2_add_region).merge storage: :s3,
551
- s3_credentials: {
552
- production: { bucket: "prod_bucket" },
553
- development: { bucket: "dev_bucket" }
554
- },
555
- bucket: "bucket",
556
- s3_host_alias: "something.something.com",
557
- path: ":attachment/:basename:dotextension",
558
- url: ":s3_alias_url"
559
- )
550
+ aws2_add_region.merge(storage: :s3,
551
+ s3_credentials: {
552
+ production: { bucket: "prod_bucket" },
553
+ development: { bucket: "dev_bucket" }
554
+ },
555
+ bucket: "bucket",
556
+ s3_host_alias: "something.something.com",
557
+ path: ":attachment/:basename:dotextension",
558
+ url: ":s3_alias_url")
559
+ )
560
560
  @dummy = Dummy.new
561
561
  @dummy.avatar = stringy_file
562
- @dummy.stubs(:new_record?).returns(false)
562
+ allow(@dummy).to receive(:new_record?).and_return(false)
563
563
  end
564
564
 
565
565
  it "returns a url based on the host_alias" do
@@ -580,12 +580,12 @@ describe Paperclip::Storage::S3 do
580
580
  s3_host_alias: "something.something.com",
581
581
  s3_prefixes_in_alias: 2,
582
582
  path: "prefix1/prefix2/:attachment/:basename:dotextension",
583
- url: ":s3_alias_url",
583
+ url: ":s3_alias_url"
584
584
  )
585
585
  )
586
586
  @dummy = Dummy.new
587
587
  @dummy.avatar = stringy_file
588
- @dummy.stubs(:new_record?).returns(false)
588
+ allow(@dummy).to receive(:new_record?).and_return(false)
589
589
  end
590
590
 
591
591
  it "returns a url with the prefixes removed" do
@@ -596,11 +596,11 @@ describe Paperclip::Storage::S3 do
596
596
 
597
597
  context "generating a url with a proc as the host alias" do
598
598
  before do
599
- rebuild_model (aws2_add_region).merge storage: :s3,
600
- s3_credentials: { bucket: "prod_bucket" },
601
- s3_host_alias: Proc.new{|atch| "cdn#{atch.instance.counter % 4}.example.com"},
602
- path: ":attachment/:basename:dotextension",
603
- url: ":s3_alias_url"
599
+ rebuild_model aws2_add_region.merge storage: :s3,
600
+ s3_credentials: { bucket: "prod_bucket" },
601
+ s3_host_alias: Proc.new { |atch| "cdn#{atch.instance.counter % 4}.example.com" },
602
+ path: ":attachment/:basename:dotextension",
603
+ url: ":s3_alias_url"
604
604
  Dummy.class_eval do
605
605
  def counter
606
606
  @counter ||= 0
@@ -610,7 +610,7 @@ describe Paperclip::Storage::S3 do
610
610
  end
611
611
  @dummy = Dummy.new
612
612
  @dummy.avatar = stringy_file
613
- @dummy.stubs(:new_record?).returns(false)
613
+ allow(@dummy).to receive(:new_record?).and_return(false)
614
614
  end
615
615
 
616
616
  it "returns a url based on the host_alias" do
@@ -621,30 +621,28 @@ describe Paperclip::Storage::S3 do
621
621
  it "still returns the bucket name" do
622
622
  assert_equal "prod_bucket", @dummy.avatar.bucket_name
623
623
  end
624
-
625
624
  end
626
625
 
627
626
  context "" do
628
627
  before do
629
- rebuild_model (aws2_add_region).merge storage: :s3,
630
- s3_credentials: {},
631
- bucket: "bucket",
632
- path: ":attachment/:basename:dotextension",
633
- url: ":asset_host"
628
+ rebuild_model aws2_add_region.merge storage: :s3,
629
+ s3_credentials: {},
630
+ bucket: "bucket",
631
+ path: ":attachment/:basename:dotextension",
632
+ url: ":asset_host"
634
633
  @dummy = Dummy.new
635
634
  @dummy.avatar = stringy_file
636
- @dummy.stubs(:new_record?).returns(false)
635
+ allow(@dummy).to receive(:new_record?).and_return(false)
637
636
  end
638
637
 
639
638
  it "returns a relative URL for Rails to calculate assets host" do
640
639
  assert_match %r{^avatars/data[^\.]}, @dummy.avatar.url
641
640
  end
642
-
643
641
  end
644
642
 
645
643
  context "Generating a secure url with an expiration" do
646
644
  before do
647
- @build_model_with_options = lambda {|options|
645
+ @build_model_with_options = lambda { |options|
648
646
  base_options = {
649
647
  storage: :s3,
650
648
  s3_credentials: {
@@ -657,7 +655,7 @@ describe Paperclip::Storage::S3 do
657
655
  url: ":s3_alias_url"
658
656
  }
659
657
 
660
- rebuild_model (aws2_add_region).merge base_options.merge(options)
658
+ rebuild_model aws2_add_region.merge base_options.merge(options)
661
659
  }
662
660
  end
663
661
 
@@ -668,10 +666,10 @@ describe Paperclip::Storage::S3 do
668
666
  @dummy = Dummy.new
669
667
  @dummy.avatar = stringy_file
670
668
 
671
- object = stub
672
- @dummy.avatar.stubs(:s3_object).returns(object)
669
+ object = double
670
+ allow(@dummy.avatar).to receive(:s3_object).and_return(object)
673
671
 
674
- object.expects(:presigned_url).with(:get, expires_in: 3600)
672
+ expect(object).to receive(:presigned_url).with(:get, expires_in: 3600)
675
673
  @dummy.avatar.expiring_url
676
674
  end
677
675
  end
@@ -683,33 +681,33 @@ describe Paperclip::Storage::S3 do
683
681
  @dummy = Dummy.new
684
682
  @dummy.avatar = stringy_file
685
683
 
686
- object = stub
687
- @dummy.avatar.stubs(:s3_object).returns(object)
688
- object.expects(:presigned_url)
689
- .with(:get, expires_in: 3600,
690
- response_content_disposition: "inline")
684
+ object = double
685
+ allow(@dummy.avatar).to receive(:s3_object).and_return(object)
686
+ expect(object).to receive(:presigned_url).
687
+ with(:get, expires_in: 3600,
688
+ response_content_disposition: "inline")
691
689
  @dummy.avatar.expiring_url
692
690
  end
693
691
  end
694
692
 
695
693
  it "allows overriding s3_object options with a proc" do
696
- @build_model_with_options[s3_url_options: lambda {|attachment| { response_content_type: attachment.avatar_content_type } }]
694
+ @build_model_with_options[s3_url_options: lambda { |attachment| { response_content_type: attachment.avatar_content_type } }]
697
695
 
698
696
  rails_env("production") do
699
697
  @dummy = Dummy.new
700
698
 
701
699
  @file = stringy_file
702
- @file.stubs(:original_filename).returns("5k.png\n\n")
703
- Paperclip.stubs(:run).returns('image/png')
704
- @file.stubs(:content_type).returns("image/png\n\n")
705
- @file.stubs(:to_tempfile).returns(@file)
700
+ allow(@file).to receive(:original_filename).and_return("5k.png\n\n")
701
+ allow(Paperclip).to receive(:run).and_return("image/png")
702
+ allow(@file).to receive(:content_type).and_return("image/png\n\n")
703
+ allow(@file).to receive(:to_tempfile).and_return(@file)
706
704
 
707
705
  @dummy.avatar = @file
708
706
 
709
- object = stub
710
- @dummy.avatar.stubs(:s3_object).returns(object)
711
- object.expects(:presigned_url)
712
- .with(:get, expires_in: 3600, response_content_type: "image/png")
707
+ object = double
708
+ allow(@dummy.avatar).to receive(:s3_object).and_return(object)
709
+ expect(object).to receive(:presigned_url).
710
+ with(:get, expires_in: 3600, response_content_type: "image/png")
713
711
  @dummy.avatar.expiring_url
714
712
  end
715
713
  end
@@ -725,7 +723,7 @@ describe Paperclip::Storage::S3 do
725
723
  assert_equal(@dummy.avatar.url, @dummy.avatar.expiring_url)
726
724
  end
727
725
 
728
- it 'generates a url for a style when a file does not exist' do
726
+ it "generates a url for a style when a file does not exist" do
729
727
  assert_equal(@dummy.avatar.url(:thumb), @dummy.avatar.expiring_url(3600, :thumb))
730
728
  end
731
729
  end
@@ -737,15 +735,15 @@ describe Paperclip::Storage::S3 do
737
735
 
738
736
  context "Generating a url with an expiration for each style" do
739
737
  before do
740
- rebuild_model (aws2_add_region).merge storage: :s3,
741
- s3_credentials: {
742
- production: { bucket: "prod_bucket" },
743
- development: { bucket: "dev_bucket" }
744
- },
745
- s3_permissions: :private,
746
- s3_host_alias: "something.something.com",
747
- path: ":attachment/:style/:basename:dotextension",
748
- url: ":s3_alias_url"
738
+ rebuild_model aws2_add_region.merge storage: :s3,
739
+ s3_credentials: {
740
+ production: { bucket: "prod_bucket" },
741
+ development: { bucket: "dev_bucket" }
742
+ },
743
+ s3_permissions: :private,
744
+ s3_host_alias: "something.something.com",
745
+ path: ":attachment/:style/:basename:dotextension",
746
+ url: ":s3_alias_url"
749
747
 
750
748
  rails_env("production") do
751
749
  @dummy = Dummy.new
@@ -754,27 +752,27 @@ describe Paperclip::Storage::S3 do
754
752
  end
755
753
 
756
754
  it "generates a url for the thumb" do
757
- object = stub
758
- @dummy.avatar.stubs(:s3_object).with(:thumb).returns(object)
759
- object.expects(:presigned_url).with(:get, expires_in: 1800)
755
+ object = double
756
+ allow(@dummy.avatar).to receive(:s3_object).with(:thumb).and_return(object)
757
+ expect(object).to receive(:presigned_url).with(:get, expires_in: 1800)
760
758
  @dummy.avatar.expiring_url(1800, :thumb)
761
759
  end
762
760
 
763
761
  it "generates a url for the default style" do
764
- object = stub
765
- @dummy.avatar.stubs(:s3_object).with(:original).returns(object)
766
- object.expects(:presigned_url).with(:get, expires_in: 1800)
762
+ object = double
763
+ allow(@dummy.avatar).to receive(:s3_object).with(:original).and_return(object)
764
+ expect(object).to receive(:presigned_url).with(:get, expires_in: 1800)
767
765
  @dummy.avatar.expiring_url(1800)
768
766
  end
769
767
  end
770
768
 
771
769
  context "Parsing S3 credentials with a bucket in them" do
772
770
  before do
773
- rebuild_model (aws2_add_region).merge storage: :s3,
774
- s3_credentials: {
775
- production: { bucket: "prod_bucket" },
776
- development: { bucket: "dev_bucket" }
777
- }
771
+ rebuild_model aws2_add_region.merge storage: :s3,
772
+ s3_credentials: {
773
+ production: { bucket: "prod_bucket" },
774
+ development: { bucket: "dev_bucket" }
775
+ }
778
776
  @dummy = Dummy.new
779
777
  end
780
778
 
@@ -793,21 +791,22 @@ describe Paperclip::Storage::S3 do
793
791
  end
794
792
  end
795
793
 
796
- # for aws-sdk-v2 the bucket.name is determined by the :s3_region
794
+ # the bucket.name is determined by the :s3_region
797
795
  context "Parsing S3 credentials with a s3_host_name in them" do
798
796
  before do
799
797
  rebuild_model storage: :s3,
800
- bucket: 'testing',
801
- s3_credentials: {
802
- production: {
803
- s3_region: "world-end",
804
- s3_host_name: "s3-world-end.amazonaws.com" },
805
- development: {
806
- s3_region: "ap-northeast-1",
807
- s3_host_name: "s3-ap-northeast-1.amazonaws.com" },
808
- test: {
809
- s3_region: "" }
810
- }
798
+ bucket: "testing",
799
+ s3_credentials: {
800
+ production: {
801
+ s3_region: "world-end",
802
+ s3_host_name: "s3-world-end.amazonaws.com"
803
+ },
804
+ development: {
805
+ s3_region: "ap-northeast-1",
806
+ s3_host_name: "s3-ap-northeast-1.amazonaws.com"
807
+ },
808
+ test: {}
809
+ }
811
810
  @dummy = Dummy.new
812
811
  end
813
812
 
@@ -815,16 +814,16 @@ describe Paperclip::Storage::S3 do
815
814
  rails_env("production") do
816
815
  assert_match %r{^s3-world-end.amazonaws.com}, @dummy.avatar.s3_host_name
817
816
  assert_match %r{^s3.world-end.amazonaws.com},
818
- @dummy.avatar.s3_bucket.client.config.endpoint.host
817
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
819
818
  end
820
819
  end
821
820
 
822
821
  it "gets the right s3_host_name in development" do
823
822
  rails_env("development") do
824
823
  assert_match %r{^s3.ap-northeast-1.amazonaws.com},
825
- @dummy.avatar.s3_host_name
824
+ @dummy.avatar.s3_host_name
826
825
  assert_match %r{^s3.ap-northeast-1.amazonaws.com},
827
- @dummy.avatar.s3_bucket.client.config.endpoint.host
826
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
828
827
  end
829
828
  end
830
829
 
@@ -840,13 +839,13 @@ describe Paperclip::Storage::S3 do
840
839
 
841
840
  context "An attachment with S3 storage" do
842
841
  before do
843
- rebuild_model (aws2_add_region).merge storage: :s3,
844
- bucket: "testing",
845
- path: ":attachment/:style/:basename:dotextension",
846
- s3_credentials: {
847
- access_key_id: "12345",
848
- secret_access_key: "54321"
849
- }
842
+ rebuild_model aws2_add_region.merge storage: :s3,
843
+ bucket: "testing",
844
+ path: ":attachment/:style/:basename:dotextension",
845
+ s3_credentials: {
846
+ access_key_id: "12345",
847
+ secret_access_key: "54321"
848
+ }
850
849
  end
851
850
 
852
851
  it "is extended by the S3 module" do
@@ -854,47 +853,47 @@ describe Paperclip::Storage::S3 do
854
853
  end
855
854
 
856
855
  it "won't be extended by the Filesystem module" do
857
- assert ! Dummy.new.avatar.is_a?(Paperclip::Storage::Filesystem)
856
+ assert !Dummy.new.avatar.is_a?(Paperclip::Storage::Filesystem)
858
857
  end
859
858
 
860
859
  context "when assigned" do
861
860
  before do
862
- @file = File.new(fixture_file('5k.png'), 'rb')
861
+ @file = File.new(fixture_file("5k.png"), "rb")
863
862
  @dummy = Dummy.new
864
863
  @dummy.avatar = @file
865
- @dummy.stubs(:new_record?).returns(false)
864
+ allow(@dummy).to receive(:new_record?).and_return(false)
866
865
  end
867
866
 
868
867
  after { @file.close }
869
868
 
870
869
  it "does not get a bucket to get a URL" do
871
- @dummy.avatar.expects(:s3).never
872
- @dummy.avatar.expects(:s3_bucket).never
870
+ expect(@dummy.avatar).to_not receive(:s3)
871
+ expect(@dummy.avatar).to_not receive(:s3_bucket)
873
872
  assert_match %r{^//s3\.amazonaws\.com/testing/avatars/original/5k\.png}, @dummy.avatar.url
874
873
  end
875
874
 
876
875
  it "is rewound after flush_writes" do
877
876
  @dummy.avatar.instance_eval "def after_flush_writes; end"
878
- @dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
877
+ allow(@dummy.avatar).to receive(:s3_object).and_return(double(upload_file: true))
879
878
  files = @dummy.avatar.queued_for_write.values.each(&:read)
880
879
  @dummy.save
881
880
  assert files.none?(&:eof?), "Expect all the files to be rewound."
882
881
  end
883
882
 
884
883
  it "is removed after after_flush_writes" do
885
- @dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
884
+ allow(@dummy.avatar).to receive(:s3_object).and_return(double(upload_file: true))
886
885
  paths = @dummy.avatar.queued_for_write.values.map(&:path)
887
886
  @dummy.save
888
- assert paths.none?{ |path| File.exist?(path) },
889
- "Expect all the files to be deleted."
887
+ assert paths.none? { |path| File.exist?(path) },
888
+ "Expect all the files to be deleted."
890
889
  end
891
890
 
892
891
  it "will retry to save again but back off on SlowDown" do
893
- @dummy.avatar.stubs(:sleep)
894
- Aws::S3::Object.any_instance.stubs(:upload_file).
895
- raises(Aws::S3::Errors::SlowDown.new(stub,
896
- stub(status: 503, body: "")))
897
- expect {@dummy.save}.to raise_error(Aws::S3::Errors::SlowDown)
892
+ allow(@dummy.avatar).to receive(:sleep)
893
+ allow_any_instance_of(Aws::S3::Object).to receive(:upload_file).
894
+ and_raise(Aws::S3::Errors::SlowDown.new(spy,
895
+ spy(status: 503, body: "")))
896
+ expect { @dummy.save }.to raise_error(Aws::S3::Errors::SlowDown)
898
897
  expect(@dummy.avatar).to have_received(:sleep).with(1)
899
898
  expect(@dummy.avatar).to have_received(:sleep).with(2)
900
899
  expect(@dummy.avatar).to have_received(:sleep).with(4)
@@ -904,10 +903,10 @@ describe Paperclip::Storage::S3 do
904
903
 
905
904
  context "and saved" do
906
905
  before do
907
- object = stub
908
- @dummy.avatar.stubs(:s3_object).returns(object)
909
- object.expects(:upload_file)
910
- .with(anything, content_type: 'image/png', acl: :"public-read")
906
+ object = double
907
+ allow(@dummy.avatar).to receive(:s3_object).and_return(object)
908
+ expect(object).to receive(:upload_file).
909
+ with(anything, content_type: "image/png", acl: :"public-read")
911
910
  @dummy.save
912
911
  end
913
912
 
@@ -918,11 +917,9 @@ describe Paperclip::Storage::S3 do
918
917
 
919
918
  context "and saved without a bucket" do
920
919
  before do
921
- Aws::S3::Bucket.any_instance.expects(:create)
922
- Aws::S3::Object.any_instance.stubs(:upload_file).
923
- raises(Aws::S3::Errors::NoSuchBucket
924
- .new(stub,
925
- stub(status: 404, body: "<foo/>"))).then.returns(nil)
920
+ allow_any_instance_of(Aws::S3::Object).to receive(:upload_file).
921
+ and_raise(Aws::S3::Errors::NoSuchBucket.new(double, double(status: 404, body: "<foo/>", empty?: false)))
922
+ allow_any_instance_of(Aws::S3::Object).to receive(:upload_file).and_return(nil)
926
923
  @dummy.save
927
924
  end
928
925
 
@@ -933,8 +930,8 @@ describe Paperclip::Storage::S3 do
933
930
 
934
931
  context "and remove" do
935
932
  before do
936
- Aws::S3::Object.any_instance.stubs(:exists?).returns(true)
937
- Aws::S3::Object.any_instance.stubs(:delete)
933
+ allow_any_instance_of(Aws::S3::Object).to receive(:exists?).and_return(true)
934
+ allow_any_instance_of(Aws::S3::Object).to receive(:delete)
938
935
  @dummy.destroy
939
936
  end
940
937
 
@@ -943,14 +940,27 @@ describe Paperclip::Storage::S3 do
943
940
  end
944
941
  end
945
942
 
946
- context 'that the file were missing' do
943
+ context "and remove, calling S3 Object destroy once per unique style" do
947
944
  before do
948
- Aws::S3::Object.any_instance.stubs(:exists?)
949
- .raises(Aws::S3::Errors::ServiceError.new("rspec stub raises",
950
- "object exists?"))
945
+ allow_any_instance_of(Aws::S3::Object).to receive(:exists?).and_return(true)
946
+ expect_any_instance_of(Aws::S3::Object).to receive(:delete).once
947
+ @dummy.avatar.clear(:original)
948
+ @dummy.destroy
951
949
  end
952
950
 
953
- it 'returns false on exists?' do
951
+ it "succeeds" do
952
+ assert true
953
+ end
954
+ end
955
+
956
+ context "that the file were missing" do
957
+ before do
958
+ allow_any_instance_of(Aws::S3::Object).to receive(:exists?).
959
+ and_raise(Aws::S3::Errors::ServiceError.new("rspec stub raises",
960
+ "object exists?"))
961
+ end
962
+
963
+ it "returns false on exists?" do
954
964
  assert !@dummy.avatar.exists?
955
965
  end
956
966
  end
@@ -959,31 +969,31 @@ describe Paperclip::Storage::S3 do
959
969
 
960
970
  context "An attachment with S3 storage and bucket defined as a Proc" do
961
971
  before do
962
- rebuild_model (aws2_add_region).merge storage: :s3,
963
- bucket: lambda { |attachment| "bucket_#{attachment.instance.other}" },
964
- s3_credentials: {not: :important}
972
+ rebuild_model aws2_add_region.merge storage: :s3,
973
+ bucket: lambda { |attachment| "bucket_#{attachment.instance.other}" },
974
+ s3_credentials: { not: :important }
965
975
  end
966
976
 
967
977
  it "gets the right bucket name" do
968
- assert "bucket_a", Dummy.new(other: 'a').avatar.bucket_name
969
- assert "bucket_a", Dummy.new(other: 'a').avatar.s3_bucket.name
970
- assert "bucket_b", Dummy.new(other: 'b').avatar.bucket_name
971
- assert "bucket_b", Dummy.new(other: 'b').avatar.s3_bucket.name
978
+ assert "bucket_a", Dummy.new(other: "a").avatar.bucket_name
979
+ assert "bucket_a", Dummy.new(other: "a").avatar.s3_bucket.name
980
+ assert "bucket_b", Dummy.new(other: "b").avatar.bucket_name
981
+ assert "bucket_b", Dummy.new(other: "b").avatar.s3_bucket.name
972
982
  end
973
983
  end
974
984
 
975
985
  context "An attachment with S3 storage and S3 credentials defined as a Proc" do
976
986
  before do
977
- rebuild_model (aws2_add_region).merge storage: :s3,
978
- bucket: {not: :important},
979
- s3_credentials: lambda { |attachment|
980
- Hash['access_key_id' => "access#{attachment.instance.other}", 'secret_access_key' => "secret#{attachment.instance.other}"]
981
- }
987
+ rebuild_model aws2_add_region.merge storage: :s3,
988
+ bucket: { not: :important },
989
+ s3_credentials: lambda { |attachment|
990
+ Hash["access_key_id" => "access#{attachment.instance.other}", "secret_access_key" => "secret#{attachment.instance.other}"]
991
+ }
982
992
  end
983
993
 
984
994
  it "gets the right credentials" do
985
- assert "access1234", Dummy.new(other: '1234').avatar.s3_credentials[:access_key_id]
986
- assert "secret1234", Dummy.new(other: '1234').avatar.s3_credentials[:secret_access_key]
995
+ assert "access1234", Dummy.new(other: "1234").avatar.s3_credentials[:access_key_id]
996
+ assert "secret1234", Dummy.new(other: "1234").avatar.s3_credentials[:secret_access_key]
987
997
  end
988
998
  end
989
999
 
@@ -991,11 +1001,11 @@ describe Paperclip::Storage::S3 do
991
1001
  before do
992
1002
  class DummyCredentialProvider; end
993
1003
 
994
- rebuild_model (aws2_add_region).merge storage: :s3,
995
- bucket: "testing",
996
- s3_credentials: {
997
- credentials: DummyCredentialProvider.new
998
- }
1004
+ rebuild_model aws2_add_region.merge storage: :s3,
1005
+ bucket: "testing",
1006
+ s3_credentials: {
1007
+ credentials: DummyCredentialProvider.new
1008
+ }
999
1009
  @dummy = Dummy.new
1000
1010
  end
1001
1011
 
@@ -1006,8 +1016,8 @@ describe Paperclip::Storage::S3 do
1006
1016
 
1007
1017
  context "An attachment with S3 storage and S3 credentials in an unsupported manor" do
1008
1018
  before do
1009
- rebuild_model (aws2_add_region).merge storage: :s3,
1010
- bucket: "testing", s3_credentials: ["unsupported"]
1019
+ rebuild_model aws2_add_region.merge storage: :s3,
1020
+ bucket: "testing", s3_credentials: ["unsupported"]
1011
1021
  @dummy = Dummy.new
1012
1022
  end
1013
1023
 
@@ -1020,7 +1030,7 @@ describe Paperclip::Storage::S3 do
1020
1030
 
1021
1031
  context "An attachment with S3 storage and S3 credentials not supplied" do
1022
1032
  before do
1023
- rebuild_model (aws2_add_region).merge storage: :s3, bucket: "testing"
1033
+ rebuild_model aws2_add_region.merge storage: :s3, bucket: "testing"
1024
1034
  @dummy = Dummy.new
1025
1035
  end
1026
1036
 
@@ -1031,19 +1041,19 @@ describe Paperclip::Storage::S3 do
1031
1041
 
1032
1042
  context "An attachment with S3 storage and specific s3 headers set" do
1033
1043
  before do
1034
- rebuild_model (aws2_add_region).merge storage: :s3,
1035
- bucket: "testing",
1036
- path: ":attachment/:style/:basename:dotextension",
1037
- s3_credentials: {
1038
- 'access_key_id' => "12345",
1039
- 'secret_access_key' => "54321"
1040
- },
1041
- s3_headers: {'Cache-Control' => 'max-age=31557600'}
1044
+ rebuild_model aws2_add_region.merge storage: :s3,
1045
+ bucket: "testing",
1046
+ path: ":attachment/:style/:basename:dotextension",
1047
+ s3_credentials: {
1048
+ "access_key_id" => "12345",
1049
+ "secret_access_key" => "54321"
1050
+ },
1051
+ s3_headers: { "Cache-Control" => "max-age=31557600" }
1042
1052
  end
1043
1053
 
1044
1054
  context "when assigned" do
1045
1055
  before do
1046
- @file = File.new(fixture_file('5k.png'), 'rb')
1056
+ @file = File.new(fixture_file("5k.png"), "rb")
1047
1057
  @dummy = Dummy.new
1048
1058
  @dummy.avatar = @file
1049
1059
  end
@@ -1052,14 +1062,14 @@ describe Paperclip::Storage::S3 do
1052
1062
 
1053
1063
  context "and saved" do
1054
1064
  before do
1055
- object = stub
1056
- @dummy.avatar.stubs(:s3_object).returns(object)
1057
-
1058
- object.expects(:upload_file)
1059
- .with(anything,
1060
- content_type: 'image/png',
1061
- acl: :"public-read",
1062
- cache_control: 'max-age=31557600')
1065
+ object = double
1066
+ allow(@dummy.avatar).to receive(:s3_object).and_return(object)
1067
+
1068
+ expect(object).to receive(:upload_file).
1069
+ with(anything,
1070
+ content_type: "image/png",
1071
+ acl: :"public-read",
1072
+ cache_control: "max-age=31557600")
1063
1073
  @dummy.save
1064
1074
  end
1065
1075
 
@@ -1072,19 +1082,19 @@ describe Paperclip::Storage::S3 do
1072
1082
 
1073
1083
  context "An attachment with S3 storage and metadata set using header names" do
1074
1084
  before do
1075
- rebuild_model (aws2_add_region).merge storage: :s3,
1076
- bucket: "testing",
1077
- path: ":attachment/:style/:basename:dotextension",
1078
- s3_credentials: {
1079
- 'access_key_id' => "12345",
1080
- 'secret_access_key' => "54321"
1081
- },
1082
- s3_headers: {'x-amz-meta-color' => 'red'}
1085
+ rebuild_model aws2_add_region.merge storage: :s3,
1086
+ bucket: "testing",
1087
+ path: ":attachment/:style/:basename:dotextension",
1088
+ s3_credentials: {
1089
+ "access_key_id" => "12345",
1090
+ "secret_access_key" => "54321"
1091
+ },
1092
+ s3_headers: { "x-amz-meta-color" => "red" }
1083
1093
  end
1084
1094
 
1085
1095
  context "when assigned" do
1086
1096
  before do
1087
- @file = File.new(fixture_file('5k.png'), 'rb')
1097
+ @file = File.new(fixture_file("5k.png"), "rb")
1088
1098
  @dummy = Dummy.new
1089
1099
  @dummy.avatar = @file
1090
1100
  end
@@ -1093,14 +1103,14 @@ describe Paperclip::Storage::S3 do
1093
1103
 
1094
1104
  context "and saved" do
1095
1105
  before do
1096
- object = stub
1097
- @dummy.avatar.stubs(:s3_object).returns(object)
1098
-
1099
- object.expects(:upload_file)
1100
- .with(anything,
1101
- content_type: 'image/png',
1102
- acl: :"public-read",
1103
- metadata: { "color" => "red" })
1106
+ object = double
1107
+ allow(@dummy.avatar).to receive(:s3_object).and_return(object)
1108
+
1109
+ expect(object).to receive(:upload_file).
1110
+ with(anything,
1111
+ content_type: "image/png",
1112
+ acl: :"public-read",
1113
+ metadata: { "color" => "red" })
1104
1114
  @dummy.save
1105
1115
  end
1106
1116
 
@@ -1113,19 +1123,19 @@ describe Paperclip::Storage::S3 do
1113
1123
 
1114
1124
  context "An attachment with S3 storage and metadata set using the :s3_metadata option" do
1115
1125
  before do
1116
- rebuild_model (aws2_add_region).merge storage: :s3,
1117
- bucket: "testing",
1118
- path: ":attachment/:style/:basename:dotextension",
1119
- s3_credentials: {
1120
- 'access_key_id' => "12345",
1121
- 'secret_access_key' => "54321"
1122
- },
1123
- s3_metadata: { "color" => "red" }
1126
+ rebuild_model aws2_add_region.merge storage: :s3,
1127
+ bucket: "testing",
1128
+ path: ":attachment/:style/:basename:dotextension",
1129
+ s3_credentials: {
1130
+ "access_key_id" => "12345",
1131
+ "secret_access_key" => "54321"
1132
+ },
1133
+ s3_metadata: { "color" => "red" }
1124
1134
  end
1125
1135
 
1126
1136
  context "when assigned" do
1127
1137
  before do
1128
- @file = File.new(fixture_file('5k.png'), 'rb')
1138
+ @file = File.new(fixture_file("5k.png"), "rb")
1129
1139
  @dummy = Dummy.new
1130
1140
  @dummy.avatar = @file
1131
1141
  end
@@ -1134,14 +1144,14 @@ describe Paperclip::Storage::S3 do
1134
1144
 
1135
1145
  context "and saved" do
1136
1146
  before do
1137
- object = stub
1138
- @dummy.avatar.stubs(:s3_object).returns(object)
1139
-
1140
- object.expects(:upload_file)
1141
- .with(anything,
1142
- content_type: 'image/png',
1143
- acl: :"public-read",
1144
- metadata: { "color" => "red" })
1147
+ object = double
1148
+ allow(@dummy.avatar).to receive(:s3_object).and_return(object)
1149
+
1150
+ expect(object).to receive(:upload_file).
1151
+ with(anything,
1152
+ content_type: "image/png",
1153
+ acl: :"public-read",
1154
+ metadata: { "color" => "red" })
1145
1155
  @dummy.save
1146
1156
  end
1147
1157
 
@@ -1155,19 +1165,19 @@ describe Paperclip::Storage::S3 do
1155
1165
  context "An attachment with S3 storage and storage class set" do
1156
1166
  context "using the header name" do
1157
1167
  before do
1158
- rebuild_model (aws2_add_region).merge storage: :s3,
1159
- bucket: "testing",
1160
- path: ":attachment/:style/:basename:dotextension",
1161
- s3_credentials: {
1162
- 'access_key_id' => "12345",
1163
- 'secret_access_key' => "54321"
1164
- },
1165
- s3_headers: { "x-amz-storage-class" => "reduced_redundancy" }
1168
+ rebuild_model aws2_add_region.merge storage: :s3,
1169
+ bucket: "testing",
1170
+ path: ":attachment/:style/:basename:dotextension",
1171
+ s3_credentials: {
1172
+ "access_key_id" => "12345",
1173
+ "secret_access_key" => "54321"
1174
+ },
1175
+ s3_headers: { "x-amz-storage-class" => "reduced_redundancy" }
1166
1176
  end
1167
1177
 
1168
1178
  context "when assigned" do
1169
1179
  before do
1170
- @file = File.new(fixture_file('5k.png'), 'rb')
1180
+ @file = File.new(fixture_file("5k.png"), "rb")
1171
1181
  @dummy = Dummy.new
1172
1182
  @dummy.avatar = @file
1173
1183
  end
@@ -1176,14 +1186,14 @@ describe Paperclip::Storage::S3 do
1176
1186
 
1177
1187
  context "and saved" do
1178
1188
  before do
1179
- object = stub
1180
- @dummy.avatar.stubs(:s3_object).returns(object)
1181
-
1182
- object.expects(:upload_file)
1183
- .with(anything,
1184
- content_type: 'image/png',
1185
- acl: :"public-read",
1186
- storage_class: "reduced_redundancy")
1189
+ object = double
1190
+ allow(@dummy.avatar).to receive(:s3_object).and_return(object)
1191
+
1192
+ expect(object).to receive(:upload_file).
1193
+ with(anything,
1194
+ content_type: "image/png",
1195
+ acl: :"public-read",
1196
+ storage_class: "reduced_redundancy")
1187
1197
  @dummy.save
1188
1198
  end
1189
1199
 
@@ -1196,24 +1206,24 @@ describe Paperclip::Storage::S3 do
1196
1206
 
1197
1207
  context "using per style hash" do
1198
1208
  before do
1199
- rebuild_model (aws2_add_region).merge :storage => :s3,
1200
- :bucket => "testing",
1201
- :path => ":attachment/:style/:basename.:extension",
1202
- :styles => {
1203
- :thumb => "80x80>"
1204
- },
1205
- :s3_credentials => {
1206
- 'access_key_id' => "12345",
1207
- 'secret_access_key' => "54321"
1208
- },
1209
- :s3_storage_class => {
1210
- :thumb => :reduced_redundancy
1211
- }
1209
+ rebuild_model aws2_add_region.merge storage: :s3,
1210
+ bucket: "testing",
1211
+ path: ":attachment/:style/:basename.:extension",
1212
+ styles: {
1213
+ thumb: "80x80>"
1214
+ },
1215
+ s3_credentials: {
1216
+ "access_key_id" => "12345",
1217
+ "secret_access_key" => "54321"
1218
+ },
1219
+ s3_storage_class: {
1220
+ thumb: :reduced_redundancy
1221
+ }
1212
1222
  end
1213
1223
 
1214
1224
  context "when assigned" do
1215
1225
  before do
1216
- @file = File.new(fixture_file('5k.png'), 'rb')
1226
+ @file = File.new(fixture_file("5k.png"), "rb")
1217
1227
  @dummy = Dummy.new
1218
1228
  @dummy.avatar = @file
1219
1229
  end
@@ -1222,18 +1232,18 @@ describe Paperclip::Storage::S3 do
1222
1232
 
1223
1233
  context "and saved" do
1224
1234
  before do
1225
- object = stub
1235
+ object = double
1226
1236
  [:thumb, :original].each do |style|
1227
- @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1237
+ allow(@dummy.avatar).to receive(:s3_object).with(style).and_return(object)
1228
1238
 
1229
1239
  expected_options = {
1230
- :content_type => "image/png",
1240
+ content_type: "image/png",
1231
1241
  acl: :"public-read"
1232
1242
  }
1233
- expected_options.merge!(:storage_class => :reduced_redundancy) if style == :thumb
1243
+ expected_options.merge!(storage_class: :reduced_redundancy) if style == :thumb
1234
1244
 
1235
- object.expects(:upload_file)
1236
- .with(anything, expected_options)
1245
+ expect(object).to receive(:upload_file).
1246
+ with(anything, expected_options)
1237
1247
  end
1238
1248
  @dummy.save
1239
1249
  end
@@ -1247,22 +1257,22 @@ describe Paperclip::Storage::S3 do
1247
1257
 
1248
1258
  context "using global hash option" do
1249
1259
  before do
1250
- rebuild_model (aws2_add_region).merge :storage => :s3,
1251
- :bucket => "testing",
1252
- :path => ":attachment/:style/:basename.:extension",
1253
- :styles => {
1254
- :thumb => "80x80>"
1255
- },
1256
- :s3_credentials => {
1257
- 'access_key_id' => "12345",
1258
- 'secret_access_key' => "54321"
1259
- },
1260
- :s3_storage_class => :reduced_redundancy
1260
+ rebuild_model aws2_add_region.merge storage: :s3,
1261
+ bucket: "testing",
1262
+ path: ":attachment/:style/:basename.:extension",
1263
+ styles: {
1264
+ thumb: "80x80>"
1265
+ },
1266
+ s3_credentials: {
1267
+ "access_key_id" => "12345",
1268
+ "secret_access_key" => "54321"
1269
+ },
1270
+ s3_storage_class: :reduced_redundancy
1261
1271
  end
1262
1272
 
1263
1273
  context "when assigned" do
1264
1274
  before do
1265
- @file = File.new(fixture_file('5k.png'), 'rb')
1275
+ @file = File.new(fixture_file("5k.png"), "rb")
1266
1276
  @dummy = Dummy.new
1267
1277
  @dummy.avatar = @file
1268
1278
  end
@@ -1271,14 +1281,14 @@ describe Paperclip::Storage::S3 do
1271
1281
 
1272
1282
  context "and saved" do
1273
1283
  before do
1274
- object = stub
1284
+ object = double
1275
1285
  [:thumb, :original].each do |style|
1276
- @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1286
+ allow(@dummy.avatar).to receive(:s3_object).with(style).and_return(object)
1277
1287
 
1278
- object.expects(:upload_file)
1279
- .with(anything, :content_type => "image/png",
1280
- acl: :"public-read",
1281
- :storage_class => :reduced_redundancy)
1288
+ expect(object).to receive(:upload_file).
1289
+ with(anything, content_type: "image/png",
1290
+ acl: :"public-read",
1291
+ storage_class: :reduced_redundancy)
1282
1292
  end
1283
1293
  @dummy.save
1284
1294
  end
@@ -1292,21 +1302,23 @@ describe Paperclip::Storage::S3 do
1292
1302
  end
1293
1303
 
1294
1304
  context "Can disable AES256 encryption multiple ways" do
1295
- [nil, false, ''].each do |tech|
1305
+ [nil, false, ""].each do |tech|
1296
1306
  before do
1297
1307
  rebuild_model(
1298
- (aws2_add_region).merge storage: :s3,
1299
- bucket: "testing",
1300
- path: ":attachment/:style/:basename:dotextension",
1301
- s3_credentials: {
1302
- 'access_key_id' => "12345",
1303
- 'secret_access_key' => "54321"},
1304
- s3_server_side_encryption: tech)
1308
+ aws2_add_region.merge(storage: :s3,
1309
+ bucket: "testing",
1310
+ path: ":attachment/:style/:basename:dotextension",
1311
+ s3_credentials: {
1312
+ "access_key_id" => "12345",
1313
+ "secret_access_key" => "54321"
1314
+ },
1315
+ s3_server_side_encryption: tech)
1316
+ )
1305
1317
  end
1306
1318
 
1307
1319
  context "when assigned" do
1308
1320
  before do
1309
- @file = File.new(fixture_file('5k.png'), 'rb')
1321
+ @file = File.new(fixture_file("5k.png"), "rb")
1310
1322
  @dummy = Dummy.new
1311
1323
  @dummy.avatar = @file
1312
1324
  end
@@ -1315,11 +1327,11 @@ describe Paperclip::Storage::S3 do
1315
1327
 
1316
1328
  context "and saved" do
1317
1329
  before do
1318
- object = stub
1319
- @dummy.avatar.stubs(:s3_object).returns(object)
1330
+ object = double
1331
+ allow(@dummy.avatar).to receive(:s3_object).and_return(object)
1320
1332
 
1321
- object.expects(:upload_file)
1322
- .with(anything, :content_type => "image/png", acl: :"public-read")
1333
+ expect(object).to receive(:upload_file).
1334
+ with(anything, content_type: "image/png", acl: :"public-read")
1323
1335
  @dummy.save
1324
1336
  end
1325
1337
 
@@ -1333,19 +1345,19 @@ describe Paperclip::Storage::S3 do
1333
1345
 
1334
1346
  context "An attachment with S3 storage and using AES256 encryption" do
1335
1347
  before do
1336
- rebuild_model (aws2_add_region).merge storage: :s3,
1337
- bucket: "testing",
1338
- path: ":attachment/:style/:basename:dotextension",
1339
- s3_credentials: {
1340
- 'access_key_id' => "12345",
1341
- 'secret_access_key' => "54321"
1342
- },
1343
- s3_server_side_encryption: "AES256"
1348
+ rebuild_model aws2_add_region.merge storage: :s3,
1349
+ bucket: "testing",
1350
+ path: ":attachment/:style/:basename:dotextension",
1351
+ s3_credentials: {
1352
+ "access_key_id" => "12345",
1353
+ "secret_access_key" => "54321"
1354
+ },
1355
+ s3_server_side_encryption: "AES256"
1344
1356
  end
1345
1357
 
1346
1358
  context "when assigned" do
1347
1359
  before do
1348
- @file = File.new(fixture_file('5k.png'), 'rb')
1360
+ @file = File.new(fixture_file("5k.png"), "rb")
1349
1361
  @dummy = Dummy.new
1350
1362
  @dummy.avatar = @file
1351
1363
  end
@@ -1354,13 +1366,13 @@ describe Paperclip::Storage::S3 do
1354
1366
 
1355
1367
  context "and saved" do
1356
1368
  before do
1357
- object = stub
1358
- @dummy.avatar.stubs(:s3_object).returns(object)
1369
+ object = double
1370
+ allow(@dummy.avatar).to receive(:s3_object).and_return(object)
1359
1371
 
1360
- object.expects(:upload_file)
1361
- .with(anything, content_type: "image/png",
1362
- acl: :"public-read",
1363
- server_side_encryption: "AES256")
1372
+ expect(object).to receive(:upload_file).
1373
+ with(anything, content_type: "image/png",
1374
+ acl: :"public-read",
1375
+ server_side_encryption: "AES256")
1364
1376
  @dummy.save
1365
1377
  end
1366
1378
 
@@ -1373,19 +1385,19 @@ describe Paperclip::Storage::S3 do
1373
1385
 
1374
1386
  context "An attachment with S3 storage and storage class set using the :storage_class option" do
1375
1387
  before do
1376
- rebuild_model (aws2_add_region).merge storage: :s3,
1377
- bucket: "testing",
1378
- path: ":attachment/:style/:basename:dotextension",
1379
- s3_credentials: {
1380
- 'access_key_id' => "12345",
1381
- 'secret_access_key' => "54321"
1382
- },
1383
- s3_storage_class: :reduced_redundancy
1388
+ rebuild_model aws2_add_region.merge storage: :s3,
1389
+ bucket: "testing",
1390
+ path: ":attachment/:style/:basename:dotextension",
1391
+ s3_credentials: {
1392
+ "access_key_id" => "12345",
1393
+ "secret_access_key" => "54321"
1394
+ },
1395
+ s3_storage_class: :reduced_redundancy
1384
1396
  end
1385
1397
 
1386
1398
  context "when assigned" do
1387
1399
  before do
1388
- @file = File.new(fixture_file('5k.png'), 'rb')
1400
+ @file = File.new(fixture_file("5k.png"), "rb")
1389
1401
  @dummy = Dummy.new
1390
1402
  @dummy.avatar = @file
1391
1403
  end
@@ -1394,14 +1406,14 @@ describe Paperclip::Storage::S3 do
1394
1406
 
1395
1407
  context "and saved" do
1396
1408
  before do
1397
- object = stub
1398
- @dummy.avatar.stubs(:s3_object).returns(object)
1399
-
1400
- object.expects(:upload_file)
1401
- .with(anything,
1402
- content_type: "image/png",
1403
- acl: :"public-read",
1404
- storage_class: :reduced_redundancy)
1409
+ object = double
1410
+ allow(@dummy.avatar).to receive(:s3_object).and_return(object)
1411
+
1412
+ expect(object).to receive(:upload_file).
1413
+ with(anything,
1414
+ content_type: "image/png",
1415
+ acl: :"public-read",
1416
+ storage_class: :reduced_redundancy)
1405
1417
  @dummy.save
1406
1418
  end
1407
1419
 
@@ -1414,13 +1426,39 @@ describe Paperclip::Storage::S3 do
1414
1426
 
1415
1427
  context "with S3 credentials supplied as Pathname" do
1416
1428
  before do
1417
- ENV['S3_KEY'] = 'pathname_key'
1418
- ENV['S3_BUCKET'] = 'pathname_bucket'
1419
- ENV['S3_SECRET'] = 'pathname_secret'
1429
+ ENV["S3_KEY"] = "pathname_key"
1430
+ ENV["S3_BUCKET"] = "pathname_bucket"
1431
+ ENV["S3_SECRET"] = "pathname_secret"
1420
1432
 
1421
- rails_env('test') do
1422
- rebuild_model (aws2_add_region).merge storage: :s3,
1423
- s3_credentials: Pathname.new(fixture_file('s3.yml'))
1433
+ rails_env("test") do
1434
+ rebuild_model aws2_add_region.merge storage: :s3,
1435
+ s3_credentials: Pathname.new(fixture_file("s3.yml"))
1436
+
1437
+ Dummy.delete_all
1438
+ @dummy = Dummy.new
1439
+ end
1440
+ end
1441
+
1442
+ it "parses the credentials" do
1443
+ assert_equal "pathname_bucket", @dummy.avatar.bucket_name
1444
+
1445
+ assert_equal "pathname_key",
1446
+ @dummy.avatar.s3_bucket.client.config.access_key_id
1447
+
1448
+ assert_equal "pathname_secret",
1449
+ @dummy.avatar.s3_bucket.client.config.secret_access_key
1450
+ end
1451
+ end
1452
+
1453
+ context "with S3 credentials supplied as Pathname and aliases being set" do
1454
+ before do
1455
+ ENV["S3_KEY"] = "pathname_key"
1456
+ ENV["S3_BUCKET"] = "pathname_bucket"
1457
+ ENV["S3_SECRET"] = "pathname_secret"
1458
+
1459
+ rails_env("test") do
1460
+ rebuild_model aws2_add_region.merge storage: :s3,
1461
+ s3_credentials: Pathname.new(fixture_file("aws_s3.yml"))
1424
1462
 
1425
1463
  Dummy.delete_all
1426
1464
  @dummy = Dummy.new
@@ -1428,25 +1466,52 @@ describe Paperclip::Storage::S3 do
1428
1466
  end
1429
1467
 
1430
1468
  it "parses the credentials" do
1431
- assert_equal 'pathname_bucket', @dummy.avatar.bucket_name
1469
+ assert_equal "pathname_bucket", @dummy.avatar.bucket_name
1432
1470
 
1433
- assert_equal 'pathname_key',
1434
- @dummy.avatar.s3_bucket.client.config.access_key_id
1471
+ assert_equal "pathname_key",
1472
+ @dummy.avatar.s3_bucket.client.config.access_key_id
1435
1473
 
1436
- assert_equal 'pathname_secret',
1437
- @dummy.avatar.s3_bucket.client.config.secret_access_key
1474
+ assert_equal "pathname_secret",
1475
+ @dummy.avatar.s3_bucket.client.config.secret_access_key
1438
1476
  end
1439
1477
  end
1440
1478
 
1441
1479
  context "with S3 credentials in a YAML file" do
1442
1480
  before do
1443
- ENV['S3_KEY'] = 'env_key'
1444
- ENV['S3_BUCKET'] = 'env_bucket'
1445
- ENV['S3_SECRET'] = 'env_secret'
1481
+ ENV["S3_KEY"] = "env_key"
1482
+ ENV["S3_BUCKET"] = "env_bucket"
1483
+ ENV["S3_SECRET"] = "env_secret"
1446
1484
 
1447
- rails_env('test') do
1448
- rebuild_model (aws2_add_region).merge storage: :s3,
1449
- s3_credentials: File.new(fixture_file('s3.yml'))
1485
+ rails_env("test") do
1486
+ rebuild_model aws2_add_region.merge storage: :s3,
1487
+ s3_credentials: File.new(fixture_file("s3.yml"))
1488
+
1489
+ Dummy.delete_all
1490
+
1491
+ @dummy = Dummy.new
1492
+ end
1493
+ end
1494
+
1495
+ it "runs the file through ERB" do
1496
+ assert_equal "env_bucket", @dummy.avatar.bucket_name
1497
+
1498
+ assert_equal "env_key",
1499
+ @dummy.avatar.s3_bucket.client.config.access_key_id
1500
+
1501
+ assert_equal "env_secret",
1502
+ @dummy.avatar.s3_bucket.client.config.secret_access_key
1503
+ end
1504
+ end
1505
+
1506
+ context "with S3 credentials in a YAML file and aliases being set" do
1507
+ before do
1508
+ ENV["S3_KEY"] = "env_key"
1509
+ ENV["S3_BUCKET"] = "env_bucket"
1510
+ ENV["S3_SECRET"] = "env_secret"
1511
+
1512
+ rails_env("test") do
1513
+ rebuild_model aws2_add_region.merge storage: :s3,
1514
+ s3_credentials: File.new(fixture_file("aws_s3.yml"))
1450
1515
 
1451
1516
  Dummy.delete_all
1452
1517
 
@@ -1455,31 +1520,31 @@ describe Paperclip::Storage::S3 do
1455
1520
  end
1456
1521
 
1457
1522
  it "runs the file through ERB" do
1458
- assert_equal 'env_bucket', @dummy.avatar.bucket_name
1523
+ assert_equal "env_bucket", @dummy.avatar.bucket_name
1459
1524
 
1460
- assert_equal 'env_key',
1461
- @dummy.avatar.s3_bucket.client.config.access_key_id
1525
+ assert_equal "env_key",
1526
+ @dummy.avatar.s3_bucket.client.config.access_key_id
1462
1527
 
1463
- assert_equal 'env_secret',
1464
- @dummy.avatar.s3_bucket.client.config.secret_access_key
1528
+ assert_equal "env_secret",
1529
+ @dummy.avatar.s3_bucket.client.config.secret_access_key
1465
1530
  end
1466
1531
  end
1467
1532
 
1468
1533
  context "S3 Permissions" do
1469
1534
  context "defaults to :public_read" do
1470
1535
  before do
1471
- rebuild_model (aws2_add_region).merge storage: :s3,
1472
- bucket: "testing",
1473
- path: ":attachment/:style/:basename:dotextension",
1474
- s3_credentials: {
1475
- 'access_key_id' => "12345",
1476
- 'secret_access_key' => "54321"
1477
- }
1536
+ rebuild_model aws2_add_region.merge storage: :s3,
1537
+ bucket: "testing",
1538
+ path: ":attachment/:style/:basename:dotextension",
1539
+ s3_credentials: {
1540
+ "access_key_id" => "12345",
1541
+ "secret_access_key" => "54321"
1542
+ }
1478
1543
  end
1479
1544
 
1480
1545
  context "when assigned" do
1481
1546
  before do
1482
- @file = File.new(fixture_file('5k.png'), 'rb')
1547
+ @file = File.new(fixture_file("5k.png"), "rb")
1483
1548
  @dummy = Dummy.new
1484
1549
  @dummy.avatar = @file
1485
1550
  end
@@ -1488,11 +1553,11 @@ describe Paperclip::Storage::S3 do
1488
1553
 
1489
1554
  context "and saved" do
1490
1555
  before do
1491
- object = stub
1492
- @dummy.avatar.stubs(:s3_object).returns(object)
1556
+ object = double
1557
+ allow(@dummy.avatar).to receive(:s3_object).and_return(object)
1493
1558
 
1494
- object.expects(:upload_file)
1495
- .with(anything, content_type: "image/png", acl: :"public-read")
1559
+ expect(object).to receive(:upload_file).
1560
+ with(anything, content_type: "image/png", acl: :"public-read")
1496
1561
  @dummy.save
1497
1562
  end
1498
1563
 
@@ -1505,19 +1570,19 @@ describe Paperclip::Storage::S3 do
1505
1570
 
1506
1571
  context "string permissions set" do
1507
1572
  before do
1508
- rebuild_model (aws2_add_region).merge storage: :s3,
1509
- bucket: "testing",
1510
- path: ":attachment/:style/:basename:dotextension",
1511
- s3_credentials: {
1512
- 'access_key_id' => "12345",
1513
- 'secret_access_key' => "54321"
1514
- },
1515
- s3_permissions: :private
1573
+ rebuild_model aws2_add_region.merge storage: :s3,
1574
+ bucket: "testing",
1575
+ path: ":attachment/:style/:basename:dotextension",
1576
+ s3_credentials: {
1577
+ "access_key_id" => "12345",
1578
+ "secret_access_key" => "54321"
1579
+ },
1580
+ s3_permissions: :private
1516
1581
  end
1517
1582
 
1518
1583
  context "when assigned" do
1519
1584
  before do
1520
- @file = File.new(fixture_file('5k.png'), 'rb')
1585
+ @file = File.new(fixture_file("5k.png"), "rb")
1521
1586
  @dummy = Dummy.new
1522
1587
  @dummy.avatar = @file
1523
1588
  end
@@ -1526,11 +1591,11 @@ describe Paperclip::Storage::S3 do
1526
1591
 
1527
1592
  context "and saved" do
1528
1593
  before do
1529
- object = stub
1530
- @dummy.avatar.stubs(:s3_object).returns(object)
1594
+ object = double
1595
+ allow(@dummy.avatar).to receive(:s3_object).and_return(object)
1531
1596
 
1532
- object.expects(:upload_file)
1533
- .with(anything, content_type: "image/png", acl: :private)
1597
+ expect(object).to receive(:upload_file).
1598
+ with(anything, content_type: "image/png", acl: :private)
1534
1599
  @dummy.save
1535
1600
  end
1536
1601
 
@@ -1543,25 +1608,25 @@ describe Paperclip::Storage::S3 do
1543
1608
 
1544
1609
  context "hash permissions set" do
1545
1610
  before do
1546
- rebuild_model (aws2_add_region).merge storage: :s3,
1547
- bucket: "testing",
1548
- path: ":attachment/:style/:basename:dotextension",
1549
- styles: {
1550
- thumb: "80x80>"
1551
- },
1552
- s3_credentials: {
1553
- 'access_key_id' => "12345",
1554
- 'secret_access_key' => "54321"
1555
- },
1556
- s3_permissions: {
1557
- original: :private,
1558
- thumb: :public_read
1559
- }
1611
+ rebuild_model aws2_add_region.merge storage: :s3,
1612
+ bucket: "testing",
1613
+ path: ":attachment/:style/:basename:dotextension",
1614
+ styles: {
1615
+ thumb: "80x80>"
1616
+ },
1617
+ s3_credentials: {
1618
+ "access_key_id" => "12345",
1619
+ "secret_access_key" => "54321"
1620
+ },
1621
+ s3_permissions: {
1622
+ original: :private,
1623
+ thumb: :public_read
1624
+ }
1560
1625
  end
1561
1626
 
1562
1627
  context "when assigned" do
1563
1628
  before do
1564
- @file = File.new(fixture_file('5k.png'), 'rb')
1629
+ @file = File.new(fixture_file("5k.png"), "rb")
1565
1630
  @dummy = Dummy.new
1566
1631
  @dummy.avatar = @file
1567
1632
  end
@@ -1571,13 +1636,13 @@ describe Paperclip::Storage::S3 do
1571
1636
  context "and saved" do
1572
1637
  before do
1573
1638
  [:thumb, :original].each do |style|
1574
- object = stub
1575
- @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1639
+ object = double
1640
+ allow(@dummy.avatar).to receive(:s3_object).with(style).and_return(object)
1576
1641
 
1577
- object.expects(:upload_file)
1578
- .with(anything,
1579
- content_type: "image/png",
1580
- acl: style == :thumb ? :public_read : :private)
1642
+ expect(object).to receive(:upload_file).
1643
+ with(anything,
1644
+ content_type: "image/png",
1645
+ acl: style == :thumb ? :public_read : :private)
1581
1646
  end
1582
1647
  @dummy.save
1583
1648
  end
@@ -1592,19 +1657,19 @@ describe Paperclip::Storage::S3 do
1592
1657
  context "proc permission set" do
1593
1658
  before do
1594
1659
  rebuild_model(
1595
- (aws2_add_region).merge storage: :s3,
1596
- bucket: "testing",
1597
- path: ":attachment/:style/:basename:dotextension",
1598
- styles: {
1599
- thumb: "80x80>"
1600
- },
1601
- s3_credentials: {
1602
- 'access_key_id' => "12345",
1603
- 'secret_access_key' => "54321"
1604
- },
1605
- s3_permissions: lambda {|attachment, style|
1606
- attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : :"public-read"
1607
- }
1660
+ aws2_add_region.merge(storage: :s3,
1661
+ bucket: "testing",
1662
+ path: ":attachment/:style/:basename:dotextension",
1663
+ styles: {
1664
+ thumb: "80x80>"
1665
+ },
1666
+ s3_credentials: {
1667
+ "access_key_id" => "12345",
1668
+ "secret_access_key" => "54321"
1669
+ },
1670
+ s3_permissions: lambda { |attachment, style|
1671
+ attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : :"public-read"
1672
+ })
1608
1673
  )
1609
1674
  end
1610
1675
  end
@@ -1613,27 +1678,27 @@ describe Paperclip::Storage::S3 do
1613
1678
  context "An attachment with S3 storage and metadata set using a proc as headers" do
1614
1679
  before do
1615
1680
  rebuild_model(
1616
- (aws2_add_region).merge storage: :s3,
1617
- bucket: "testing",
1618
- path: ":attachment/:style/:basename:dotextension",
1619
- styles: {
1620
- thumb: "80x80>"
1621
- },
1622
- s3_credentials: {
1623
- 'access_key_id' => "12345",
1624
- 'secret_access_key' => "54321"
1625
- },
1626
- s3_headers: lambda {|attachment|
1627
- {'Content-Disposition' => "attachment; filename=\"#{attachment.name}\""}
1628
- }
1681
+ aws2_add_region.merge(storage: :s3,
1682
+ bucket: "testing",
1683
+ path: ":attachment/:style/:basename:dotextension",
1684
+ styles: {
1685
+ thumb: "80x80>"
1686
+ },
1687
+ s3_credentials: {
1688
+ "access_key_id" => "12345",
1689
+ "secret_access_key" => "54321"
1690
+ },
1691
+ s3_headers: lambda { |attachment|
1692
+ { "Content-Disposition" => "attachment; filename=\"#{attachment.name}\"" }
1693
+ })
1629
1694
  )
1630
1695
  end
1631
1696
 
1632
1697
  context "when assigned" do
1633
1698
  before do
1634
- @file = File.new(fixture_file('5k.png'), 'rb')
1699
+ @file = File.new(fixture_file("5k.png"), "rb")
1635
1700
  @dummy = Dummy.new
1636
- @dummy.stubs(name: 'Custom Avatar Name.png')
1701
+ allow(@dummy).to receive(:name).and_return("Custom Avatar Name.png")
1637
1702
  @dummy.avatar = @file
1638
1703
  end
1639
1704
 
@@ -1642,14 +1707,14 @@ describe Paperclip::Storage::S3 do
1642
1707
  context "and saved" do
1643
1708
  before do
1644
1709
  [:thumb, :original].each do |style|
1645
- object = stub
1646
- @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1647
-
1648
- object.expects(:upload_file)
1649
- .with(anything,
1650
- content_type: "image/png",
1651
- acl: :"public-read",
1652
- content_disposition: 'attachment; filename="Custom Avatar Name.png"')
1710
+ object = double
1711
+ allow(@dummy.avatar).to receive(:s3_object).with(style).and_return(object)
1712
+
1713
+ expect(object).to receive(:upload_file).
1714
+ with(anything,
1715
+ content_type: "image/png",
1716
+ acl: :"public-read",
1717
+ content_disposition: 'attachment; filename="Custom Avatar Name.png"')
1653
1718
  end
1654
1719
  @dummy.save
1655
1720
  end
@@ -1663,27 +1728,28 @@ describe Paperclip::Storage::S3 do
1663
1728
 
1664
1729
  context "path is a proc" do
1665
1730
  before do
1666
- rebuild_model (aws2_add_region).merge storage: :s3,
1667
- path: ->(attachment) { attachment.instance.attachment_path }
1731
+ rebuild_model aws2_add_region.merge storage: :s3,
1732
+ path: ->(attachment) { attachment.instance.attachment_path }
1668
1733
 
1669
1734
  @dummy = Dummy.new
1670
1735
  @dummy.class_eval do
1671
1736
  def attachment_path
1672
- '/some/dynamic/path'
1737
+ "/some/dynamic/path"
1673
1738
  end
1674
1739
  end
1675
1740
  @dummy.avatar = stringy_file
1676
1741
  end
1677
1742
 
1678
1743
  it "returns a correct path" do
1679
- assert_match '/some/dynamic/path', @dummy.avatar.path
1744
+ assert_match "/some/dynamic/path", @dummy.avatar.path
1680
1745
  end
1681
1746
  end
1682
1747
 
1683
1748
  private
1684
1749
 
1685
1750
  def rails_env(env)
1686
- stored_env, Rails.env = Rails.env, env
1751
+ stored_env = Rails.env
1752
+ Rails.env = env
1687
1753
  begin
1688
1754
  yield
1689
1755
  ensure