kt-paperclip 5.4.0 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.github/issue_template.md +3 -0
  3. data/.hound.yml +27 -32
  4. data/.travis.yml +23 -2
  5. data/Appraisals +17 -0
  6. data/Gemfile +9 -7
  7. data/NEWS +21 -0
  8. data/README.md +27 -37
  9. data/Rakefile +29 -21
  10. data/UPGRADING +3 -3
  11. data/features/basic_integration.feature +4 -0
  12. data/features/migration.feature +10 -51
  13. data/features/step_definitions/attachment_steps.rb +12 -12
  14. data/features/step_definitions/html_steps.rb +5 -5
  15. data/features/step_definitions/rails_steps.rb +29 -9
  16. data/features/step_definitions/s3_steps.rb +3 -3
  17. data/features/step_definitions/web_steps.rb +5 -6
  18. data/features/support/env.rb +4 -4
  19. data/features/support/fakeweb.rb +3 -5
  20. data/features/support/file_helpers.rb +2 -2
  21. data/features/support/paths.rb +4 -4
  22. data/features/support/rails.rb +7 -7
  23. data/features/support/selectors.rb +1 -1
  24. data/gemfiles/4.2.gemfile +7 -4
  25. data/gemfiles/5.0.gemfile +7 -4
  26. data/gemfiles/5.1.gemfile +20 -0
  27. data/gemfiles/5.2.gemfile +20 -0
  28. data/gemfiles/6.0.gemfile +20 -0
  29. data/lib/generators/paperclip/paperclip_generator.rb +6 -8
  30. data/lib/paperclip/attachment.rb +102 -104
  31. data/lib/paperclip/attachment_registry.rb +2 -2
  32. data/lib/paperclip/file_command_content_type_detector.rb +1 -3
  33. data/lib/paperclip/filename_cleaner.rb +0 -1
  34. data/lib/paperclip/geometry.rb +18 -19
  35. data/lib/paperclip/geometry_detector_factory.rb +13 -16
  36. data/lib/paperclip/geometry_parser_factory.rb +5 -5
  37. data/lib/paperclip/glue.rb +3 -3
  38. data/lib/paperclip/has_attached_file.rb +5 -4
  39. data/lib/paperclip/helpers.rb +3 -3
  40. data/lib/paperclip/interpolations.rb +42 -38
  41. data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
  42. data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
  43. data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
  44. data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
  45. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +3 -3
  46. data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
  47. data/lib/paperclip/io_adapters/registry.rb +1 -1
  48. data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
  49. data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
  50. data/lib/paperclip/io_adapters/uri_adapter.rb +9 -7
  51. data/lib/paperclip/logger.rb +1 -1
  52. data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
  53. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
  54. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
  55. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
  56. data/lib/paperclip/matchers.rb +4 -4
  57. data/lib/paperclip/media_type_spoof_detector.rb +13 -13
  58. data/lib/paperclip/missing_attachment_styles.rb +11 -6
  59. data/lib/paperclip/processor.rb +13 -6
  60. data/lib/paperclip/processor_helpers.rb +3 -1
  61. data/lib/paperclip/rails_environment.rb +1 -5
  62. data/lib/paperclip/railtie.rb +5 -5
  63. data/lib/paperclip/schema.rb +18 -14
  64. data/lib/paperclip/storage/filesystem.rb +5 -7
  65. data/lib/paperclip/storage/fog.rb +36 -32
  66. data/lib/paperclip/storage/s3.rb +67 -75
  67. data/lib/paperclip/style.rb +3 -6
  68. data/lib/paperclip/tempfile.rb +4 -5
  69. data/lib/paperclip/tempfile_factory.rb +0 -1
  70. data/lib/paperclip/thumbnail.rb +11 -11
  71. data/lib/paperclip/url_generator.rb +5 -12
  72. data/lib/paperclip/validators/attachment_content_type_validator.rb +3 -3
  73. data/lib/paperclip/validators/attachment_file_name_validator.rb +5 -10
  74. data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
  75. data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
  76. data/lib/paperclip/validators/attachment_size_validator.rb +8 -8
  77. data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
  78. data/lib/paperclip/validators.rb +12 -13
  79. data/lib/paperclip/version.rb +1 -3
  80. data/lib/paperclip.rb +49 -48
  81. data/lib/tasks/paperclip.rake +23 -24
  82. data/paperclip.gemspec +29 -33
  83. data/shoulda_macros/paperclip.rb +16 -16
  84. data/spec/paperclip/attachment_definitions_spec.rb +5 -5
  85. data/spec/paperclip/attachment_processing_spec.rb +22 -23
  86. data/spec/paperclip/attachment_registry_spec.rb +15 -15
  87. data/spec/paperclip/attachment_spec.rb +238 -196
  88. data/spec/paperclip/content_type_detector_spec.rb +11 -12
  89. data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
  90. data/spec/paperclip/filename_cleaner_spec.rb +3 -4
  91. data/spec/paperclip/geometry_detector_spec.rb +7 -8
  92. data/spec/paperclip/geometry_parser_spec.rb +31 -31
  93. data/spec/paperclip/geometry_spec.rb +24 -24
  94. data/spec/paperclip/glue_spec.rb +3 -5
  95. data/spec/paperclip/has_attached_file_spec.rb +46 -126
  96. data/spec/paperclip/integration_spec.rb +111 -77
  97. data/spec/paperclip/interpolations_spec.rb +101 -93
  98. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
  99. data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
  100. data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
  101. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
  102. data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
  103. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +42 -26
  104. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
  105. data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
  106. data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
  107. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
  108. data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
  109. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +80 -31
  110. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
  111. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
  112. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
  113. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
  114. data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
  115. data/spec/paperclip/meta_class_spec.rb +3 -3
  116. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
  117. data/spec/paperclip/paperclip_spec.rb +15 -11
  118. data/spec/paperclip/plural_cache_spec.rb +8 -8
  119. data/spec/paperclip/processor_helpers_spec.rb +35 -35
  120. data/spec/paperclip/processor_spec.rb +8 -8
  121. data/spec/paperclip/rails_environment_spec.rb +7 -10
  122. data/spec/paperclip/rake_spec.rb +39 -39
  123. data/spec/paperclip/schema_spec.rb +57 -53
  124. data/spec/paperclip/storage/filesystem_spec.rb +6 -6
  125. data/spec/paperclip/storage/fog_spec.rb +76 -82
  126. data/spec/paperclip/storage/s3_live_spec.rb +22 -22
  127. data/spec/paperclip/storage/s3_spec.rb +585 -583
  128. data/spec/paperclip/style_spec.rb +67 -71
  129. data/spec/paperclip/tempfile_factory_spec.rb +5 -5
  130. data/spec/paperclip/thumbnail_spec.rb +68 -67
  131. data/spec/paperclip/url_generator_spec.rb +18 -29
  132. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +27 -27
  133. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +15 -16
  134. data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
  135. data/spec/paperclip/validators/attachment_size_validator_spec.rb +21 -21
  136. data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
  137. data/spec/paperclip/validators_spec.rb +40 -40
  138. data/spec/spec_helper.rb +21 -23
  139. data/spec/support/assertions.rb +8 -6
  140. data/spec/support/fake_model.rb +1 -2
  141. data/spec/support/fake_rails.rb +1 -1
  142. data/spec/support/matchers/exist.rb +1 -1
  143. data/spec/support/matchers/have_column.rb +1 -1
  144. data/spec/support/mock_url_generator_builder.rb +2 -3
  145. data/spec/support/model_reconstruction.rb +16 -12
  146. data/spec/support/reporting.rb +1 -1
  147. data/spec/support/test_data.rb +2 -2
  148. metadata +49 -105
  149. data/lib/kt-paperclip.rb +0 -1
  150. data/spec/support/conditional_filter_helper.rb +0 -5
