paperclip 5.0.0.beta1 → 5.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of paperclip might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a699912c4b56d87a1b16846ed1b9772f6149aeeb
4
- data.tar.gz: f975845257fa910032dfc7b52913cd2b17917079
3
+ metadata.gz: f6fccc7d5627358582473c510bef269b25156565
4
+ data.tar.gz: 07eb1f02126bb0022635083684eaf43ba049a466
5
5
  SHA512:
6
- metadata.gz: 46c3a1935badc5820ca134933317f37bd284b2d01ff755b52250f5105e27aa562e3bfb9d20f1aa95c44994b0de477c1feec81d24b53be3e5e9e1852bd45d5448
7
- data.tar.gz: 43b0e540a847140ba445040281be26d23308f9afe204d0bd5911fa6b245cd7cbb079e987460effe2784d94f7019313cbb5fd662fe9c1dc09160bcde9cb28db13
6
+ metadata.gz: 7bf6930cb7bd20a9dd477d1596f9a4ea6ec78108f079424ed4163125f86358275e164667597a6bedec27244435e749dbaf97fbff73a2df724eeb4174ec60ba6c
7
+ data.tar.gz: ee22ab27c69ca3a529ba6b41fcbe6a4f580a16f46b31eae9e1427d13d0bf29bbbe01b65471ebc148c0c21f53213ad39ff2b74f60287b70671d7b676abd2b1d76
data/NEWS CHANGED
@@ -1,4 +1,11 @@
1
- 5.0.0.beta1
1
+ 5.0.0.beta2 (2015-04-01):
2
+
3
+ * Bugfix: Dynamic fog directory option is now respected
4
+ * Bugfix: Fixes cocaine duplicated paths [#2169]
5
+ * Removal of dead code (older versions of Rails and AWS SDK)
6
+ * README adjustments
7
+
8
+ 5.0.0.beta1 (2015-03-13):
2
9
 
3
10
  * Drop support to end-of-life'd ruby 2.0.
4
11
  * Drop support for end-of-life'd Rails 3.2 and 4.1
data/README.md CHANGED
@@ -159,7 +159,7 @@ Paperclip is distributed as a gem, which is how it should be used in your app.
159
159
  Include the gem in your Gemfile:
160
160
 
161
161
  ```ruby
162
- gem "paperclip", "~> 5.0"
162
+ gem "paperclip", "~> 5.0.0.beta1"
163
163
  ```
164
164
 
165
165
  Or, if you want to get the latest, you can get master from the main paperclip repository:
@@ -189,18 +189,6 @@ Quick Start
189
189
 
190
190
  ### Models
191
191
 
192
- **Rails 3**
193
-
194
- ```ruby
195
- class User < ActiveRecord::Base
196
- attr_accessible :avatar
197
- has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
198
- validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
199
- end
200
- ```
201
-
202
- **Rails 4**
203
-
204
192
  ```ruby
205
193
  class User < ActiveRecord::Base
206
194
  has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
@@ -241,16 +229,6 @@ end
241
229
 
242
230
  ### Controller
243
231
 
244
- **Rails 3**
245
-
246
- ```ruby
247
- def create
248
- @user = User.create( params[:user] )
249
- end
250
- ```
251
-
252
- **Rails 4**
253
-
254
232
  ```ruby
255
233
  def create
256
234
  @user = User.create( user_params )
@@ -451,14 +429,13 @@ will not cause errors to be raised.
451
429
 
452
430
  This can sometimes cause false validation errors in applications that use custom
453
431
  file extensions. In these cases you may wish to add your custom extension to the
454
- list of file extensions allowed for your MIME type configured by the `mime-types`
455
- gem:
432
+ list of content type mappings by creating `config/initializers/paperclip.rb`:
456
433
 
457
434
  ```ruby
458
435
  # Allow ".foo" as an extension for files with the MIME type "text/plain".
459
- text_plain = MIME::Types["text/plain"].first
460
- text_plain.extensions << "foo"
461
- MIME::Types.index_extensions text_plain
436
+ Paperclip.options[:content_type_mappings] = {
437
+ foo: %w(text/plain)
438
+ }
462
439
  ```
463
440
 
464
441
  ---
@@ -595,16 +572,13 @@ You may also choose to store your files using Amazon's S3 service. To do so, inc
595
572
  the `aws-sdk` gem in your Gemfile:
596
573
 
597
574
  ```ruby
598
- gem 'aws-sdk', '>= 2.0.0' # If using paperclip `master` (upcoming v5.0)
575
+ gem 'aws-sdk', '>= 2.0.34'
599
576
  ```
600
577
 
601
578
  And then you can specify using S3 from `has_attached_file`.
602
579
  You can find more information about configuring and using S3 storage in
603
580
  [the `Paperclip::Storage::S3` documentation](http://www.rubydoc.info/gems/paperclip/Paperclip/Storage/S3).
604
581
 
605
- _**NOTE**: If upgrading aws-sdk from v1.x to v2.x, be sure to read the
606
- [UPGRADING guide](https://github.com/thoughtbot/paperclip/blob/master/UPGRADING)._
607
-
608
582
  Files on the local filesystem (and in the Rails app's public directory) will be
609
583
  available to the internet at large. If you require access control, it's
610
584
  possible to place your files in a different location. You will need to change
data/UPGRADING CHANGED
@@ -12,3 +12,6 @@ changes:
12
12
  note that the format of the permissions changed from using an underscore to
13
13
  using a hyphen. For example, `:public_read` needs to be changed to
14
14
  `public-read`.
15
+
16
+ For a walkthrough of upgrading from 4 to 5 and aws-sdk >= 2.0 you can watch
17
+ http://rubythursday.com/episodes/ruby-snack-27-upgrade-paperclip-and-aws-sdk-in-prep-for-rails-5
@@ -68,27 +68,3 @@ Feature: Migration
68
68
 
69
69
  When I rollback a migration
70
70
  Then I should not have attachment columns for "avatar"
71
-
72
- Scenario: Rails 3.2 change method
73
- Given I am using Rails newer than 3.1
74
- When I write to "db/migrate/01_create_users.rb" with:
75
- """
76
- class CreateUsers < ActiveRecord::Migration
77
- def self.up
78
- create_table :users
79
- end
80
- end
81
- """
82
- When I write to "db/migrate/02_add_attachment_to_users.rb" with:
83
- """
84
- class AddAttachmentToUsers < ActiveRecord::Migration
85
- def change
86
- add_attachment :users, :avatar
87
- end
88
- end
89
- """
90
- And I run a migration
91
- Then I should have attachment columns for "avatar"
92
-
93
- When I rollback a migration
94
- Then I should not have attachment columns for "avatar"
@@ -190,12 +190,6 @@ When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
190
190
  comment_out_gem_in_gemfile gemname
191
191
  end
192
192
 
193
- Given /^I am using Rails newer than ([\d\.]+)$/ do |version|
194
- if framework_version < version
195
- pending "Not supported in Rails < #{version}"
196
- end
197
- end
198
-
199
193
  Given(/^I add a "(.*?)" processor in "(.*?)"$/) do |processor, directory|
200
194
  filename = "#{directory}/#{processor}.rb"
201
195
  cd(".") do
@@ -1,15 +1,11 @@
1
1
  When /^I attach the file "([^"]*)" to "([^"]*)" on S3$/ do |file_path, field|
2
2
  definition = Paperclip::AttachmentRegistry.definitions_for(User)[field.downcase.to_sym]
3
- path = if defined?(::AWS)
4
- "https://paperclip.s3.amazonaws.com#{definition[:path]}"
5
- else
6
- "https://paperclip.s3-us-west-2.amazonaws.com#{definition[:path]}"
7
- end
3
+ path = "https://paperclip.s3-us-west-2.amazonaws.com#{definition[:path]}"
8
4
  path.gsub!(':filename', File.basename(file_path))
9
5
  path.gsub!(/:([^\/\.]+)/) do |match|
10
6
  "([^\/\.]+)"
11
7
  end
12
- FakeWeb.register_uri(:put, Regexp.new(path), :body => defined?(::AWS) ? "OK" : "<xml></xml>")
8
+ FakeWeb.register_uri(:put, Regexp.new(path), :body => "<xml></xml>")
13
9
  step "I attach the file \"#{file_path}\" to \"#{field}\""
14
10
  end
15
11
 
@@ -24,7 +24,8 @@ module Paperclip
24
24
  #
25
25
  def run(cmd, arguments = "", interpolation_values = {}, local_options = {})
26
26
  command_path = options[:command_path]
27
- Cocaine::CommandLine.path = [Cocaine::CommandLine.path, command_path].flatten.compact.uniq
27
+ cocaine_path_array = Cocaine::CommandLine.path.try(:split, Cocaine::OS.path_separator)
28
+ Cocaine::CommandLine.path = [cocaine_path_array, command_path].flatten.compact.uniq
28
29
  if logging? && (options[:log_command] || local_options[:log_command])
29
30
  local_options = local_options.merge(:logger => logger)
30
31
  end
@@ -12,10 +12,7 @@ module Paperclip
12
12
  ActiveRecord::ConnectionAdapters::Table.send :include, TableDefinition
13
13
  ActiveRecord::ConnectionAdapters::TableDefinition.send :include, TableDefinition
14
14
  ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Statements
15
-
16
- if defined?(ActiveRecord::Migration::CommandRecorder) # Rails 3.1+
17
- ActiveRecord::Migration::CommandRecorder.send :include, CommandRecorder
18
- end
15
+ ActiveRecord::Migration::CommandRecorder.send :include, CommandRecorder
19
16
  end
20
17
 
21
18
  module Statements
@@ -35,8 +32,6 @@ module Paperclip
35
32
  def remove_attachment(table_name, *attachment_names)
36
33
  raise ArgumentError, "Please specify attachment name in your remove_attachment call in your migration." if attachment_names.empty?
37
34
 
38
- options = attachment_names.extract_options!
39
-
40
35
  attachment_names.each do |attachment_name|
41
36
  COLUMNS.keys.each do |column_name|
42
37
  remove_column(table_name, "#{attachment_name}_#{column_name}")
@@ -195,10 +195,10 @@ module Paperclip
195
195
  end
196
196
 
197
197
  def host_name_for_directory
198
- if @options[:fog_directory].to_s =~ Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX
199
- "#{@options[:fog_directory]}.s3.amazonaws.com"
198
+ if directory_name.to_s =~ Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX
199
+ "#{directory_name}.s3.amazonaws.com"
200
200
  else
201
- "s3.amazonaws.com/#{@options[:fog_directory]}"
201
+ "s3.amazonaws.com/#{directory_name}"
202
202
  end
203
203
  end
204
204
 
@@ -224,13 +224,15 @@ module Paperclip
224
224
  end
225
225
 
226
226
  def directory
227
- dir = if @options[:fog_directory].respond_to?(:call)
227
+ @directory ||= connection.directories.new(key: directory_name)
228
+ end
229
+
230
+ def directory_name
231
+ if @options[:fog_directory].respond_to?(:call)
228
232
  @options[:fog_directory].call(self)
229
233
  else
230
234
  @options[:fog_directory]
231
235
  end
232
-
233
- @directory ||= connection.directories.new(:key => dir)
234
236
  end
235
237
 
236
238
  def scheme
@@ -113,37 +113,15 @@ module Paperclip
113
113
 
114
114
  module S3
115
115
  def self.extended base
116
- unless defined?(AWS_CLASS)
117
- begin
118
- require 'aws-sdk'
119
- const_set('AWS_CLASS', defined?(::Aws) ? ::Aws : ::AWS)
120
- const_set('AWS_BASE_ERROR',
121
- defined?(::Aws) ? Aws::Errors::ServiceError : AWS::Errors::Base)
122
- const_set('DEFAULT_PERMISSION',
123
- defined?(::AWS) ? :public_read : :'public-read')
124
-
125
- rescue LoadError => e
126
- e.message << " (You may need to install the aws-sdk gem)"
127
- raise e
128
- end
129
- if Gem::Version.new(AWS_CLASS::VERSION) >= Gem::Version.new(2) && Gem::Version.new(AWS_CLASS::VERSION) <= Gem::Version.new("2.0.33")
130
- raise LoadError, "paperclip does not support aws-sdk versions 2.0.0 - 2.0.33. Please upgrade aws-sdk to a newer version."
131
- end
116
+ begin
117
+ require 'aws-sdk'
118
+ rescue LoadError => e
119
+ e.message << " (You may need to install the aws-sdk gem)"
120
+ raise e
132
121
  end
133
-
134
- # Overriding log formatter to make sure it return a UTF-8 string
135
- if defined?(AWS_CLASS::Core::LogFormatter)
136
- AWS_CLASS::Core::LogFormatter.class_eval do
137
- def summarize_hash(hash)
138
- hash.map { |key, value| ":#{key}=>#{summarize_value(value)}".force_encoding('UTF-8') }.sort.join(',')
139
- end
140
- end
141
- elsif defined?(AWS_CLASS::Core::ClientLogging)
142
- AWS_CLASS::Core::ClientLogging.class_eval do
143
- def sanitize_hash(hash)
144
- hash.map { |key, value| "#{sanitize_value(key)}=>#{sanitize_value(value)}".force_encoding('UTF-8') }.sort.join(',')
145
- end
146
- end
122
+ if Gem::Version.new(Aws::VERSION) >= Gem::Version.new(2) &&
123
+ Gem::Version.new(Aws::VERSION) <= Gem::Version.new("2.0.33")
124
+ raise LoadError, "paperclip does not support aws-sdk versions 2.0.0 - 2.0.33. Please upgrade aws-sdk to a newer version."
147
125
  end
148
126
 
149
127
  base.instance_eval do
@@ -153,7 +131,7 @@ module Paperclip
153
131
  Proc.new do |style, attachment|
154
132
  permission = (@s3_permissions[style.to_s.to_sym] || @s3_permissions[:default])
155
133
  permission = permission.call(attachment, style) if permission.respond_to?(:call)
156
- (permission == DEFAULT_PERMISSION) ? 'http'.freeze : 'https'.freeze
134
+ (permission == :"public-read") ? 'http'.freeze : 'https'.freeze
157
135
  end
158
136
  @s3_metadata = @options[:s3_metadata] || {}
159
137
  @s3_headers = {}
@@ -266,7 +244,7 @@ module Paperclip
266
244
 
267
245
  def obtain_s3_instance_for(options)
268
246
  instances = (Thread.current[:paperclip_s3_instances] ||= {})
269
- instances[options] ||= AWS_CLASS::S3::Resource.new(options)
247
+ instances[options] ||= ::Aws::S3::Resource.new(options)
270
248
  end
271
249
 
272
250
  def s3_bucket
@@ -303,7 +281,7 @@ module Paperclip
303
281
 
304
282
  def set_permissions permissions
305
283
  permissions = { :default => permissions } unless permissions.respond_to?(:merge)
306
- permissions.merge :default => (permissions[:default] || DEFAULT_PERMISSION)
284
+ permissions.merge :default => (permissions[:default] || :"public-read")
307
285
  end
308
286
 
309
287
  def set_storage_class(storage_class)
@@ -323,7 +301,7 @@ module Paperclip
323
301
  else
324
302
  false
325
303
  end
326
- rescue AWS_BASE_ERROR => e
304
+ rescue Aws::Errors::ServiceError => e
327
305
  false
328
306
  end
329
307
 
@@ -381,10 +359,10 @@ module Paperclip
381
359
  write_options.merge!(@s3_headers)
382
360
 
383
361
  s3_object(style).upload_file(file.path, write_options)
384
- rescue AWS_CLASS::S3::Errors::NoSuchBucket
362
+ rescue ::Aws::S3::Errors::NoSuchBucket
385
363
  create_bucket
386
364
  retry
387
- rescue AWS_CLASS::S3::Errors::SlowDown
365
+ rescue ::Aws::S3::Errors::SlowDown
388
366
  retries += 1
389
367
  if retries <= 5
390
368
  sleep((2 ** retries) * 0.5)
@@ -407,7 +385,7 @@ module Paperclip
407
385
  begin
408
386
  log("deleting #{path}")
409
387
  s3_bucket.object(path.sub(%r{\A/}, "")).delete
410
- rescue AWS_BASE_ERROR => e
388
+ rescue Aws::Errors::ServiceError => e
411
389
  # Ignore this.
412
390
  end
413
391
  end
@@ -421,7 +399,7 @@ module Paperclip
421
399
  local_file.write(chunk)
422
400
  end
423
401
  end
424
- rescue AWS_BASE_ERROR => e
402
+ rescue Aws::Errors::ServiceError => e
425
403
  warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}")
426
404
  false
427
405
  end
@@ -71,13 +71,7 @@ module Paperclip
71
71
  end
72
72
 
73
73
  def human_size(size)
74
- if defined?(ActiveSupport::NumberHelper) # Rails 4.0+
75
- ActiveSupport::NumberHelper.number_to_human_size(size)
76
- else
77
- storage_units_format = I18n.translate(:'number.human.storage_units.format', :locale => options[:locale], :raise => true)
78
- unit = I18n.translate(:'number.human.storage_units.units.byte', :locale => options[:locale], :count => size.to_i, :raise => true)
79
- storage_units_format.gsub(/%n/, size.to_i.to_s).gsub(/%u/, unit).html_safe
80
- end
74
+ ActiveSupport::NumberHelper.number_to_human_size(size)
81
75
  end
82
76
 
83
77
  def min_value_in_human_size(record)
@@ -1,3 +1,3 @@
1
1
  module Paperclip
2
- VERSION = "5.0.0.beta1" unless defined? Paperclip::VERSION
2
+ VERSION = "5.0.0.beta2" unless defined? Paperclip::VERSION
3
3
  end
data/paperclip.gemspec CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
35
35
  s.add_development_dependency('rspec', '~> 3.0')
36
36
  s.add_development_dependency('appraisal')
37
37
  s.add_development_dependency('mocha')
38
- s.add_development_dependency('aws-sdk', '>= 2.0.33', '< 3.0')
38
+ s.add_development_dependency('aws-sdk', '>= 2.0.34', '< 3.0')
39
39
  s.add_development_dependency('bourne')
40
40
  s.add_development_dependency('cucumber', '~> 1.3.18')
41
41
  s.add_development_dependency('aruba', '~> 0.9.0')
@@ -222,9 +222,6 @@ describe Paperclip::Attachment do
222
222
  dummy.avatar_file_name = "fake.jpg"
223
223
  dummy.stubs(:new_record?).returns(false)
224
224
  expected_string = '{"avatar":"/system/dummies/avatars/000/001/234/original/fake.jpg"}'
225
- if ActiveRecord::Base.include_root_in_json # This is true by default in Rails 3, and false in 4
226
- expected_string = %({"dummy":#{expected_string}})
227
- end
228
225
  # active_model pre-3.2 checks only by calling any? on it, thus it doesn't work if it is empty
229
226
  assert_equal expected_string, dummy.to_json(only: [:dummy_key_for_old_active_model], methods: [:avatar])
230
227
  end
@@ -29,7 +29,9 @@ describe Paperclip do
29
29
  Paperclip.options[:command_path] = "/opt/my_app/bin"
30
30
  Paperclip.run("convert", "stuff")
31
31
  Paperclip.run("convert", "more_stuff")
32
- assert_equal 1, [Cocaine::CommandLine.path].flatten.size
32
+
33
+ cmd_path = Paperclip.options[:command_path]
34
+ assert_equal 1, Cocaine::CommandLine.path.scan(cmd_path).count
33
35
  end
34
36
  end
35
37
 
@@ -418,6 +418,9 @@ describe Paperclip::Storage::Fog do
418
418
  assert @connection.directories.get(@dynamic_fog_directory).inspect
419
419
  end
420
420
 
421
+ it "provides an url using dynamic bucket name" do
422
+ assert_match(/^https:\/\/dynamicpaperclip.s3.amazonaws.com\/avatars\/5k.png\?\d*$/, @dummy.avatar.url)
423
+ end
421
424
  end
422
425
 
423
426
  context "with a proc for the fog_host evaluating a model method" do
@@ -3,15 +3,11 @@ require 'aws-sdk'
3
3
 
4
4
  describe Paperclip::Storage::S3 do
5
5
  before do
6
- if defined?(::Aws)
7
- Aws.config[:stub_responses] = true
8
- else
9
- AWS.stub!
10
- end
6
+ Aws.config[:stub_responses] = true
11
7
  end
12
8
 
13
9
  def aws2_add_region
14
- defined?(::Aws) ? { s3_region: 'us-east-1' } : {}
10
+ { s3_region: 'us-east-1' }
15
11
  end
16
12
 
17
13
  context "Parsing S3 credentials" do
@@ -244,20 +240,12 @@ describe Paperclip::Storage::S3 do
244
240
  # if using aws-sdk-v2, the s3_host_name will be defined by the s3_region
245
241
  context "s3_host_name" do
246
242
  before do
247
- if defined?(::Aws)
248
- rebuild_model storage: :s3,
249
- s3_credentials: {},
250
- bucket: "bucket",
251
- path: ":attachment/:basename:dotextension",
252
- s3_host_name: "s3-ap-northeast-1.amazonaws.com",
253
- s3_region: "ap-northeast-1"
254
- else
255
- rebuild_model storage: :s3,
256
- s3_credentials: {},
257
- bucket: "bucket",
258
- path: ":attachment/:basename:dotextension",
259
- s3_host_name: "s3-ap-northeast-1.amazonaws.com"
260
- end
243
+ 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"
261
249
  @dummy = Dummy.new
262
250
  @dummy.avatar = stringy_file
263
251
  @dummy.stubs(:new_record?).returns(false)
@@ -269,9 +257,7 @@ describe Paperclip::Storage::S3 do
269
257
 
270
258
  it "uses the S3 bucket with the correct host name" do
271
259
  assert_equal "s3-ap-northeast-1.amazonaws.com",
272
- (defined?(::Aws) ?
273
- @dummy.avatar.s3_bucket.client.config.endpoint.host :
274
- @dummy.avatar.s3_bucket.config.s3_endpoint)
260
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
275
261
  end
276
262
  end
277
263
 
@@ -361,13 +347,12 @@ describe Paperclip::Storage::S3 do
361
347
  @dummy.avatar.stubs(:s3_object).with(:original).returns(object)
362
348
  @dummy.avatar.stubs(:s3_object).with(:thumbnail).returns(object)
363
349
 
364
- object.expects((defined?(::Aws) ? :upload_file : :write))
350
+ object.expects(:upload_file)
365
351
  .with(anything, content_type: 'image/png',
366
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION)
367
-
368
- object.expects((defined?(::Aws) ? :upload_file : :write))
352
+ acl: :"public-read")
353
+ object.expects(:upload_file)
369
354
  .with(anything, content_type: 'image/png',
370
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
355
+ acl: :"public-read",
371
356
  cache_control: 'max-age=31557600')
372
357
  @dummy.save
373
358
  end
@@ -554,11 +539,7 @@ describe Paperclip::Storage::S3 do
554
539
  object = stub
555
540
  @dummy.avatar.stubs(:s3_object).returns(object)
556
541
 
557
- if defined?(::Aws)
558
- object.expects(:presigned_url).with(:get, expires_in: 3600)
559
- else
560
- object.expects(:url_for).with(:read, expires: 3600, secure: true)
561
- end
542
+ object.expects(:presigned_url).with(:get, expires_in: 3600)
562
543
  @dummy.avatar.expiring_url
563
544
  end
564
545
  end
@@ -572,15 +553,9 @@ describe Paperclip::Storage::S3 do
572
553
 
573
554
  object = stub
574
555
  @dummy.avatar.stubs(:s3_object).returns(object)
575
- if defined?(::Aws)
576
- object.expects(:presigned_url)
577
- .with(:get, expires_in: 3600,
578
- response_content_disposition: "inline")
579
- else
580
- object.expects(:url_for)
581
- .with(:read, expires: 3600, secure: true,
582
- response_content_disposition: "inline")
583
- end
556
+ object.expects(:presigned_url)
557
+ .with(:get, expires_in: 3600,
558
+ response_content_disposition: "inline")
584
559
  @dummy.avatar.expiring_url
585
560
  end
586
561
  end
@@ -601,14 +576,8 @@ describe Paperclip::Storage::S3 do
601
576
 
602
577
  object = stub
603
578
  @dummy.avatar.stubs(:s3_object).returns(object)
604
- if defined?(::Aws)
605
- object.expects(:presigned_url)
606
- .with(:get, expires_in: 3600, response_content_type: "image/png")
607
- else
608
- object.expects(:url_for)
609
- .with(:read, expires: 3600, secure: true,
610
- response_content_type: "image/png")
611
- end
579
+ object.expects(:presigned_url)
580
+ .with(:get, expires_in: 3600, response_content_type: "image/png")
612
581
  @dummy.avatar.expiring_url
613
582
  end
614
583
  end
@@ -655,22 +624,14 @@ describe Paperclip::Storage::S3 do
655
624
  it "generates a url for the thumb" do
656
625
  object = stub
657
626
  @dummy.avatar.stubs(:s3_object).with(:thumb).returns(object)
658
- if defined?(::Aws)
659
- object.expects(:presigned_url).with(:get, expires_in: 1800)
660
- else
661
- object.expects(:url_for).with(:read, expires: 1800, secure: true)
662
- end
627
+ object.expects(:presigned_url).with(:get, expires_in: 1800)
663
628
  @dummy.avatar.expiring_url(1800, :thumb)
664
629
  end
665
630
 
666
631
  it "generates a url for the default style" do
667
632
  object = stub
668
633
  @dummy.avatar.stubs(:s3_object).with(:original).returns(object)
669
- if defined?(::Aws)
670
- object.expects(:presigned_url).with(:get, expires_in: 1800)
671
- else
672
- object.expects(:url_for).with(:read, expires: 1800, secure: true)
673
- end
634
+ object.expects(:presigned_url).with(:get, expires_in: 1800)
674
635
  @dummy.avatar.expiring_url(1800)
675
636
  end
676
637
  end
@@ -703,65 +664,40 @@ describe Paperclip::Storage::S3 do
703
664
  # for aws-sdk-v2 the bucket.name is determined by the :s3_region
704
665
  context "Parsing S3 credentials with a s3_host_name in them" do
705
666
  before do
706
- if defined?(::Aws)
707
- rebuild_model storage: :s3,
708
- bucket: 'testing',
709
- s3_credentials: {
710
- production: {
711
- s3_region: "world-end",
712
- s3_host_name: "s3-world-end.amazonaws.com" },
713
- development: {
714
- s3_region: "ap-northeast-1",
715
- s3_host_name: "s3-ap-northeast-1.amazonaws.com" }
716
- }
717
- else
718
- rebuild_model storage: :s3,
719
- bucket: 'testing',
720
- s3_credentials: {
721
- production: { s3_host_name: "s3-world-end.amazonaws.com" },
722
- development: { s3_host_name: "s3-ap-northeast-1.amazonaws.com" }
723
- }
724
- end
667
+ rebuild_model storage: :s3,
668
+ bucket: 'testing',
669
+ s3_credentials: {
670
+ production: {
671
+ s3_region: "world-end",
672
+ s3_host_name: "s3-world-end.amazonaws.com" },
673
+ development: {
674
+ s3_region: "ap-northeast-1",
675
+ s3_host_name: "s3-ap-northeast-1.amazonaws.com" }
676
+ }
725
677
  @dummy = Dummy.new
726
678
  end
727
679
 
728
680
  it "gets the right s3_host_name in production" do
729
681
  rails_env("production") do
730
682
  assert_match %r{^s3-world-end.amazonaws.com}, @dummy.avatar.s3_host_name
731
- if defined?(::Aws)
732
- assert_match %r{^s3.world-end.amazonaws.com},
733
- @dummy.avatar.s3_bucket.client.config.endpoint.host
734
- else
735
- assert_match %r{^s3-world-end.amazonaws.com},
736
- @dummy.avatar.s3_bucket.config.s3_endpoint
737
- end
683
+ assert_match %r{^s3.world-end.amazonaws.com},
684
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
738
685
  end
739
686
  end
740
687
 
741
688
  it "gets the right s3_host_name in development" do
742
689
  rails_env("development") do
743
690
  assert_match %r{^s3-ap-northeast-1.amazonaws.com}, @dummy.avatar.s3_host_name
744
- if defined?(::Aws)
745
- assert_match %r{^s3-ap-northeast-1.amazonaws.com},
746
- @dummy.avatar.s3_bucket.client.config.endpoint.host
747
- else
748
- assert_match %r{^s3-ap-northeast-1.amazonaws.com},
749
- @dummy.avatar.s3_bucket.config.s3_endpoint
750
- end
691
+ assert_match %r{^s3-ap-northeast-1.amazonaws.com},
692
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
751
693
  end
752
694
  end
753
695
 
754
696
  it "gets the right s3_host_name if the key does not exist" do
755
697
  rails_env("test") do
756
698
  assert_match %r{^s3.amazonaws.com}, @dummy.avatar.s3_host_name
757
- if defined?(::Aws)
758
- # :s3_region is *required* for aws-sdk-v2
759
- assert_raises(Aws::Errors::MissingRegionError) do
760
- @dummy.avatar.s3_bucket.client.config.endpoint.host
761
- end
762
- else
763
- assert_match %r{^s3.amazonaws.com},
764
- @dummy.avatar.s3_bucket.config.s3_endpoint
699
+ assert_raises(Aws::Errors::MissingRegionError) do
700
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
765
701
  end
766
702
  end
767
703
  end
@@ -804,22 +740,14 @@ describe Paperclip::Storage::S3 do
804
740
 
805
741
  it "is rewound after flush_writes" do
806
742
  @dummy.avatar.instance_eval "def after_flush_writes; end"
807
- if defined?(::Aws)
808
- @dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
809
- else
810
- @dummy.avatar.stubs(:s3_object).returns(stub(write: true))
811
- end
743
+ @dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
812
744
  files = @dummy.avatar.queued_for_write.values.each(&:read)
813
745
  @dummy.save
814
746
  assert files.none?(&:eof?), "Expect all the files to be rewound."
815
747
  end
816
748
 
817
749
  it "is removed after after_flush_writes" do
818
- if defined?(::Aws)
819
- @dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
820
- else
821
- @dummy.avatar.stubs(:s3_object).returns(stub(write: true))
822
- end
750
+ @dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
823
751
  paths = @dummy.avatar.queued_for_write.values.map(&:path)
824
752
  @dummy.save
825
753
  assert paths.none?{ |path| File.exist?(path) },
@@ -828,17 +756,10 @@ describe Paperclip::Storage::S3 do
828
756
 
829
757
  it "will retry to save again but back off on SlowDown" do
830
758
  @dummy.avatar.stubs(:sleep)
831
- if defined?(::Aws)
832
- Aws::S3::Object.any_instance.stubs(:upload_file).
833
- raises(Aws::S3::Errors::SlowDown.new(stub,
834
- stub(status: 503, body: "")))
835
- expect {@dummy.save}.to raise_error(Aws::S3::Errors::SlowDown)
836
- else
837
- AWS::S3::S3Object.any_instance.stubs(:write).
838
- raises(AWS::S3::Errors::SlowDown.new(stub,
839
- stub(status: 503, body: "")))
840
- expect {@dummy.save}.to raise_error(AWS::S3::Errors::SlowDown)
841
- end
759
+ Aws::S3::Object.any_instance.stubs(:upload_file).
760
+ raises(Aws::S3::Errors::SlowDown.new(stub,
761
+ stub(status: 503, body: "")))
762
+ expect {@dummy.save}.to raise_error(Aws::S3::Errors::SlowDown)
842
763
  expect(@dummy.avatar).to have_received(:sleep).with(1)
843
764
  expect(@dummy.avatar).to have_received(:sleep).with(2)
844
765
  expect(@dummy.avatar).to have_received(:sleep).with(4)
@@ -850,9 +771,8 @@ describe Paperclip::Storage::S3 do
850
771
  before do
851
772
  object = stub
852
773
  @dummy.avatar.stubs(:s3_object).returns(object)
853
- object.expects((defined?(::Aws) ? :upload_file : :write))
854
- .with(anything, content_type: 'image/png',
855
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION)
774
+ object.expects(:upload_file)
775
+ .with(anything, content_type: 'image/png', acl: :"public-read")
856
776
  @dummy.save
857
777
  end
858
778
 
@@ -863,21 +783,11 @@ describe Paperclip::Storage::S3 do
863
783
 
864
784
  context "and saved without a bucket" do
865
785
  before do
866
- if defined?(::Aws)
867
- Aws::S3::Bucket.any_instance.expects(:create)
868
- Aws::S3::Object.any_instance.stubs(:upload_file).
869
- raises(Aws::S3::Errors::NoSuchBucket
870
- .new(stub,
871
- stub(status: 404, body: "<foo/>"))).then.returns(nil)
872
- else
873
- AWS::S3::BucketCollection.any_instance.expects(:create)
874
- .with("testing")
875
- AWS::S3::S3Object.any_instance.stubs(:write).
876
- raises(AWS::S3::Errors::NoSuchBucket.new(stub,
877
- stub(status: 404,
878
- body: "<foo/>"))).
879
- then.returns(nil)
880
- end
786
+ Aws::S3::Bucket.any_instance.expects(:create)
787
+ Aws::S3::Object.any_instance.stubs(:upload_file).
788
+ raises(Aws::S3::Errors::NoSuchBucket
789
+ .new(stub,
790
+ stub(status: 404, body: "<foo/>"))).then.returns(nil)
881
791
  @dummy.save
882
792
  end
883
793
 
@@ -888,13 +798,8 @@ describe Paperclip::Storage::S3 do
888
798
 
889
799
  context "and remove" do
890
800
  before do
891
- if defined?(::Aws)
892
- Aws::S3::Object.any_instance.stubs(:exists?).returns(true)
893
- Aws::S3::Object.any_instance.stubs(:delete)
894
- else
895
- AWS::S3::S3Object.any_instance.stubs(:exists?).returns(true)
896
- AWS::S3::S3Object.any_instance.stubs(:delete)
897
- end
801
+ Aws::S3::Object.any_instance.stubs(:exists?).returns(true)
802
+ Aws::S3::Object.any_instance.stubs(:delete)
898
803
  @dummy.destroy
899
804
  end
900
805
 
@@ -905,14 +810,9 @@ describe Paperclip::Storage::S3 do
905
810
 
906
811
  context 'that the file were missing' do
907
812
  before do
908
- if defined?(::Aws)
909
- Aws::S3::Object.any_instance.stubs(:exists?)
910
- .raises(Aws::S3::Errors::ServiceError.new("rspec stub raises",
911
- "object exists?"))
912
- else
913
- AWS::S3::S3Object.any_instance.stubs(:exists?)
914
- .raises(AWS::Errors::Base)
915
- end
813
+ Aws::S3::Object.any_instance.stubs(:exists?)
814
+ .raises(Aws::S3::Errors::ServiceError.new("rspec stub raises",
815
+ "object exists?"))
916
816
  end
917
817
 
918
818
  it 'returns false on exists?' do
@@ -956,28 +856,16 @@ describe Paperclip::Storage::S3 do
956
856
  before do
957
857
  class DummyCredentialProvider; end
958
858
 
959
- if defined?(::Aws)
960
- rebuild_model (aws2_add_region).merge storage: :s3,
961
- bucket: "testing",
962
- s3_credentials: {
963
- credentials: DummyCredentialProvider.new
964
- }
965
- else
966
- rebuild_model storage: :s3,
967
- bucket: "testing",
968
- s3_credentials: {
969
- credential_provider: DummyCredentialProvider.new
970
- }
971
- end
859
+ rebuild_model (aws2_add_region).merge storage: :s3,
860
+ bucket: "testing",
861
+ s3_credentials: {
862
+ credentials: DummyCredentialProvider.new
863
+ }
972
864
  @dummy = Dummy.new
973
865
  end
974
866
 
975
867
  it "sets the credential-provider" do
976
- if defined?(::Aws)
977
- expect(@dummy.avatar.s3_bucket.client.config.credentials).to be_a DummyCredentialProvider
978
- else
979
- expect(@dummy.avatar.s3_bucket.config.credential_provider).to be_a DummyCredentialProvider
980
- end
868
+ expect(@dummy.avatar.s3_bucket.client.config.credentials).to be_a DummyCredentialProvider
981
869
  end
982
870
  end
983
871
 
@@ -1032,10 +920,10 @@ describe Paperclip::Storage::S3 do
1032
920
  object = stub
1033
921
  @dummy.avatar.stubs(:s3_object).returns(object)
1034
922
 
1035
- object.expects((defined?(::Aws) ? :upload_file : :write))
923
+ object.expects(:upload_file)
1036
924
  .with(anything,
1037
925
  content_type: 'image/png',
1038
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
926
+ acl: :"public-read",
1039
927
  cache_control: 'max-age=31557600')
1040
928
  @dummy.save
1041
929
  end
@@ -1073,10 +961,10 @@ describe Paperclip::Storage::S3 do
1073
961
  object = stub
1074
962
  @dummy.avatar.stubs(:s3_object).returns(object)
1075
963
 
1076
- object.expects((defined?(::Aws) ? :upload_file : :write))
964
+ object.expects(:upload_file)
1077
965
  .with(anything,
1078
966
  content_type: 'image/png',
1079
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
967
+ acl: :"public-read",
1080
968
  metadata: { "color" => "red" })
1081
969
  @dummy.save
1082
970
  end
@@ -1114,10 +1002,10 @@ describe Paperclip::Storage::S3 do
1114
1002
  object = stub
1115
1003
  @dummy.avatar.stubs(:s3_object).returns(object)
1116
1004
 
1117
- object.expects((defined?(::Aws) ? :upload_file : :write))
1005
+ object.expects(:upload_file)
1118
1006
  .with(anything,
1119
1007
  content_type: 'image/png',
1120
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1008
+ acl: :"public-read",
1121
1009
  metadata: { "color" => "red" })
1122
1010
  @dummy.save
1123
1011
  end
@@ -1156,10 +1044,10 @@ describe Paperclip::Storage::S3 do
1156
1044
  object = stub
1157
1045
  @dummy.avatar.stubs(:s3_object).returns(object)
1158
1046
 
1159
- object.expects((defined?(::Aws) ? :upload_file : :write))
1047
+ object.expects(:upload_file)
1160
1048
  .with(anything,
1161
1049
  content_type: 'image/png',
1162
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1050
+ acl: :"public-read",
1163
1051
  storage_class: "reduced_redundancy")
1164
1052
  @dummy.save
1165
1053
  end
@@ -1205,11 +1093,11 @@ describe Paperclip::Storage::S3 do
1205
1093
 
1206
1094
  expected_options = {
1207
1095
  :content_type => "image/png",
1208
- :acl => Paperclip::Storage::S3::DEFAULT_PERMISSION
1096
+ acl: :"public-read"
1209
1097
  }
1210
1098
  expected_options.merge!(:storage_class => :reduced_redundancy) if style == :thumb
1211
1099
 
1212
- object.expects((defined?(::Aws) ? :upload_file : :write))
1100
+ object.expects(:upload_file)
1213
1101
  .with(anything, expected_options)
1214
1102
  end
1215
1103
  @dummy.save
@@ -1252,9 +1140,9 @@ describe Paperclip::Storage::S3 do
1252
1140
  [:thumb, :original].each do |style|
1253
1141
  @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1254
1142
 
1255
- object.expects((defined?(::Aws) ? :upload_file : :write))
1143
+ object.expects(:upload_file)
1256
1144
  .with(anything, :content_type => "image/png",
1257
- :acl => Paperclip::Storage::S3::DEFAULT_PERMISSION,
1145
+ acl: :"public-read",
1258
1146
  :storage_class => :reduced_redundancy)
1259
1147
  end
1260
1148
  @dummy.save
@@ -1295,9 +1183,8 @@ describe Paperclip::Storage::S3 do
1295
1183
  object = stub
1296
1184
  @dummy.avatar.stubs(:s3_object).returns(object)
1297
1185
 
1298
- object.expects((defined?(::Aws) ? :upload_file : :write))
1299
- .with(anything, :content_type => "image/png",
1300
- :acl => Paperclip::Storage::S3::DEFAULT_PERMISSION)
1186
+ object.expects(:upload_file)
1187
+ .with(anything, :content_type => "image/png", acl: :"public-read")
1301
1188
  @dummy.save
1302
1189
  end
1303
1190
 
@@ -1335,9 +1222,9 @@ describe Paperclip::Storage::S3 do
1335
1222
  object = stub
1336
1223
  @dummy.avatar.stubs(:s3_object).returns(object)
1337
1224
 
1338
- object.expects((defined?(::Aws) ? :upload_file : :write))
1225
+ object.expects(:upload_file)
1339
1226
  .with(anything, content_type: "image/png",
1340
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1227
+ acl: :"public-read",
1341
1228
  server_side_encryption: :aes256)
1342
1229
  @dummy.save
1343
1230
  end
@@ -1375,10 +1262,10 @@ describe Paperclip::Storage::S3 do
1375
1262
  object = stub
1376
1263
  @dummy.avatar.stubs(:s3_object).returns(object)
1377
1264
 
1378
- object.expects((defined?(::Aws) ? :upload_file : :write))
1265
+ object.expects(:upload_file)
1379
1266
  .with(anything,
1380
1267
  content_type: "image/png",
1381
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1268
+ acl: :"public-read",
1382
1269
  storage_class: :reduced_redundancy)
1383
1270
  @dummy.save
1384
1271
  end
@@ -1409,14 +1296,10 @@ describe Paperclip::Storage::S3 do
1409
1296
  assert_equal 'pathname_bucket', @dummy.avatar.bucket_name
1410
1297
 
1411
1298
  assert_equal 'pathname_key',
1412
- (defined?(::Aws) ?
1413
- @dummy.avatar.s3_bucket.client.config.access_key_id :
1414
- @dummy.avatar.s3_bucket.config.access_key_id)
1299
+ @dummy.avatar.s3_bucket.client.config.access_key_id
1415
1300
 
1416
1301
  assert_equal 'pathname_secret',
1417
- (defined?(::Aws) ?
1418
- @dummy.avatar.s3_bucket.client.config.secret_access_key :
1419
- @dummy.avatar.s3_bucket.config.secret_access_key)
1302
+ @dummy.avatar.s3_bucket.client.config.secret_access_key
1420
1303
  end
1421
1304
  end
1422
1305
 
@@ -1440,14 +1323,10 @@ describe Paperclip::Storage::S3 do
1440
1323
  assert_equal 'env_bucket', @dummy.avatar.bucket_name
1441
1324
 
1442
1325
  assert_equal 'env_key',
1443
- (defined?(::Aws) ?
1444
- @dummy.avatar.s3_bucket.client.config.access_key_id :
1445
- @dummy.avatar.s3_bucket.config.access_key_id)
1326
+ @dummy.avatar.s3_bucket.client.config.access_key_id
1446
1327
 
1447
1328
  assert_equal 'env_secret',
1448
- (defined?(::Aws) ?
1449
- @dummy.avatar.s3_bucket.client.config.secret_access_key :
1450
- @dummy.avatar.s3_bucket.config.secret_access_key)
1329
+ @dummy.avatar.s3_bucket.client.config.secret_access_key
1451
1330
  end
1452
1331
  end
1453
1332
 
@@ -1477,10 +1356,8 @@ describe Paperclip::Storage::S3 do
1477
1356
  object = stub
1478
1357
  @dummy.avatar.stubs(:s3_object).returns(object)
1479
1358
 
1480
- object.expects((defined?(::Aws) ? :upload_file : :write))
1481
- .with(anything,
1482
- content_type: "image/png",
1483
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION)
1359
+ object.expects(:upload_file)
1360
+ .with(anything, content_type: "image/png", acl: :"public-read")
1484
1361
  @dummy.save
1485
1362
  end
1486
1363
 
@@ -1517,7 +1394,7 @@ describe Paperclip::Storage::S3 do
1517
1394
  object = stub
1518
1395
  @dummy.avatar.stubs(:s3_object).returns(object)
1519
1396
 
1520
- object.expects((defined?(::Aws) ? :upload_file : :write))
1397
+ object.expects(:upload_file)
1521
1398
  .with(anything, content_type: "image/png", acl: :private)
1522
1399
  @dummy.save
1523
1400
  end
@@ -1562,7 +1439,7 @@ describe Paperclip::Storage::S3 do
1562
1439
  object = stub
1563
1440
  @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1564
1441
 
1565
- object.expects((defined?(::Aws) ? :upload_file : :write))
1442
+ object.expects(:upload_file)
1566
1443
  .with(anything,
1567
1444
  content_type: "image/png",
1568
1445
  acl: style == :thumb ? :public_read : :private)
@@ -1591,7 +1468,7 @@ describe Paperclip::Storage::S3 do
1591
1468
  'secret_access_key' => "54321"
1592
1469
  },
1593
1470
  s3_permissions: lambda {|attachment, style|
1594
- attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : Paperclip::Storage::S3::DEFAULT_PERMISSION
1471
+ attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : :"public-read"
1595
1472
  }
1596
1473
  )
1597
1474
  end
@@ -1656,10 +1533,10 @@ describe Paperclip::Storage::S3 do
1656
1533
  object = stub
1657
1534
  @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1658
1535
 
1659
- object.expects((defined?(::Aws) ? :upload_file : :write))
1536
+ object.expects(:upload_file)
1660
1537
  .with(anything,
1661
1538
  content_type: "image/png",
1662
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1539
+ acl: :"public-read",
1663
1540
  content_disposition: 'attachment; filename="Custom Avatar Name.png"')
1664
1541
  end
1665
1542
  @dummy.save
@@ -1691,7 +1568,6 @@ describe Paperclip::Storage::S3 do
1691
1568
  end
1692
1569
  end
1693
1570
 
1694
-
1695
1571
  private
1696
1572
 
1697
1573
  def rails_env(env)
@@ -12,14 +12,6 @@ describe Paperclip::Validators::AttachmentSizeValidator do
12
12
  ))
