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,44 +1,44 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip::MediaTypeSpoofDetector do
4
- it 'rejects a file that is named .html and identifies as PNG' do
4
+ it "rejects a file that is named .html and identifies as PNG" do
5
5
  file = File.open(fixture_file("5k.png"))
6
6
  assert Paperclip::MediaTypeSpoofDetector.using(file, "5k.html", "image/png").spoofed?
7
7
  end
8
8
 
9
- it 'does not reject a file that is named .jpg and identifies as PNG' do
9
+ it "does not reject a file that is named .jpg and identifies as PNG" do
10
10
  file = File.open(fixture_file("5k.png"))
11
- assert ! Paperclip::MediaTypeSpoofDetector.using(file, "5k.jpg", "image/png").spoofed?
11
+ assert !Paperclip::MediaTypeSpoofDetector.using(file, "5k.jpg", "image/png").spoofed?
12
12
  end
13
13
 
14
- it 'does not reject a file that is named .html and identifies as HTML' do
14
+ it "does not reject a file that is named .html and identifies as HTML" do
15
15
  file = File.open(fixture_file("empty.html"))
16
- assert ! Paperclip::MediaTypeSpoofDetector.using(file, "empty.html", "text/html").spoofed?
16
+ assert !Paperclip::MediaTypeSpoofDetector.using(file, "empty.html", "text/html").spoofed?
17
17
  end
18
18
 
19
- it 'does not reject a file that does not have a name' do
19
+ it "does not reject a file that does not have a name" do
20
20
  file = File.open(fixture_file("empty.html"))
21
- assert ! Paperclip::MediaTypeSpoofDetector.using(file, "", "text/html").spoofed?
21
+ assert !Paperclip::MediaTypeSpoofDetector.using(file, "", "text/html").spoofed?
22
22
  end
23
23
 
24
- it 'does not reject a file that does have an extension' do
24
+ it "does not reject a file that does have an extension" do
25
25
  file = File.open(fixture_file("empty.html"))
26
- assert ! Paperclip::MediaTypeSpoofDetector.using(file, "data", "text/html").spoofed?
26
+ assert !Paperclip::MediaTypeSpoofDetector.using(file, "data", "text/html").spoofed?
27
27
  end
28
28
 
29
- it 'does not reject when the supplied file is an IOAdapter' do
29
+ it "does not reject when the supplied file is an IOAdapter" do
30
30
  adapter = Paperclip.io_adapters.for(File.new(fixture_file("5k.png")))
31
- assert ! Paperclip::MediaTypeSpoofDetector.using(adapter, adapter.original_filename, adapter.content_type).spoofed?
31
+ assert !Paperclip::MediaTypeSpoofDetector.using(adapter, adapter.original_filename, adapter.content_type).spoofed?
32
32
  end
33
33
 
34
- it 'does not reject when the extension => content_type is in :content_type_mappings' do
34
+ it "does not reject when the extension => content_type is in :content_type_mappings" do
35
35
  begin
36
36
  Paperclip.options[:content_type_mappings] = { pem: "text/plain" }
37
37
  file = Tempfile.open(["test", ".PEM"])
38
38
  file.puts "Certificate!"
39
39
  file.close
40
- adapter = Paperclip.io_adapters.for(File.new(file.path));
41
- assert ! Paperclip::MediaTypeSpoofDetector.using(adapter, adapter.original_filename, adapter.content_type).spoofed?
40
+ adapter = Paperclip.io_adapters.for(File.new(file.path))
41
+ assert !Paperclip::MediaTypeSpoofDetector.using(adapter, adapter.original_filename, adapter.content_type).spoofed?
42
42
  ensure
43
43
  Paperclip.options[:content_type_mappings] = {}
44
44
  end
@@ -53,24 +53,50 @@ describe Paperclip::MediaTypeSpoofDetector do
53
53
  end
54
54
 
55
55
  it "logs info about the detected spoof" do