@@ -1,8 +1,6 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
1
+ require "spec_helper"
3
2
 
4
3
  describe Paperclip::Attachment do
5
-
6
4
  it "is not present when file not set" do
7
5
  rebuild_class
8
6
  dummy = Dummy.new
@@ -19,8 +17,8 @@ describe Paperclip::Attachment do
19
17
  end
20
18
 
21
19
  it "processes :original style first" do
22
- file = File.new(fixture_file("50x50.png"), 'rb')
23
- rebuild_class styles: { small: '100x>', original: '42x42#' }
20
+ file = File.new(fixture_file("50x50.png"), "rb")
21
+ rebuild_class styles: { small: "100x>", original: "42x42#" }
24
22
  dummy = Dummy.new
25
23
  dummy.avatar = file
26
24
  dummy.save
@@ -32,7 +30,7 @@ describe Paperclip::Attachment do
32
30
  end
33
31
 
34
32
  it "does not delete styles that don't get reprocessed" do
35
- file = File.new(fixture_file("50x50.png"), 'rb')
33
+ file = File.new(fixture_file("50x50.png"), "rb")
36
34
  rebuild_class styles: {
37
35
  small: "100x>",
38
36
  large: "500x>",
@@ -54,6 +52,22 @@ describe Paperclip::Attachment do
54
52
  expect(dummy.avatar.path(:original)).to exist
55
53
  end
56
54
 
55
+ it "reprocess works with virtual content_type attribute" do
56
+ rebuild_class styles: { small: "100x>" }
57
+ modify_table { |t| t.remove :avatar_content_type }
58
+ Dummy.send :attr_accessor, :avatar_content_type
59
+ Dummy.validates_attachment_content_type(
60
+ :avatar,
61
+ content_type: %w(image/jpeg image/png)
62
+ )
63
+ Dummy.create!(avatar: File.new(fixture_file("50x50.png"), "rb"))
64
+
65
+ dummy = Dummy.first
66
+ dummy.avatar.reprocess!(:small)
67
+
68
+ expect(dummy.avatar.path(:small)).to exist
69
+ end
70
+
57
71
  context "having a not empty hash as a default option" do
58
72
  before do
59
73
  @old_default_options = Paperclip::Attachment.default_options.dup
@@ -79,7 +93,7 @@ describe Paperclip::Attachment do
79
93
  :name,
80
94
  FakeModel.new,
81
95
  url_generator: mock_url_generator_builder
82
- )
96
+ )
83
97
 
84
98
  attachment.url(:style_name, true)
85
99
  expect(mock_url_generator_builder.has_generated_url_with_options?(timestamp: true, escape: true)).to eq true
@@ -94,7 +108,7 @@ describe Paperclip::Attachment do
94
108
  :name,
95
109
  FakeModel.new,
96
110
  url_generator: mock_url_generator_builder
97
- )
111
+ )
98
112
 
99
113
  attachment.url(:style_name, options: :values)
100
114
  expect(mock_url_generator_builder.has_generated_url_with_options?(options: :values)).to eq true
@@ -115,13 +129,13 @@ describe Paperclip::Attachment do
115
129
  mock_url_generator_builder = MockUrlGeneratorBuilder.new
116
130
  attachment = Paperclip::Attachment.new(:name,
117
131
  FakeModel.new,
118
- default_style: 'default style',
132
+ default_style: "default style",
119
133
  url_generator: mock_url_generator_builder,
120
134
  use_timestamp: true)
121
135
 
122
136
  attachment.url
123
137
  assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true)
124
- assert mock_url_generator_builder.has_generated_url_with_style_name?('default style')
138
+ assert mock_url_generator_builder.has_generated_url_with_style_name?("default style")
125
139
  end
126
140
 
127
141
  it "passes the option timestamp: true if :use_timestamp is true and :timestamp is not passed" do
@@ -161,11 +175,11 @@ describe Paperclip::Attachment do
161
175
  mock_url_generator_builder = MockUrlGeneratorBuilder.new
162
176
  attachment = Paperclip::Attachment.new(:name,
163
177
  FakeModel.new,
164
- default_style: 'default style',
178
+ default_style: "default style",
165
179
  url_generator: mock_url_generator_builder)
166
180
 
167
181
  attachment.as_json
168
- assert mock_url_generator_builder.has_generated_url_with_style_name?('default style')
182
+ assert mock_url_generator_builder.has_generated_url_with_style_name?("default style")
169
183
  end
170
184
 
171
185
  it "passes the option escape: true if :escape_url is true and :escape is not passed" do
@@ -220,7 +234,7 @@ describe Paperclip::Attachment do
220
234
  dummy = Dummy.new
221
235
  dummy.id = 1234
222
236
  dummy.avatar_file_name = "fake.jpg"
223
- dummy.stubs(:new_record?).returns(false)
237
+ allow(dummy).to receive(:new_record?).and_return(false)
224
238
  expected_string = '{"avatar":"/system/dummies/avatars/000/001/234/original/fake.jpg"}'
225
239
  # active_model pre-3.2 checks only by calling any? on it, thus it doesn't work if it is empty
226
240
  assert_equal expected_string, dummy.to_json(only: [:dummy_key_for_old_active_model], methods: [:avatar])
@@ -230,11 +244,11 @@ describe Paperclip::Attachment do
230
244
  before do
231
245
  rebuild_model
232
246
  @old_default_options = Paperclip::Attachment.default_options.dup
233
- @new_default_options = @old_default_options.merge({
247
+ @new_default_options = @old_default_options.merge(
234
248
  path: "argle/bargle",
235
249
  url: "fooferon",
236
250
  default_url: "not here.png"
237
- })
251
+ )
238
252
  end
239
253
 
240
254
  after do
@@ -300,8 +314,9 @@ describe Paperclip::Attachment do
300
314
  before do
301
315
  rebuild_model path: ":id.omg/:id-bbq/:idwhat/:id_partition.wtf"
302
316
  @dummy = Dummy.new
303
- @dummy.stubs(:id).returns(1024)
304
- @file = File.new(fixture_file("5k.png"), 'rb')
317
+
318
+ allow(@dummy).to receive(:id).and_return(1024)
319
+ @file = File.new(fixture_file("5k.png"), "rb")
305
320
  @dummy.avatar = @file
306
321
  end
307
322
 
@@ -315,10 +330,10 @@ describe Paperclip::Attachment do
315
330
  context "An attachment with :timestamp interpolations" do
316
331
  before do
317
332
  @file = StringIO.new("...")
318
- @zone = 'UTC'
319
- Time.stubs(:zone).returns(@zone)
320
- @zone_default = 'Eastern Time (US & Canada)'
321
- Time.stubs(:zone_default).returns(@zone_default)
333
+ @zone = "UTC"
334
+ allow(Time).to receive(:zone).and_return(@zone)
335
+ @zone_default = "Eastern Time (US & Canada)"
336
+ allow(Time).to receive(:zone_default).and_return(@zone_default)
322
337
  end
323
338
 
324
339
  context "using default time zone" do
@@ -368,17 +383,17 @@ describe Paperclip::Attachment do
368
383
  context "when secret is set" do
369
384
  before do