13
13
  end
14
14
 
15
- def self.storage_units
16
- if defined?(ActiveSupport::NumberHelper) # Rails 4.0+
17
- { 5120 => '5 KB', 10240 => '10 KB' }
18
- else
19
- { 5120 => '5120 Bytes', 10240 => '10240 Bytes' }
20
- end
21
- end
22
-
23
15
  def self.should_allow_attachment_file_size(size)
24
16
  context "when the attachment size is #{size}" do
25
17
  it "adds error to dummy object" do
@@ -158,8 +150,10 @@ describe Paperclip::Validators::AttachmentSizeValidator do
158
150
  message: "is invalid. (Between %{min} and %{max} please.)"
159
151
  end
160
152
 
161
- should_not_allow_attachment_file_size 11.kilobytes,
162
- message: "is invalid. (Between #{storage_units[5120]} and #{storage_units[10240]} please.)"
153
+ should_not_allow_attachment_file_size(
154
+ 11.kilobytes,
155
+ message: "is invalid. (Between 5 KB and 10 KB please.)"
156
+ )
163
157
  end
164
158
 
165
159
  context "given :less_than and :greater_than" do
@@ -169,8 +163,10 @@ describe Paperclip::Validators::AttachmentSizeValidator do
169
163
  message: "is invalid. (Between %{min} and %{max} please.)"