56
- Paperclip.expects(:log).with('Content Type Spoof: Filename empty.html (image/jpg from Headers, ["text/html"] from Extension), content type discovered from file command: text/html. See documentation to allow this combination.')
56
+ expect(Paperclip).to receive(:log).with('Content Type Spoof: Filename empty.html (image/jpg from Headers, ["text/html"] from Extension), content type discovered from file command: text/html. See documentation to allow this combination.')
57
57
  spoofed?
58
58
  end
59
59
  end
60
60
 
61
+ context "GIF file named without extension, but we're told GIF" do
62
+ let(:file) { File.open(fixture_file("animated")) }
63
+ let(:spoofed?) do
64
+ Paperclip::MediaTypeSpoofDetector.
65
+ using(file, "animated", "image/gif").
66
+ spoofed?
67
+ end
68
+
69
+ it "accepts the file" do
70
+ assert !spoofed?
71
+ end
72
+ end
73
+
74
+ context "GIF file named without extension, but we're told HTML" do
75
+ let(:file) { File.open(fixture_file("animated")) }
76
+ let(:spoofed?) do
77
+ Paperclip::MediaTypeSpoofDetector.
78
+ using(file, "animated", "text/html").
79
+ spoofed?
80
+ end
81
+
82
+ it "rejects the file" do
83
+ assert spoofed?
84
+ end
85
+ end
86
+
61
87
  it "does not reject if content_type is empty but otherwise checks out" do
62
88
  file = File.open(fixture_file("empty.html"))
63
- assert ! Paperclip::MediaTypeSpoofDetector.using(file, "empty.html", "").spoofed?
89
+ assert !Paperclip::MediaTypeSpoofDetector.using(file, "empty.html", "").spoofed?
64
90
  end
65
91
 
66
- it 'does allow array as :content_type_mappings' do
92
+ it "does allow array as :content_type_mappings" do
67
93
  begin
68
94
  Paperclip.options[:content_type_mappings] = {
69
- html: ['binary', 'text/html']
95
+ html: ["binary", "text/html"]
70
96
  }
71
- file = File.open(fixture_file('empty.html'))
72
- spoofed = Paperclip::MediaTypeSpoofDetector
73
- .using(file, "empty.html", "text/html").spoofed?
97
+ file = File.open(fixture_file("empty.html"))
98
+ spoofed = Paperclip::MediaTypeSpoofDetector.
99
+ using(file, "empty.html", "text/html").spoofed?
74
100
  assert !spoofed
75
101
  ensure
76
102
  Paperclip.options[:content_type_mappings] = {}
@@ -82,12 +108,12 @@ describe Paperclip::MediaTypeSpoofDetector do
82
108
  let(:detector) { Paperclip::MediaTypeSpoofDetector.new(file, "html", "") }
83
109
 
84
110
  it "does work with the output of old versions of file" do
85
- Paperclip.stubs(:run).returns("text/html charset=us-ascii")
111
+ allow(Paperclip).to receive(:run).and_return("text/html charset=us-ascii")
86
112
  expect(detector.send(:type_from_file_command)).to eq("text/html")
87
113
  end
88
114
 
89
115
  it "does work with the output of new versions of file" do
90
- Paperclip.stubs(:run).returns("text/html; charset=us-ascii")
116
+ allow(Paperclip).to receive(:run).and_return("text/html; charset=us-ascii")
91
117
  expect(detector.send(:type_from_file_command)).to eq("text/html")
92
118
  end
93
119
  end
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe 'Metaclasses' do
3
+ describe "Metaclasses" do
4
4
  context "A meta-class of dummy" do
5
5
  if active_support_version >= "4.1" || ruby_version < "2.1"
6
6
  before do
@@ -21,7 +21,7 @@ describe 'Metaclasses' do
21
21
  rebuild_meta_class_of(@dummy)
22
22
 
23
23
  assert_nothing_raised do
24
- @dummy.avatar = File.new(fixture_file("5k.png"), 'rb')
24
+ @dummy.avatar = File.new(fixture_file("5k.png"), "rb")
25
25
  end
26
26
  assert @dummy.save
27
27
  end