370
385
  rebuild_model path: ":hash",
371
- hash_secret: "w00t",
372
- hash_data: ":class/:attachment/:style/:filename"
386
+ hash_secret: "w00t",
387
+ hash_data: ":class/:attachment/:style/:filename"
373
388
  @attachment = Dummy.new.avatar
374
389
  @attachment.assign @file
375
390
  end
376
391
 
377
392
  it "results in the correct interpolation" do
378
393
  assert_equal "dummies/avatars/original/5k.png",
379
- @attachment.send(:interpolate, @attachment.options[:hash_data])
394
+ @attachment.send(:interpolate, @attachment.options[:hash_data])
380
395
  assert_equal "dummies/avatars/thumb/5k.png",
381
- @attachment.send(:interpolate, @attachment.options[:hash_data], :thumb)
396
+ @attachment.send(:interpolate, @attachment.options[:hash_data], :thumb)
382
397
  end
383
398
 
384
399
  it "results in a correct hash" do
@@ -394,10 +409,10 @@ describe Paperclip::Attachment do
394
409
  @id = 1024
395
410
  rebuild_model path: ":rails_env/:id.png"
396
411
  @dummy = Dummy.new
397
- @dummy.stubs(:id).returns(@id)
412
+ allow(@dummy).to receive(:id).and_return(@id)
398
413
  @file = StringIO.new(".")
399
414
  @dummy.avatar = @file
400
- Rails.stubs(:env).returns(@rails_env)
415
+ allow(Rails).to receive(:env).and_return(@rails_env)
401
416
  end
402
417
 
403
418
  it "returns the proper path" do
@@ -408,11 +423,11 @@ describe Paperclip::Attachment do
408
423
  context "An attachment with a default style and an extension interpolation" do
409
424
  before do
410
425
  rebuild_model path: ":basename.:extension",
411
- styles: { default: ["100x100", :jpg] },
412
- default_style: :default
426
+ styles: { default: ["100x100", :jpg] },
427
+ default_style: :default
413
428
  @attachment = Dummy.new.avatar
414
429
  @file = File.open(fixture_file("5k.png"))
415
- @file.stubs(:original_filename).returns("file.png")
430
+ allow(@file).to receive(:original_filename).and_return("file.png")
416
431
  end
417
432
  it "returns the right extension for the path" do
418
433
  @attachment.assign(@file)
@@ -423,9 +438,9 @@ describe Paperclip::Attachment do
423
438
  context "An attachment with :convert_options" do
424
439
  before do
425
440
  rebuild_model styles: {
426
- thumb: "100x100",
427
- large: "400x400"
428
- },
441
+ thumb: "100x100",
442
+ large: "400x400"
443
+ },
429
444
  convert_options: {
430
445
  all: "-do_stuff",
431
446
  thumb: "-thumbnailize"
@@ -446,9 +461,9 @@ describe Paperclip::Attachment do
446
461
  context "An attachment with :source_file_options" do
447
462
  before do
448
463
  rebuild_model styles: {
449
- thumb: "100x100",
450
- large: "400x400"
451
- },
464
+ thumb: "100x100",
465
+ large: "400x400"
466
+ },
452
467
  source_file_options: {
453
468
  all: "-density 400",
454
469
  thumb: "-depth 8"
@@ -469,17 +484,17 @@ describe Paperclip::Attachment do
469
484
  context "An attachment with :only_process" do
470
485
  before do
471
486
  rebuild_model styles: {
472
- thumb: "100x100",
473
- large: "400x400"
474
- },
487
+ thumb: "100x100",
488
+ large: "400x400"
489
+ },
475
490
  only_process: [:thumb]
476
491
  @file = StringIO.new("...")
477
492
  @attachment = Dummy.new.avatar
478
493
  end
479
494
 
480
495
  it "only processes the provided style" do
481
- @attachment.expects(:post_process).with(:thumb)
482
- @attachment.expects(:post_process).with(:large).never
496
+ expect(@attachment).to receive(:post_process).with(:thumb)
497
+ expect(@attachment).to receive(:post_process).with(:large).never
483
498
  @attachment.assign(@file)
484
499
  end
485
500
  end
@@ -487,18 +502,18 @@ describe Paperclip::Attachment do
487
502
  context "An attachment with :only_process that is a proc" do
488
503
  before do
489
504
  rebuild_model styles: {
490
- thumb: "100x100",
491
- large: "400x400"
492
- },
493
- only_process: lambda { |attachment| [:thumb] }
505
+ thumb: "100x100",
506
+ large: "400x400"
507
+ },
508
+ only_process: lambda { |_attachment| [:thumb] }
494
509
 
495
510
  @file = StringIO.new("...")
496
511
  @attachment = Dummy.new.avatar
497
512
  end
498
513
 
499
514
  it "only processes the provided style" do
500
- @attachment.expects(:post_process).with(:thumb)
501
- @attachment.expects(:post_process).with(:large).never
515
+ expect(@attachment).to receive(:post_process).with(:thumb)
516
+ expect(@attachment).to receive(:post_process).with(:large).never
502
517
  @attachment.assign(@file)
503
518
  @attachment.save
504
519
  end
@@ -507,15 +522,16 @@ describe Paperclip::Attachment do
507
522
  context "An attachment with :convert_options that is a proc" do
508
523
  before do
509
524
  rebuild_model styles: {
510
- thumb: "100x100",
511
- large: "400x400"
512
- },
525
+ thumb: "100x100",
526
+ large: "400x400"
527
+ },
513
528
  convert_options: {
514
- all: lambda{|i| i.all },
515
- thumb: lambda{|i| i.thumb }
529
+ all: lambda { |i| i.all },
530
+ thumb: lambda { |i| i.thumb }
516
531
  }
517
532
  Dummy.class_eval do
518
533
  def all; "-all"; end
534
+
519
535
  def thumb; "-thumb"; end
520
536
  end
521
537
  @dummy = Dummy.new
@@ -533,12 +549,12 @@ describe Paperclip::Attachment do
533
549
 
534
550
  context "An attachment with :path that is a proc" do
535
551
  before do
536
- rebuild_model path: lambda{ |attachment| "path/#{attachment.instance.other}.:extension" }
552
+ rebuild_model path: lambda { |attachment| "path/#{attachment.instance.other}.:extension" }
537
553
 
538
- @file = File.new(fixture_file("5k.png"), 'rb')
539
- @dummyA = Dummy.new(other: 'a')
554
+ @file = File.new(fixture_file("5k.png"), "rb")
555
+ @dummyA = Dummy.new(other: "a")
540
556
  @dummyA.avatar = @file
541
- @dummyB = Dummy.new(other: 'b')
557
+ @dummyB = Dummy.new(other: "b")
542
558
  @dummyB.avatar = @file
543
559
  end
544
560
 
@@ -552,7 +568,7 @@ describe Paperclip::Attachment do
552
568
 
553
569
  context "An attachment with :styles that is a proc" do
554
570
  before do
555
- rebuild_model styles: lambda{ |attachment| {thumb: "50x50#", large: "400x400"} }
571
+ rebuild_model styles: lambda { |_attachment| { thumb: "50x50#", large: "400x400" } }
556
572
 
557
573
  @attachment = Dummy.new.avatar
558
574
  end
@@ -564,16 +580,16 @@ describe Paperclip::Attachment do
564
580
 
565
581
  context "An attachment with conditional :styles that is a proc" do
566
582
  before do