170
164
  end
171
165
 
172
- should_not_allow_attachment_file_size 11.kilobytes,
173
- message: "is invalid. (Between #{storage_units[5120]} and #{storage_units[10240]} please.)"
166
+ should_not_allow_attachment_file_size(
167
+ 11.kilobytes,
168
+ message: "is invalid. (Between 5 KB and 10 KB please.)"
169
+ )
174
170
  end
175
171
  end
176
172
 
@@ -181,10 +177,15 @@ describe Paperclip::Validators::AttachmentSizeValidator do
181
177
  less_than: 10.kilobytes
182
178
  end
183
179
 
184
- should_not_allow_attachment_file_size 11.kilobytes,
185
- message: "must be less than #{storage_units[10240]}"
186
- should_not_allow_attachment_file_size 4.kilobytes,
187
- message: "must be greater than #{storage_units[5120]}"
180
+ should_not_allow_attachment_file_size(
181
+ 11.kilobytes,
182
+ message: "must be less than 10 KB"
183
+ )
184
+
185
+ should_not_allow_attachment_file_size(
186
+ 4.kilobytes,
187
+ message: "must be greater than 5 KB"
188
+ )
188
189
  end
189
190
 
190
191
  context "given a size range" do
@@ -192,10 +193,15 @@ describe Paperclip::Validators::AttachmentSizeValidator do
192
193
  build_validator in: (5.kilobytes..10.kilobytes)