@@ -1,59 +1,63 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe 'Missing Attachment Styles' do
3
+ describe "Missing Attachment Styles" do
4
4
  before do
5
5
  Paperclip::AttachmentRegistry.clear
6
6
  end
7
7
 
8
8
  after do
9
- File.unlink(Paperclip.registered_attachments_styles_path) rescue nil
9
+ begin
10
+ File.unlink(Paperclip.registered_attachments_styles_path)
11
+ rescue StandardError
12
+ nil
13
+ end
10
14
  end
11
15
 
12
16
  it "enables to get and set path to registered styles file" do
13
- assert_equal ROOT.join('tmp/public/system/paperclip_attachments.yml').to_s, Paperclip.registered_attachments_styles_path
14
- Paperclip.registered_attachments_styles_path = '/tmp/config/paperclip_attachments.yml'
15
- assert_equal '/tmp/config/paperclip_attachments.yml', Paperclip.registered_attachments_styles_path
17
+ assert_equal ROOT.join("tmp/public/system/paperclip_attachments.yml").to_s, Paperclip.registered_attachments_styles_path
18
+ Paperclip.registered_attachments_styles_path = "/tmp/config/paperclip_attachments.yml"
19
+ assert_equal "/tmp/config/paperclip_attachments.yml", Paperclip.registered_attachments_styles_path
16
20
  Paperclip.registered_attachments_styles_path = nil
17
- assert_equal ROOT.join('tmp/public/system/paperclip_attachments.yml').to_s, Paperclip.registered_attachments_styles_path
21
+ assert_equal ROOT.join("tmp/public/system/paperclip_attachments.yml").to_s, Paperclip.registered_attachments_styles_path
18
22
  end
19
23
 
20
24
  it "is able to get current attachment styles" do
21
25
  assert_equal Hash.new, Paperclip.send(:current_attachments_styles)
22
- rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'}
23
- expected_hash = { Dummy: {avatar: [:big, :croppable]}}
26
+ rebuild_model styles: { croppable: "600x600>", big: "1000x1000>" }
27
+ expected_hash = { Dummy: { avatar: [:big, :croppable] } }
24
28
  assert_equal expected_hash, Paperclip.send(:current_attachments_styles)
25
29
  end
26
30
 
27
31
  it "is able to save current attachment styles for further comparison" do
28
- rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'}
32
+ rebuild_model styles: { croppable: "600x600>", big: "1000x1000>" }
29
33
  Paperclip.save_current_attachments_styles!
30
- expected_hash = { Dummy: {avatar: [:big, :croppable]}}
34
+ expected_hash = { Dummy: { avatar: [:big, :croppable] } }
31
35
  assert_equal expected_hash, YAML.load_file(Paperclip.registered_attachments_styles_path)
32
36
  end
33
37
 
34
38
  it "is able to read registered attachment styles from file" do
35
- rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'}
39
+ rebuild_model styles: { croppable: "600x600>", big: "1000x1000>" }
36
40
  Paperclip.save_current_attachments_styles!
37
- expected_hash = { Dummy: {avatar: [:big, :croppable]}}
41
+ expected_hash = { Dummy: { avatar: [:big, :croppable] } }
38
42
  assert_equal expected_hash, Paperclip.send(:get_registered_attachments_styles)
39
43
  end
40
44
 
41
45
  it "is able to calculate differences between registered styles and current styles" do
42
- rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'}
46
+ rebuild_model styles: { croppable: "600x600>", big: "1000x1000>" }
43
47
  Paperclip.save_current_attachments_styles!
44
- rebuild_model styles: {thumb: 'x100', export: 'x400>', croppable: '600x600>', big: '1000x1000>'}
45
- expected_hash = { Dummy: {avatar: [:export, :thumb]} }
48
+ rebuild_model styles: { thumb: "x100", export: "x400>", croppable: "600x600>", big: "1000x1000>" }
49
+ expected_hash = { Dummy: { avatar: [:export, :thumb] } }
46
50
  assert_equal expected_hash, Paperclip.missing_attachments_styles