567
- rebuild_model styles: lambda{ |attachment| attachment.instance.other == 'a' ? {thumb: "50x50#"} : {large: "400x400"} }
583
+ rebuild_model styles: lambda { |attachment| attachment.instance.other == "a" ? { thumb: "50x50#" } : { large: "400x400" } }
568
584
 
569
- @dummy = Dummy.new(other: 'a')
585
+ @dummy = Dummy.new(other: "a")
570
586
  end
571
587
 
572
588
  it "has the correct styles for the assigned instance values" do
573
589
  assert_equal "50x50#", @dummy.avatar.styles[:thumb][:geometry]
574
590
  assert_nil @dummy.avatar.styles[:large]
575
591
 
576
- @dummy.other = 'b'
592
+ @dummy.other = "b"
577
593
 
578
594
  assert_equal "400x400", @dummy.avatar.styles[:large][:geometry]
579
595
  assert_nil @dummy.avatar.styles[:thumb]
@@ -581,9 +597,9 @@ describe Paperclip::Attachment do
581
597
  end
582
598
 
583
599
  geometry_specs = [
584
- [ lambda{|z| "50x50#" }, :png ],
585
- lambda{|z| "50x50#" },
586
- { geometry: lambda{|z| "50x50#" } }
600
+ [lambda { |_z| "50x50#" }, :png],
601
+ lambda { |_z| "50x50#" },
602
+ { geometry: lambda { |_z| "50x50#" } }
587
603
  ]
588
604
  geometry_specs.each do |geometry_spec|
589
605
  context "An attachment geometry like #{geometry_spec}" do
@@ -608,9 +624,9 @@ describe Paperclip::Attachment do
608
624
  context "An attachment with both 'normal' and hash-style styles" do
609
625
  before do
610
626
  rebuild_model styles: {
611
- normal: ["50x50#", :png],
612
- hash: { geometry: "50x50#", format: :png }
613
- }
627
+ normal: ["50x50#", :png],
628
+ hash: { geometry: "50x50#", format: :png }
629
+ }
614
630
  @dummy = Dummy.new
615
631
  @attachment = @dummy.avatar
616
632
  end
@@ -626,9 +642,9 @@ describe Paperclip::Attachment do
626
642
  before do
627
643
  class Paperclip::Test < Paperclip::Processor; end
628
644
  @file = StringIO.new("...")
629
- Paperclip::Test.stubs(:make).returns(@file)
645
+ allow(Paperclip::Test).to receive(:make).and_return(@file)
630
646
 
631
- rebuild_model styles: { normal: '' }, processors: lambda { |a| [ :test ] }
647
+ rebuild_model styles: { normal: "" }, processors: lambda { |_a| [:test] }
632
648
  @attachment = Dummy.new.avatar
633
649
  end
634
650
 
@@ -638,22 +654,22 @@ describe Paperclip::Attachment do
638
654
  end
639
655
 
640
656
  it "has the correct processors" do
641
- assert_equal [ :test ], @attachment.styles[:normal][:processors]
657
+ assert_equal [:test], @attachment.styles[:normal][:processors]
642
658
  end
643
659
  end
644
660
  end
645
661
 
646
662
  context "An attachment with erroring processor" do
647
663
  before do
648
- rebuild_model processor: [:thumbnail], styles: { small: '' }, whiny_thumbnails: true
664
+ rebuild_model processor: [:thumbnail], styles: { small: "" }, whiny_thumbnails: true
649
665
  @dummy = Dummy.new
650
666
  @file = StringIO.new("...")
651
- @file.stubs(:to_tempfile).returns(@file)
667
+ allow(@file).to receive(:to_tempfile).and_return(@file)
652
668
  end
653
669
 
654
670
  context "when error is meaningful for the end user" do
655
671
  before do