193
194
  end
194
195
 
195
- should_not_allow_attachment_file_size 11.kilobytes,
196
- message: "must be in between #{storage_units[5120]} and #{storage_units[10240]}"
197
- should_not_allow_attachment_file_size 4.kilobytes,
198
- message: "must be in between #{storage_units[5120]} and #{storage_units[10240]}"
196
+ should_not_allow_attachment_file_size(
197
+ 11.kilobytes,
198
+ message: "must be in between 5 KB and 10 KB"
199
+ )
200
+
201
+ should_not_allow_attachment_file_size(
202
+ 4.kilobytes,
203
+ message: "must be in between 5 KB and 10 KB"
204
+ )
199
205
  end
200
206
  end
201
207
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.beta1
4
+ version: 5.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Yurek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-23 00:00:00.000000000 Z
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -156,7 +156,7 @@ dependencies:
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 2.0.33
159
+ version: 2.0.34
160
160
  - - "<"
161
161
  - !ruby/object:Gem::Version
162
162
  version: '3.0'
@@ -166,7 +166,7 @@ dependencies:
166
166
  requirements:
167
167
  - - ">="
168
168
  - !ruby/object:Gem::Version
169
- version: 2.0.33
169
+ version: 2.0.34
170
170
  - - "<"
171
171
  - !ruby/object:Gem::Version