47
51
 
48
52
  ActiveRecord::Base.connection.create_table :books, force: true
49
53
  class ::Book < ActiveRecord::Base
50
- has_attached_file :cover, styles: {small: 'x100', large: '1000x1000>'}
51
- has_attached_file :sample, styles: {thumb: 'x100'}
54
+ has_attached_file :cover, styles: { small: "x100", large: "1000x1000>" }
55
+ has_attached_file :sample, styles: { thumb: "x100" }
52
56
  end
53
57
 
54
58
  expected_hash = {
55
- Dummy: {avatar: [:export, :thumb]},
56
- Book: {sample: [:thumb], cover: [:large, :small]}
59
+ Dummy: { avatar: [:export, :thumb] },
60
+ Book: { sample: [:thumb], cover: [:large, :small] }
57
61
  }
58
62
  assert_equal expected_hash, Paperclip.missing_attachments_styles
59
63
  Paperclip.save_current_attachments_styles!
@@ -61,15 +65,15 @@ describe 'Missing Attachment Styles' do
61
65
  end
62
66
 
63
67
  it "is able to calculate differences when a new attachment is added to a model" do
64
- rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'}
68
+ rebuild_model styles: { croppable: "600x600>", big: "1000x1000>" }
65
69
  Paperclip.save_current_attachments_styles!
66
70
 
67
71
  class ::Dummy
68
- has_attached_file :photo, styles: {small: 'x100', large: '1000x1000>'}
72
+ has_attached_file :photo, styles: { small: "x100", large: "1000x1000>" }
69
73
  end
70
74
 
71
75
  expected_hash = {
72
- Dummy: {photo: [:large, :small]}
76
+ Dummy: { photo: [:large, :small] }
73
77
  }
74
78
  assert_equal expected_hash, Paperclip.missing_attachments_styles
75
79
  Paperclip.save_current_attachments_styles!
@@ -78,7 +82,7 @@ describe 'Missing Attachment Styles' do
78
82
 
79
83
  # It's impossible to build styles hash without loading from database whole bunch of records
80
84
  it "skips lambda-styles" do
81
- rebuild_model styles: lambda{ |attachment| attachment.instance.other == 'a' ? {thumb: "50x50#"} : {large: "400x400"} }
85
+ rebuild_model styles: lambda { |attachment| attachment.instance.other == "a" ? { thumb: "50x50#" } : { large: "400x400" } }
82
86
  assert_equal Hash.new, Paperclip.send(:current_attachments_styles)
83
87
  end
84
88
  end
@@ -1,10 +1,10 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip do
4
4
  context ".run" do
5
5
  before do
6
6
  Paperclip.options[:log_command] = false
7
- Terrapin::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))
7
+ expect(Terrapin::CommandLine).to receive(:new).with("convert", "stuff", {}).and_return(double(run: nil))
8
8
  @original_command_line_path = Terrapin::CommandLine.path
9
9
  end
10
10
 
@@ -24,7 +24,7 @@ describe Paperclip do
24
24
  end
25
25
 
26
26
  it "does not duplicate Terrapin::CommandLine.path on multiple runs" do
27
- Terrapin::CommandLine.expects(:new).with("convert", "more_stuff", {}).returns(stub(:run))
27
+ expect(Terrapin::CommandLine).to receive(:new).with("convert", "more_stuff", {}).and_return(double(run: nil))
28
28
  Terrapin::CommandLine.path = nil
29
29
  Paperclip.options[:command_path] = "/opt/my_app/bin"
30
30
  Paperclip.run("convert", "stuff")
@@ -35,7 +35,7 @@ describe Paperclip do
35
35
  end
36
36
  end
37
37
 
38
- it 'does not raise errors when doing a lot of running' do
38
+ it "does not raise errors when doing a lot of running" do
39
39
  Paperclip.options[:command_path] = ["/usr/local/bin"] * 1024
40
40
  Terrapin::CommandLine.path = "/something/else"
41
41
  100.times do |x|