656
- Paperclip::Thumbnail.expects(:make).raises(
672
+ expect(Paperclip::Thumbnail).to receive(:make).and_raise(
657
673
  Paperclip::Errors::NotIdentifiedByImageMagickError,
658
674
  "cannot be processed."
659
675
  )
@@ -671,7 +687,7 @@ describe Paperclip::Attachment do
671
687
 
672
688
  context "when error is intended for the developer" do
673
689
  before do
674
- Paperclip::Thumbnail.expects(:make).raises(
690
+ expect(Paperclip::Thumbnail).to receive(:make).and_raise(
675
691
  Paperclip::Errors::CommandNotFoundError
676
692
  )
677
693
  end
@@ -687,13 +703,13 @@ describe Paperclip::Attachment do
687
703
  context "An attachment with multiple processors" do
688
704
  before do
689
705
  class Paperclip::Test < Paperclip::Processor; end
690
- @style_params = { once: {one: 1, two: 2} }
706
+ @style_params = { once: { one: 1, two: 2 } }
691
707
  rebuild_model processors: [:thumbnail, :test], styles: @style_params
692
708
  @dummy = Dummy.new
693
709
  @file = StringIO.new("...")
694
- @file.stubs(:close)
695
- Paperclip::Test.stubs(:make).returns(@file)
696
- Paperclip::Thumbnail.stubs(:make).returns(@file)
710
+ allow(@file).to receive(:close)
711
+ allow(Paperclip::Test).to receive(:make).and_return(@file)
712
+ allow(Paperclip::Thumbnail).to receive(:make).and_return(@file)
697
713
  end
698
714
 
699
715
  context "when assigned" do
@@ -705,13 +721,13 @@ describe Paperclip::Attachment do
705
721
  end
706
722
 
707
723
  it "calls #make with the right parameters passed as second argument" do
708
- expected_params = @style_params[:once].merge({
724
+ expected_params = @style_params[:once].merge(
709
725
  style: :once,
710
726
  processors: [:thumbnail, :test],
711
727
  whiny: true,
712
728
  convert_options: "",
713
729
  source_file_options: ""
714
- })
730
+ )
715
731
 
716
732
  @dummy.avatar = @file
717
733
 
@@ -725,7 +741,7 @@ describe Paperclip::Attachment do
725
741
  end
726
742
 
727
743
  it "calls #make and unlinks intermediary files afterward" do
728
- @dummy.avatar.expects(:unlink_files).with([@file, @file])
744
+ expect(@dummy.avatar).to receive(:unlink_files).with([@file, @file])
729
745
 
730
746
  @dummy.avatar = @file
731
747
  end
@@ -739,13 +755,13 @@ describe Paperclip::Attachment do
739
755
  end
740
756
  rebuild_model processors: [:test], styles: { once: "100x100" }
741
757
  @file = StringIO.new("...")
742
- @file.stubs(:close)
758
+ allow(@file).to receive(:close)
743
759
  @dummy = Dummy.new
744
760
  end
745
761
 
746
762
  context "when assigned" do
747
763
  it "#calls #make and doesn't unlink the original file" do
748
- @dummy.avatar.expects(:unlink_files).with([])
764
+ expect(@dummy.avatar).to receive(:unlink_files).with([])
749
765
 
750
766
  @dummy.avatar = @file
751
767
  end
@@ -786,12 +802,12 @@ describe Paperclip::Attachment do
786
802
 
787
803
  context "An attachment with styles but no processors defined" do
788
804
  before do
789
- rebuild_model processors: [], styles: {something: '1'}
805
+ rebuild_model processors: [], styles: { something: "1" }
790
806
  @dummy = Dummy.new
791
807
  @file = StringIO.new("...")
792
808
  end
793
809
  it "raises when assigned to" do
794
- assert_raises(RuntimeError){ @dummy.avatar = @file }
810
+ assert_raises(RuntimeError) { @dummy.avatar = @file }
795
811
  end
796
812
  end
797
813
 
@@ -815,50 +831,78 @@ describe Paperclip::Attachment do
815
831
  before_post_process :do_before_all
816
832
  after_post_process :do_after_all
817
833
  def do_before_avatar; end
834
+
818
835
  def do_after_avatar; end
836
+
819
837
  def do_before_all; end
838
+
820
839
  def do_after_all; end
821
840
  end
822
- @file = StringIO.new(".")
823
- @file.stubs(:to_tempfile).returns(@file)
841
+ @file = StringIO.new(".")
842
+ allow(@file).to receive(:to_tempfile).and_return(@file)
824
843
  @dummy = Dummy.new
825
- Paperclip::Thumbnail.stubs(:make).returns(@file)
844
+ allow(Paperclip::Thumbnail).to receive(:make).and_return(@file)
826
845
  @attachment = @dummy.avatar
827
846
  end
828
847
 
829
848
  it "calls the defined callbacks when assigned" do
830
- @dummy.expects(:do_before_avatar).with()
831
- @dummy.expects(:do_after_avatar).with()
832
- @dummy.expects(:do_before_all).with()
833
- @dummy.expects(:do_after_all).with()
834
- Paperclip::Thumbnail.expects(:make).returns(@file)
849
+ expect(@dummy).to receive(:do_before_avatar)
850
+ expect(@dummy).to receive(:do_after_avatar)
851
+ expect(@dummy).to receive(:do_before_all)
852
+ expect(@dummy).to receive(:do_after_all)
853
+ expect(Paperclip::Thumbnail).to receive(:make).and_return(@file)
835
854
  @dummy.avatar = @file
836
855
  end
837
856
 
838
857
  it "does not cancel the processing if a before_post_process returns nil" do
839
- @dummy.expects(:do_before_avatar).with().returns(nil)
840
- @dummy.expects(:do_after_avatar).with()
841
- @dummy.expects(:do_before_all).with().returns(nil)
842
- @dummy.expects(:do_after_all).with()
843
- Paperclip::Thumbnail.expects(:make).returns(@file)
858
+ expect(@dummy).to receive(:do_before_avatar).and_return(nil)
859
+ expect(@dummy).to receive(:do_after_avatar)
860
+ expect(@dummy).to receive(:do_before_all).and_return(nil)
861
+ expect(@dummy).to receive(:do_after_all)
862
+ expect(Paperclip::Thumbnail).to receive(:make).and_return(@file)
844
863
  @dummy.avatar = @file
845
864
  end
846
865
 
847
866
  it "cancels the processing if a before_post_process returns false" do
848
- @dummy.expects(:do_before_avatar).never
849
- @dummy.expects(:do_after_avatar).never
850
- @dummy.expects(:do_before_all).with().returns(false)
851
- @dummy.expects(:do_after_all)
852
- Paperclip::Thumbnail.expects(:make).never
867
+ expect(@dummy).to receive(:do_before_avatar).never
868
+ expect(@dummy).to receive(:do_after_avatar).never
869
+ expect(@dummy).to receive(:do_before_all).and_return(false)
870
+ expect(@dummy).to receive(:do_after_all)
871
+ expect(Paperclip::Thumbnail).not_to receive(:make)
853
872
  @dummy.avatar = @file
854
873
  end
855
874
 
856
875
  it "cancels the processing if a before_avatar_post_process returns false" do
857
- @dummy.expects(:do_before_avatar).with().returns(false)
858
- @dummy.expects(:do_after_avatar)
859
- @dummy.expects(:do_before_all).with().returns(true)
860
- @dummy.expects(:do_after_all)
861
- Paperclip::Thumbnail.expects(:make).never
876
+ expect(@dummy).to receive(:do_before_avatar).and_return(false)
877
+ expect(@dummy).to receive(:do_after_avatar)
878
+ expect(@dummy).to receive(:do_before_all).and_return(true)
879
+ expect(@dummy).to receive(:do_after_all)
880
+ expect(Paperclip::Thumbnail).not_to receive(:make)
881
+ @dummy.avatar = @file
882
+ end
883
+
884
+ it "should not call process hooks if validation fails" do
885
+ Dummy.class_eval do
886
+ validates_attachment_content_type :avatar, content_type: 'image/jpeg'
887
+ end
888
+ expect(@dummy).not_to receive(:do_before_avatar)
889
+ expect(@dummy).not_to receive(:do_after_avatar)
890
+ expect(@dummy).not_to receive(:do_before_all)
891
+ expect(@dummy).not_to receive(:do_after_all)
892
+ expect(Paperclip::Thumbnail).not_to receive(:make)
893
+ @dummy.avatar = @file
894
+ end
895
+
896
+ it "should call process hooks if validation would fail but check validity flag is false" do
897
+ Dummy.class_eval do
898
+ validates_attachment_content_type :avatar, content_type: 'image/jpeg'
899
+ end
900
+ @dummy.avatar.options[:check_validity_before_processing] = false
901
+ expect(@dummy).to receive(:do_before_avatar)
902
+ expect(@dummy).to receive(:do_after_avatar)
903
+ expect(@dummy).to receive(:do_before_all)
904
+ expect(@dummy).to receive(:do_after_all)
905
+ expect(Paperclip::Thumbnail).to receive(:make).and_return(@file)
862
906
  @dummy.avatar = @file
863
907
  end
864
908
  end
@@ -897,7 +941,7 @@ describe Paperclip::Attachment do
897
941
  before do
898
942
  rebuild_model
899
943
  @file = File.new(fixture_file("5k.png"), "rb")
900
- @file.stubs(:original_filename).returns("sheep_say_bæ.png")
944
+ allow(@file).to receive(:original_filename).and_return("sheep_say_bæ.png")
901
945
  @dummy = Dummy.new
902
946
  @dummy.avatar = @file
903
947
  end
@@ -910,7 +954,7 @@ describe Paperclip::Attachment do
910
954
  context "Attachment with reserved filename" do
911
955
  before do
912
956
  rebuild_model
913
- @file = Tempfile.new(["filename","png"])
957
+ @file = Tempfile.new(["filename", "png"])
914
958
  end
915
959
 
916
960
  after do
@@ -920,10 +964,9 @@ describe Paperclip::Attachment do
920
964
  context "with default configuration" do
921
965
  "&$+,/:;=?@<>[]{}|\^~%# ".split(//).each do |character|
922
966
  context "with character #{character}" do
923
-
924
967
  context "at beginning of filename" do
925
968
  before do
926
- @file.stubs(:original_filename).returns("#{character}filename.png")
969
+ allow(@file).to receive(:original_filename).and_return("#{character}filename.png")
927
970
  @dummy = Dummy.new
928
971
  @dummy.avatar = @file
929
972
  end
@@ -935,7 +978,7 @@ describe Paperclip::Attachment do
935
978
 
936
979
  context "at end of filename" do
937
980
  before do
938
- @file.stubs(:original_filename).returns("filename.png#{character}")
981
+ allow(@file).to receive(:original_filename).and_return("filename.png#{character}")
939
982
  @dummy = Dummy.new
940
983
  @dummy.avatar = @file
941
984
  end
@@ -947,7 +990,7 @@ describe Paperclip::Attachment do
947
990
 
948
991
  context "in the middle of filename" do
949
992
  before do
950
- @file.stubs(:original_filename).returns("file#{character}name.png")
993
+ allow(@file).to receive(:original_filename).and_return("file#{character}name.png")
951
994
  @dummy = Dummy.new
952
995
  @dummy.avatar = @file
953
996
  end
@@ -956,7 +999,6 @@ describe Paperclip::Attachment do
956
999
  assert_equal "file_name.png", @dummy.avatar.original_filename
957
1000
  end
958
1001
  end
959
-
960
1002
  end
961
1003
  end
962
1004
  end
@@ -970,11 +1012,11 @@ describe Paperclip::Attachment do
970
1012
  Paperclip::Attachment.default_options.merge! @old_defaults
971
1013
  end
972
1014
 
973
- context 'as another regexp' do
1015
+ context "as another regexp" do
974
1016
  before do
975
1017
  Paperclip::Attachment.default_options.merge! restricted_characters: /o/
976
1018
 
977
- @file.stubs(:original_filename).returns("goood.png")
1019
+ allow(@file).to receive(:original_filename).and_return("goood.png")
978
1020
  @dummy = Dummy.new
979
1021
  @dummy.avatar = @file
980
1022
  end
@@ -984,11 +1026,11 @@ describe Paperclip::Attachment do
984
1026
  end
985
1027
  end
986
1028
 
987
- context 'as nil' do
1029
+ context "as nil" do
988
1030
  before do
989
1031
  Paperclip::Attachment.default_options.merge! restricted_characters: nil
990
1032
 
991
- @file.stubs(:original_filename).returns("goood.png")
1033
+ allow(@file).to receive(:original_filename).and_return("goood.png")
992
1034
  @dummy = Dummy.new
993
1035
  @dummy.avatar = @file
994
1036
  end
@@ -999,7 +1041,7 @@ describe Paperclip::Attachment do
999
1041
  end
1000
1042
  end
1001
1043
 
1002
- context 'with specified cleaner' do
1044
+ context "with specified cleaner" do
1003
1045
  before do
1004
1046
  @old_defaults = Paperclip::Attachment.default_options.dup
1005
1047
  end
@@ -1008,26 +1050,26 @@ describe Paperclip::Attachment do
1008
1050
  Paperclip::Attachment.default_options.merge! @old_defaults
1009
1051
  end
1010
1052
 
1011
- it 'calls the given proc and take the result as cleaned filename' do
1053
+ it "calls the given proc and take the result as cleaned filename" do
1012
1054
  Paperclip::Attachment.default_options[:filename_cleaner] = lambda do |str|
1013
1055
  "from_proc_#{str}"
1014
1056
  end
1015
1057
 
1016
- @file.stubs(:original_filename).returns("goood.png")
1058
+ allow(@file).to receive(:original_filename).and_return("goood.png")
1017
1059
  @dummy = Dummy.new
1018
1060
  @dummy.avatar = @file
1019
1061
  assert_equal "from_proc_goood.png", @dummy.avatar.original_filename
1020
1062
  end
1021
1063
 
1022
- it 'calls the given object and take the result as the cleaned filename' do
1064
+ it "calls the given object and take the result as the cleaned filename" do
1023
1065
  class MyCleaner
1024
- def call(filename)
1066
+ def call(_filename)
1025
1067
  "foo"
1026
1068
  end
1027
1069
  end
1028
1070
  Paperclip::Attachment.default_options[:filename_cleaner] = MyCleaner.new
1029
1071
 
1030
- @file.stubs(:original_filename).returns("goood.png")
1072
+ allow(@file).to receive(:original_filename).and_return("goood.png")
1031
1073
  @dummy = Dummy.new
1032
1074
  @dummy.avatar = @file
1033
1075
  assert_equal "foo", @dummy.avatar.original_filename
@@ -1038,22 +1080,22 @@ describe Paperclip::Attachment do
1038
1080
  context "Attachment with uppercase extension and a default style" do
1039
1081
  before do
1040
1082
  @old_defaults = Paperclip::Attachment.default_options.dup
1041
- Paperclip::Attachment.default_options.merge!({
1083
+ Paperclip::Attachment.default_options.merge!(
1042
1084
  path: ":rails_root/:attachment/:class/:style/:id/:basename.:extension"
1043
- })
1085
+ )
1044
1086
  FileUtils.rm_rf("tmp")
1045
1087
  rebuild_model styles: { large: ["400x400", :jpg],
1046
- medium: ["100x100", :jpg],
1047
- small: ["32x32#", :jpg]},
1088
+ medium: ["100x100", :jpg],
1089
+ small: ["32x32#", :jpg] },
1048
1090
  default_style: :small
1049
1091
  @instance = Dummy.new
1050
- @instance.stubs(:id).returns 123
1051
- @file = File.new(fixture_file("uppercase.PNG"), 'rb')
1092
+ allow(@instance).to receive(:id).and_return 123
1093
+ @file = File.new(fixture_file("uppercase.PNG"), "rb")
1052
1094
 
1053
1095
  @attachment = @instance.avatar
1054
1096
 
1055
1097
  now = Time.now
1056
- Time.stubs(:now).returns(now)
1098
+ allow(Time).to receive(:now).and_return(now)
1057
1099
  @attachment.assign(@file)
1058
1100
  @attachment.save
1059
1101
  end
@@ -1076,16 +1118,16 @@ describe Paperclip::Attachment do
1076
1118
  context "An attachment" do
1077
1119
  before do
1078
1120
  @old_defaults = Paperclip::Attachment.default_options.dup
1079
- Paperclip::Attachment.default_options.merge!({
1121
+ Paperclip::Attachment.default_options.merge!(
1080
1122
  path: ":rails_root/:attachment/:class/:style/:id/:basename.:extension"
1081
- })
1123
+ )
1082
1124
  FileUtils.rm_rf("tmp")
1083
1125
  rebuild_model
1084
1126
  @instance = Dummy.new
1085
- @instance.stubs(:id).returns 123
1127
+ allow(@instance).to receive(:id).and_return 123
1086
1128
  # @attachment = Paperclip::Attachment.new(:avatar, @instance)
1087
1129
  @attachment = @instance.avatar
1088
- @file = File.new(fixture_file("5k.png"), 'rb')
1130
+ @file = File.new(fixture_file("5k.png"), "rb")
1089
1131
  end
1090
1132
 
1091
1133
  after do
@@ -1100,14 +1142,14 @@ describe Paperclip::Attachment do
1100
1142
  end
1101
1143
  end
1102
1144
 
1103
- it 'clears out the previous assignment when assigned nil' do
1145
+ it "clears out the previous assignment when assigned nil" do
1104
1146
  @attachment.assign(@file)
1105
1147
  @attachment.queued_for_write[:original]
1106
1148
  @attachment.assign(nil)
1107
1149
  assert_nil @attachment.queued_for_write[:original]
1108
1150
  end
1109
1151
 
1110
- it 'does not do anything when it is assigned an empty string' do
1152
+ it "does not do anything when it is assigned an empty string" do
1111
1153
  @attachment.assign(@file)
1112
1154
  original_file = @attachment.queued_for_write[:original]
1113
1155
  @attachment.assign("")
@@ -1130,13 +1172,13 @@ describe Paperclip::Attachment do
1130
1172
 
1131
1173
  context "with a file assigned in the database" do
1132
1174
  before do
1133
- @attachment.stubs(:instance_read).with(:file_name).returns("5k.png")
1134
- @attachment.stubs(:instance_read).with(:content_type).returns("image/png")
1135
- @attachment.stubs(:instance_read).with(:file_size).returns(12345)
1175
+ allow(@attachment).to receive(:instance_read).with(:file_name).and_return("5k.png")
1176
+ allow(@attachment).to receive(:instance_read).with(:content_type).and_return("image/png")
1177
+ allow(@attachment).to receive(:instance_read).with(:file_size).and_return(12345)
1136
1178
  dtnow = DateTime.now
1137
1179
  @now = Time.now
1138
- Time.stubs(:now).returns(@now)
1139
- @attachment.stubs(:instance_read).with(:updated_at).returns(dtnow)
1180
+ allow(Time).to receive(:now).and_return(@now)
1181
+ allow(@attachment).to receive(:instance_read).with(:updated_at).and_return(dtnow)
1140
1182
  end
1141
1183
 
1142
1184
  it "returns the proper path when filename has a single .'s" do
@@ -1144,7 +1186,7 @@ describe Paperclip::Attachment do
1144
1186
  end
1145
1187
 
1146
1188
  it "returns the proper path when filename has multiple .'s" do
1147
- @attachment.stubs(:instance_read).with(:file_name).returns("5k.old.png")
1189
+ allow(@attachment).to receive(:instance_read).with(:file_name).and_return("5k.old.png")
1148
1190
  assert_equal File.expand_path("tmp/avatars/dummies/original/#{@instance.id}/5k.old.png"), File.expand_path(@attachment.path)
1149
1191
  end
1150
1192
 
@@ -1156,15 +1198,15 @@ describe Paperclip::Attachment do
1156
1198
  small: ["32x32#", :jpg]
1157
1199
  }
1158
1200
  @instance = Dummy.new
1159
- @instance.stubs(:id).returns 123
1160
- @file = File.new(fixture_file("5k.png"), 'rb')
1201
+ allow(@instance).to receive(:id).and_return 123
1202
+ @file = File.new(fixture_file("5k.png"), "rb")
1161
1203
  @attachment = @instance.avatar
1162
1204
  end
1163
1205
 
1164
1206
  context "and assigned a file" do
1165
1207
  before do
1166
1208
  now = Time.now
1167
- Time.stubs(:now).returns(now)
1209
+ allow(Time).to receive(:now).and_return(now)
1168
1210
  @attachment.assign(@file)
1169
1211
  end
1170
1212
 
@@ -1187,7 +1229,7 @@ describe Paperclip::Attachment do
1187
1229
  [[:large, 400, 61, "PNG"],
1188
1230
  [:medium, 100, 15, "GIF"],
1189
1231
  [:small, 32, 32, "JPEG"]].each do |style|
1190
- cmd = %Q[identify -format "%w %h %b %m" "#{@attachment.path(style.first)}"]
1232
+ cmd = %[identify -format "%w %h %b %m" "#{@attachment.path(style.first)}"]
1191
1233
  out = `#{cmd}`
1192
1234
  width, height, _size, format = out.split(" ")
1193
1235
  assert_equal style[1].to_s, width.to_s
@@ -1198,41 +1240,41 @@ describe Paperclip::Attachment do
1198
1240
 
1199
1241
  context "and trying to delete" do
1200
1242
  before do
1201
- @existing_names = @attachment.styles.keys.collect do |style|
1243
+ @existing_names = @attachment.styles.keys.map do |style|
1202
1244
  @attachment.path(style)
1203
1245
  end
1204
1246
  end
1205
1247
 
1206
1248
  it "deletes the files after assigning nil" do
1207
- @attachment.expects(:instance_write).with(:file_name, nil)
1208
- @attachment.expects(:instance_write).with(:content_type, nil)
1209
- @attachment.expects(:instance_write).with(:file_size, nil)
1210
- @attachment.expects(:instance_write).with(:fingerprint, nil)
1211
- @attachment.expects(:instance_write).with(:updated_at, nil)
1249
+ expect(@attachment).to receive(:instance_write).with(:file_name, nil)
1250
+ expect(@attachment).to receive(:instance_write).with(:content_type, nil)
1251
+ expect(@attachment).to receive(:instance_write).with(:file_size, nil)
1252
+ expect(@attachment).to receive(:instance_write).with(:fingerprint, nil)
1253
+ expect(@attachment).to receive(:instance_write).with(:updated_at, nil)
1212
1254
  @attachment.assign nil
1213
1255
  @attachment.save
1214
- @existing_names.each{|f| assert_file_not_exists(f) }
1256
+ @existing_names.each { |f| assert_file_not_exists(f) }
1215
1257
  end
1216
1258
 
1217
1259
  it "deletes the files when you call #clear and #save" do
1218
- @attachment.expects(:instance_write).with(:file_name, nil)
1219
- @attachment.expects(:instance_write).with(:content_type, nil)
1220
- @attachment.expects(:instance_write).with(:file_size, nil)
1221
- @attachment.expects(:instance_write).with(:fingerprint, nil)
1222
- @attachment.expects(:instance_write).with(:updated_at, nil)
1260
+ expect(@attachment).to receive(:instance_write).with(:file_name, nil)
1261
+ expect(@attachment).to receive(:instance_write).with(:content_type, nil)
1262
+ expect(@attachment).to receive(:instance_write).with(:file_size, nil)
1263
+ expect(@attachment).to receive(:instance_write).with(:fingerprint, nil)
1264
+ expect(@attachment).to receive(:instance_write).with(:updated_at, nil)
1223
1265
  @attachment.clear
1224
1266
  @attachment.save
1225
- @existing_names.each{|f| assert_file_not_exists(f) }
1267
+ @existing_names.each { |f| assert_file_not_exists(f) }
1226
1268
  end
1227
1269
 
1228
1270
  it "deletes the files when you call #delete" do
1229
- @attachment.expects(:instance_write).with(:file_name, nil)
1230
- @attachment.expects(:instance_write).with(:content_type, nil)
1231
- @attachment.expects(:instance_write).with(:file_size, nil)
1232
- @attachment.expects(:instance_write).with(:fingerprint, nil)
1233
- @attachment.expects(:instance_write).with(:updated_at, nil)
1271
+ expect(@attachment).to receive(:instance_write).with(:file_name, nil)
1272
+ expect(@attachment).to receive(:instance_write).with(:content_type, nil)
1273
+ expect(@attachment).to receive(:instance_write).with(:file_size, nil)
1274
+ expect(@attachment).to receive(:instance_write).with(:fingerprint, nil)
1275
+ expect(@attachment).to receive(:instance_write).with(:updated_at, nil)
1234
1276
  @attachment.destroy
1235
- @existing_names.each{|f| assert_file_not_exists(f) }
1277
+ @existing_names.each { |f| assert_file_not_exists(f) }
1236
1278
  end
1237
1279
 
1238
1280
  context "when keeping old files" do
@@ -1241,35 +1283,35 @@ describe Paperclip::Attachment do
1241
1283
  end
1242
1284
 
1243
1285
  it "keeps the files after assigning nil" do
1244
- @attachment.expects(:instance_write).with(:file_name, nil)
1245
- @attachment.expects(:instance_write).with(:content_type, nil)
1246
- @attachment.expects(:instance_write).with(:file_size, nil)
1247
- @attachment.expects(:instance_write).with(:fingerprint, nil)
1248
- @attachment.expects(:instance_write).with(:updated_at, nil)
1286
+ expect(@attachment).to receive(:instance_write).with(:file_name, nil)
1287
+ expect(@attachment).to receive(:instance_write).with(:content_type, nil)
1288
+ expect(@attachment).to receive(:instance_write).with(:file_size, nil)
1289
+ expect(@attachment).to receive(:instance_write).with(:fingerprint, nil)
1290
+ expect(@attachment).to receive(:instance_write).with(:updated_at, nil)
1249
1291
  @attachment.assign nil
1250
1292
  @attachment.save
1251
- @existing_names.each{|f| assert_file_exists(f) }
1293
+ @existing_names.each { |f| assert_file_exists(f) }
1252
1294
  end
1253
1295
 
1254
1296
  it "keeps the files when you call #clear and #save" do
1255
- @attachment.expects(:instance_write).with(:file_name, nil)
1256
- @attachment.expects(:instance_write).with(:content_type, nil)
1257
- @attachment.expects(:instance_write).with(:file_size, nil)
1258
- @attachment.expects(:instance_write).with(:fingerprint, nil)
1259
- @attachment.expects(:instance_write).with(:updated_at, nil)
1297
+ expect(@attachment).to receive(:instance_write).with(:file_name, nil)
1298
+ expect(@attachment).to receive(:instance_write).with(:content_type, nil)
1299
+ expect(@attachment).to receive(:instance_write).with(:file_size, nil)
1300
+ expect(@attachment).to receive(:instance_write).with(:fingerprint, nil)
1301
+ expect(@attachment).to receive(:instance_write).with(:updated_at, nil)
1260
1302
  @attachment.clear
1261
1303
  @attachment.save
1262
- @existing_names.each{|f| assert_file_exists(f) }
1304
+ @existing_names.each { |f| assert_file_exists(f) }
1263
1305
  end
1264
1306
 
1265
1307
  it "keeps the files when you call #delete" do
1266
- @attachment.expects(:instance_write).with(:file_name, nil)
1267
- @attachment.expects(:instance_write).with(:content_type, nil)
1268
- @attachment.expects(:instance_write).with(:file_size, nil)
1269
- @attachment.expects(:instance_write).with(:fingerprint, nil)
1270
- @attachment.expects(:instance_write).with(:updated_at, nil)
1308
+ expect(@attachment).to receive(:instance_write).with(:file_name, nil)
1309
+ expect(@attachment).to receive(:instance_write).with(:content_type, nil)
1310
+ expect(@attachment).to receive(:instance_write).with(:file_size, nil)
1311
+ expect(@attachment).to receive(:instance_write).with(:fingerprint, nil)
1312
+ expect(@attachment).to receive(:instance_write).with(:updated_at, nil)
1271
1313
  @attachment.destroy
1272
- @existing_names.each{|f| assert_file_exists(f) }
1314
+ @existing_names.each { |f| assert_file_exists(f) }
1273
1315
  end
1274
1316
  end
1275
1317
  end
@@ -1284,7 +1326,7 @@ describe Paperclip::Attachment do
1284
1326
  end
1285
1327
 
1286
1328
  it "is not able to find the module" do
1287
- assert_raises(Paperclip::Errors::StorageMethodNotFound){ Dummy.new.avatar }
1329
+ assert_raises(Paperclip::Errors::StorageMethodNotFound) { Dummy.new.avatar }
1288
1330
  end
1289
1331
  end
1290
1332
  end
@@ -1296,7 +1338,7 @@ describe Paperclip::Attachment do
1296
1338
  end
1297
1339
  rebuild_class
1298
1340
  @dummy = Dummy.new
1299
- @file = File.new(fixture_file("5k.png"), 'rb')
1341
+ @file = File.new(fixture_file("5k.png"), "rb")
1300
1342
  end
1301
1343
 
1302
1344
  after { @file.close }
@@ -1328,7 +1370,7 @@ describe Paperclip::Attachment do
1328
1370
 
1329
1371
  it "returns the creation time when sent #avatar_created_at" do
1330
1372
  now = Time.now
1331
- Time.stubs(:now).returns(now)
1373
+ allow(Time).to receive(:now).and_return(now)
1332
1374
  @dummy.avatar = @file
1333
1375
  assert_equal now.to_i, @dummy.avatar.created_at
1334
1376
  end
@@ -1336,9 +1378,9 @@ describe Paperclip::Attachment do
1336
1378
  it "returns the creation time when sent #avatar_created_at and the entry has been updated" do
1337
1379
  creation = 2.hours.ago
1338
1380
  now = Time.now
1339
- Time.stubs(:now).returns(creation)
1381
+ allow(Time).to receive(:now).and_return(creation)
1340
1382
  @dummy.avatar = @file
1341
- Time.stubs(:now).returns(now)
1383
+ allow(Time).to receive(:now).and_return(now)
1342
1384
  @dummy.avatar = @file
1343
1385
  assert_equal creation.to_i, @dummy.avatar.created_at
1344
1386
  assert_not_equal now.to_i, @dummy.avatar.created_at
@@ -1365,16 +1407,16 @@ describe Paperclip::Attachment do
1365
1407
 
1366
1408
  it "returns the right value when sent #avatar_updated_at" do
1367
1409
  now = Time.now
1368
- Time.stubs(:now).returns(now)
1410
+ allow(Time).to receive(:now).and_return(now)
1369
1411
  @dummy.avatar = @file
1370
1412
  assert_equal now.to_i, @dummy.avatar.updated_at
1371
1413
  end
1372
1414
  end
1373
1415
 
1374
1416
  it "does not calculate fingerprint" do
1375
- Digest::MD5.stubs(:file)
1417
+ allow(Digest::MD5).to receive(:file)
1376
1418
  @dummy.avatar = @file
1377
- expect(Digest::MD5).to have_received(:file).never
1419
+ expect(Digest::MD5).not_to have_received(:file)
1378
1420
  end
1379
1421
 
1380
1422
  it "does not assign fingerprint" do
@@ -1401,7 +1443,7 @@ describe Paperclip::Attachment do
1401
1443
 
1402
1444
  context "and avatar_file_size column" do
1403
1445
  before do
1404
- ActiveRecord::Base.connection.add_column :dummies, :avatar_file_size, :integer
1446
+ ActiveRecord::Base.connection.add_column :dummies, :avatar_file_size, :bigint
1405
1447
  rebuild_class
1406
1448
  @dummy = Dummy.new
1407
1449
  end
@@ -1482,7 +1524,7 @@ describe Paperclip::Attachment do
1482
1524
  before do
1483
1525
  rebuild_model preserve_files: true
1484
1526
  @dummy = Dummy.new
1485
- @file = File.new(fixture_file("5k.png"), 'rb')
1527
+ @file = File.new(fixture_file("5k.png"), "rb")
1486
1528
  @dummy.avatar = @file
1487
1529
  @dummy.save!
1488
1530
  @attachment = @dummy.avatar
@@ -1512,7 +1554,7 @@ describe Paperclip::Attachment do
1512
1554
  before do
1513
1555
  rebuild_model
1514
1556
  @dummy = Dummy.new
1515
- @file = File.new(fixture_file("5k.png"), 'rb')
1557
+ @file = File.new(fixture_file("5k.png"), "rb")
1516
1558
  @dummy.avatar = @file
1517
1559
  @dummy.save!
1518
1560
  @attachment = @dummy.avatar
@@ -1522,7 +1564,7 @@ describe Paperclip::Attachment do
1522
1564
  after { @file.close }
1523
1565
 
1524
1566
  it "is not deleted when the model fails to destroy" do
1525
- @dummy.stubs(:destroy).raises(Exception)
1567
+ allow(@dummy).to receive(:destroy).and_raise(Exception)
1526
1568
 
1527
1569
  assert_raises Exception do
1528
1570
  @dummy.destroy