172
172
  version: '3.0'
@@ -400,7 +400,6 @@ files:
400
400
  - RELEASING.md
401
401
  - Rakefile
402
402
  - UPGRADING
403
- - cucumber/paperclip_steps.rb
404
403
  - features/basic_integration.feature
405
404
  - features/migration.feature
406
405
  - features/rake_tasks.feature
@@ -594,6 +593,9 @@ post_install_message: |
594
593
  note that the format of the permissions changed from using an underscore to
595
594
  using a hyphen. For example, `:public_read` needs to be changed to
596
595
  `public-read`.
596
+
597
+ For a walkthrough of upgrading from 4 to 5 and aws-sdk >= 2.0 you can watch
598
+ http://rubythursday.com/episodes/ruby-snack-27-upgrade-paperclip-and-aws-sdk-in-prep-for-rails-5
597
599
  rdoc_options: []
598
600
  require_paths:
599
601
  - lib
@@ -610,7 +612,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
610
612
  requirements:
611
613
  - ImageMagick
612
614
  rubyforge_project:
613
- rubygems_version: 2.5.1
615
+ rubygems_version: 2.6.2
614
616
  signing_key:
615
617
  specification_version: 4
616
618
  summary: File attachments as attributes for ActiveRecord
@@ -1,6 +0,0 @@
1
- When /^I attach an? "([^\"]*)" "([^\"]*)" file to an? "([^\"]*)" on S3$/ do |attachment, extension, model|
2
- stub_paperclip_s3(model, attachment, extension)
3
- attach_file attachment,
4
- "features/support/paperclip/#{model.gsub(" ", "_").underscore}/#{attachment}.#{extension}"
5
- end
6
-