@@ -56,21 +56,21 @@ describe Paperclip do
56
56
 
57
57
  it "does not raise an error when log is called" do
58
58
  silence_stream(STDOUT) do
59
- Paperclip.log('something')
59
+ Paperclip.log("something")
60
60
  end
61
61
  end
62
62
  end
63
63
  context "Calling Paperclip.run with a logger" do
64
64
  it "passes the defined logger if :log_command is set" do
65
65
  Paperclip.options[:log_command] = true
66
- Terrapin::CommandLine.expects(:new).with("convert", "stuff", logger: Paperclip.logger).returns(stub(:run))
66
+ expect(Terrapin::CommandLine).to receive(:new).with("convert", "stuff", logger: Paperclip.logger).and_return(double(run: nil))
67
67
  Paperclip.run("convert", "stuff")
68
68
  end
69
69
  end
70
70
 
71
71
  context "Paperclip.each_instance_with_attachment" do
72
72
  before do
73
- @file = File.new(fixture_file("5k.png"), 'rb')
73
+ @file = File.new(fixture_file("5k.png"), "rb")
74
74
  d1 = Dummy.create(avatar: @file)
75
75
  d2 = Dummy.create
76
76
  d3 = Dummy.create(avatar: @file)
@@ -89,7 +89,7 @@ describe Paperclip do
89
89
  end
90
90
 
91
91
  it "raises when sent #processor and the name of a class that doesn't exist" do
92
- assert_raises(LoadError){ Paperclip.processor(:boogey_man) }
92
+ assert_raises(LoadError) { Paperclip.processor(:boogey_man) }
93
93
  end
94
94
 
95
95
  it "returns a class when sent #processor and the name of a class under Paperclip" do
@@ -112,7 +112,7 @@ describe Paperclip do
112
112
  context "An ActiveRecord model with an 'avatar' attachment" do
113
113
  before do
114
114
  rebuild_model path: "tmp/:class/omg/:style.:extension"
115
- @file = File.new(fixture_file("5k.png"), 'rb')
115
+ @file = File.new(fixture_file("5k.png"), "rb")
116
116
  end
117
117
 
118
118
  after { @file.close }
@@ -138,7 +138,11 @@ describe Paperclip do
138
138
 
139
139
  after do
140
140
  SubDummy.delete_all
141
- Object.send(:remove_const, "SubDummy") rescue nil
141
+ begin
142
+ Object.send(:remove_const, "SubDummy")
143
+ rescue StandardError
144
+ nil
145
+ end
142
146
  end
143
147
  end
144
148
 
@@ -171,7 +175,7 @@ describe Paperclip do
171
175
  context "configuring a custom processor" do
172
176
  before do
173
177
  @freedom_processor = Class.new do
174
- def make(file, options = {}, attachment = nil)
178
+ def make(file, _options = {}, _attachment = nil)
175
179
  file
176
180
  end
177
181
  end.new
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe 'Plural cache' do
4
- it 'caches pluralizations' do
3
+ describe "Plural cache" do
4
+ it "caches pluralizations" do
5
5
  cache = Paperclip::Interpolations::PluralCache.new
6
6
  symbol = :box
7
7
 
@@ -10,8 +10,8 @@ describe 'Plural cache' do
10
10
  expect(first).to equal(second)
11
11
  end
12
12
 
13
- it 'caches pluralizations and underscores' do
14
- class BigBox ; end
13
+ it "caches pluralizations and underscores" do
14
+ class BigBox; end
15
15
  cache = Paperclip::Interpolations::PluralCache.new
16
16
  klass = BigBox
17
17
 
@@ -20,15 +20,15 @@ describe 'Plural cache' do
20
20
  expect(first).to equal(second)
21
21
  end
22
22
 
23
- it 'pluralizes words' do
23
+ it "pluralizes words" do
24
24
  cache = Paperclip::Interpolations::PluralCache.new
25
25
  symbol = :box
26
26
 
27
27
  expect(cache.pluralize_symbol(symbol)).to eq("boxes")
28
28
  end
29
29
 
30
- it 'pluralizes and underscore class names' do
31
- class BigBox ; end
30
+ it "pluralizes and underscore class names" do
31
+ class BigBox; end
32
32
  cache = Paperclip::Interpolations::PluralCache.new
33
33
  klass = BigBox
34
34
 
@@ -1,54 +1,54 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip::ProcessorHelpers do
4
- describe '.load_processor' do
5
- context 'when the file exists in lib/paperclip' do
6
- it 'loads it correctly' do
7
- pathname = Pathname.new('my_app')
8
- main_path = 'main_path'
9
- alternate_path = 'alternate_path'
4
+ describe ".load_processor" do
5
+ context "when the file exists in lib/paperclip" do
6
+ it "loads it correctly" do
7
+ pathname = Pathname.new("my_app")
8
+ main_path = "main_path"
9
+ alternate_path = "alternate_path"
10
10
 
11
- Rails.stubs(:root).returns(pathname)
12
- File.expects(:expand_path).with(pathname.join('lib/paperclip', 'custom.rb')).returns(main_path)
13
- File.expects(:expand_path).with(pathname.join('lib/paperclip_processors', 'custom.rb')).returns(alternate_path)
14
- File.expects(:exist?).with(main_path).returns(true)
15
- File.expects(:exist?).with(alternate_path).returns(false)
11
+ allow(Rails).to receive(:root).and_return(pathname)
12
+ expect(File).to receive(:expand_path).with(pathname.join("lib/paperclip", "custom.rb")).and_return(main_path)
13
+ expect(File).to receive(:expand_path).with(pathname.join("lib/paperclip_processors", "custom.rb")).and_return(alternate_path)
14
+ expect(File).to receive(:exist?).with(main_path).and_return(true)
15
+ expect(File).to receive(:exist?).with(alternate_path).and_return(false)
16
16
 
17
- Paperclip.expects(:require).with(main_path)
17
+ expect(Paperclip).to receive(:require).with(main_path)
18
18
 
19
19
  Paperclip.load_processor(:custom)
20
20
  end
21
21
  end
22
22
 
23
- context 'when the file exists in lib/paperclip_processors' do
24
- it 'loads it correctly' do
25
- pathname = Pathname.new('my_app')
26
- main_path = 'main_path'
27
- alternate_path = 'alternate_path'
23
+ context "when the file exists in lib/paperclip_processors" do
24
+ it "loads it correctly" do
25
+ pathname = Pathname.new("my_app")
26
+ main_path = "main_path"
27
+ alternate_path = "alternate_path"
28
28
 
29
- Rails.stubs(:root).returns(pathname)
30
- File.expects(:expand_path).with(pathname.join('lib/paperclip', 'custom.rb')).returns(main_path)
31
- File.expects(:expand_path).with(pathname.join('lib/paperclip_processors', 'custom.rb')).returns(alternate_path)
32
- File.expects(:exist?).with(main_path).returns(false)
33
- File.expects(:exist?).with(alternate_path).returns(true)
29
+ allow(Rails).to receive(:root).and_return(pathname)
30
+ expect(File).to receive(:expand_path).with(pathname.join("lib/paperclip", "custom.rb")).and_return(main_path)
31
+ expect(File).to receive(:expand_path).with(pathname.join("lib/paperclip_processors", "custom.rb")).and_return(alternate_path)
32
+ expect(File).to receive(:exist?).with(main_path).and_return(false)
33
+ expect(File).to receive(:exist?).with(alternate_path).and_return(true)
34
34
 
35
- Paperclip.expects(:require).with(alternate_path)
35
+ expect(Paperclip).to receive(:require).with(alternate_path)
36
36
 
37
37
  Paperclip.load_processor(:custom)
38
38
  end
39
39
  end
40
40
 
41
- context 'when the file does not exist in lib/paperclip_processors' do
42
- it 'raises an error' do
43
- pathname = Pathname.new('my_app')
44
- main_path = 'main_path'
45
- alternate_path = 'alternate_path'
46
-
47
- Rails.stubs(:root).returns(pathname)
48
- File.stubs(:expand_path).with(pathname.join('lib/paperclip', 'custom.rb')).returns(main_path)
49
- File.stubs(:expand_path).with(pathname.join('lib/paperclip_processors', 'custom.rb')).returns(alternate_path)
50
- File.stubs(:exist?).with(main_path).returns(false)
51
- File.stubs(:exist?).with(alternate_path).returns(false)
41
+ context "when the file does not exist in lib/paperclip_processors" do
42
+ it "raises an error" do
43
+ pathname = Pathname.new("my_app")
44
+ main_path = "main_path"
45
+ alternate_path = "alternate_path"
46
+
47
+ allow(Rails).to receive(:root).and_return(pathname)
48
+ allow(File).to receive(:expand_path).with(pathname.join("lib/paperclip", "custom.rb")).and_return(main_path)
49
+ allow(File).to receive(:expand_path).with(pathname.join("lib/paperclip_processors", "custom.rb")).and_return(alternate_path)
50
+ allow(File).to receive(:exist?).with(main_path).and_return(false)
51
+ allow(File).to receive(:exist?).with(alternate_path).and_return(false)
52
52
 
53
53
  assert_raises(LoadError) { Paperclip.processor(:custom) }
54
54
  end
@@ -1,26 +1,26 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip::Processor do
4
4
  it "instantiates and call #make when sent #make to the class" do
5
- processor = mock
6
- processor.expects(:make).with()
7
- Paperclip::Processor.expects(:new).with(:one, :two, :three).returns(processor)
5
+ processor = double
6
+ expect(processor).to receive(:make)
7
+ expect(Paperclip::Processor).to receive(:new).with(:one, :two, :three).and_return(processor)
8
8
  Paperclip::Processor.make(:one, :two, :three)
9
9
  end
10
10
 
11
11
  context "Calling #convert" do
12
12
  it "runs the convert command with Terrapin" do
13
13
  Paperclip.options[:log_command] = false
14
- Terrapin::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))
15
- Paperclip::Processor.new('filename').convert("stuff")
14
+ expect(Terrapin::CommandLine).to receive(:new).with("convert", "stuff", {}).and_return(double(run: nil))
15
+ Paperclip::Processor.new("filename").convert("stuff")
16
16
  end
17
17
  end
18
18
 
19
19
  context "Calling #identify" do
20
20
  it "runs the identify command with Terrapin" do
21
21
  Paperclip.options[:log_command] = false
22
- Terrapin::CommandLine.expects(:new).with("identify", "stuff", {}).returns(stub(:run))
23
- Paperclip::Processor.new('filename').identify("stuff")
22
+ expect(Terrapin::CommandLine).to receive(:new).with("identify", "stuff", {}).and_return(double(run: nil))
23
+ Paperclip::Processor.new("filename").identify("stuff")
24
24
  end
25
25
  end
26
26
  end
@@ -1,7 +1,6 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip::RailsEnvironment do
4
-
5
4
  it "returns nil when Rails isn't defined" do
6
5
  resetting_rails_to(nil) do
7
6
  expect(Paperclip::RailsEnvironment.get).to be_nil
@@ -21,13 +20,11 @@ describe Paperclip::RailsEnvironment do
21
20
  end
22
21
 
23
22
  def resetting_rails_to(new_value)
24
- begin
25
- previous_rails = Object.send(:remove_const, "Rails")
26
- Object.const_set("Rails", new_value) unless new_value.nil?
27
- yield
28
- ensure
29
- Object.send(:remove_const, "Rails") if Object.const_defined?("Rails")
30
- Object.const_set("Rails", previous_rails)
31
- end
23
+ previous_rails = Object.send(:remove_const, "Rails")
24
+ Object.const_set("Rails", new_value) unless new_value.nil?
25
+ yield
26
+ ensure
27
+ Object.send(:remove_const, "Rails") if Object.const_defined?("Rails")
28
+ Object.const_set("Rails", previous_rails)
32
29
  end
33
30
  end