jr-paperclip 8.0.1 → 8.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS +9 -0
  3. data/lib/paperclip/thumbnail.rb +18 -15
  4. data/lib/paperclip/version.rb +1 -1
  5. metadata +3 -245
  6. data/.github/FUNDING.yml +0 -3
  7. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -18
  8. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  9. data/.github/workflows/reviewdog.yml +0 -23
  10. data/.github/workflows/tests.yml +0 -56
  11. data/.gitignore +0 -19
  12. data/.qlty/.gitignore +0 -7
  13. data/.qlty/qlty.toml +0 -89
  14. data/Appraisals +0 -29
  15. data/Gemfile +0 -18
  16. data/bin/console +0 -11
  17. data/features/basic_integration.feature +0 -112
  18. data/features/migration.feature +0 -29
  19. data/features/rake_tasks.feature +0 -62
  20. data/features/step_definitions/attachment_steps.rb +0 -138
  21. data/features/step_definitions/html_steps.rb +0 -15
  22. data/features/step_definitions/rails_steps.rb +0 -271
  23. data/features/step_definitions/s3_steps.rb +0 -16
  24. data/features/step_definitions/web_steps.rb +0 -106
  25. data/features/support/env.rb +0 -12
  26. data/features/support/file_helpers.rb +0 -34
  27. data/features/support/fixtures/boot_config.txt +0 -15
  28. data/features/support/fixtures/gemfile.txt +0 -5
  29. data/features/support/fixtures/preinitializer.txt +0 -20
  30. data/features/support/paths.rb +0 -28
  31. data/features/support/rails.rb +0 -39
  32. data/features/support/selectors.rb +0 -19
  33. data/features/support/webmock_setup.rb +0 -8
  34. data/gemfiles/7.0.gemfile +0 -21
  35. data/gemfiles/7.1.gemfile +0 -21
  36. data/gemfiles/7.2.gemfile +0 -21
  37. data/gemfiles/8.0.gemfile +0 -21
  38. data/gemfiles/8.1.gemfile +0 -21
  39. data/paperclip.gemspec +0 -52
  40. data/spec/database.yml +0 -4
  41. data/spec/paperclip/attachment_definitions_spec.rb +0 -313
  42. data/spec/paperclip/attachment_processing_spec.rb +0 -79
  43. data/spec/paperclip/attachment_registry_spec.rb +0 -158
  44. data/spec/paperclip/attachment_spec.rb +0 -1617
  45. data/spec/paperclip/content_type_detector_spec.rb +0 -58
  46. data/spec/paperclip/file_command_content_type_detector_spec.rb +0 -40
  47. data/spec/paperclip/filename_cleaner_spec.rb +0 -13
  48. data/spec/paperclip/geometry_detector_spec.rb +0 -96
  49. data/spec/paperclip/geometry_parser_spec.rb +0 -73
  50. data/spec/paperclip/geometry_spec.rb +0 -270
  51. data/spec/paperclip/glue_spec.rb +0 -63
  52. data/spec/paperclip/has_attached_file_spec.rb +0 -78
  53. data/spec/paperclip/helpers_spec.rb +0 -49
  54. data/spec/paperclip/integration_spec.rb +0 -702
  55. data/spec/paperclip/interpolations_spec.rb +0 -270
  56. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +0 -160
  57. data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +0 -167
  58. data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +0 -88
  59. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +0 -17
  60. data/spec/paperclip/io_adapters/file_adapter_spec.rb +0 -134
  61. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +0 -142
  62. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +0 -8
  63. data/spec/paperclip/io_adapters/nil_adapter_spec.rb +0 -25
  64. data/spec/paperclip/io_adapters/registry_spec.rb +0 -35
  65. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +0 -64
  66. data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +0 -146
  67. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +0 -231
  68. data/spec/paperclip/lazy_thumbnail_compatibility_spec.rb +0 -266
  69. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +0 -19
  70. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +0 -108
  71. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +0 -69
  72. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +0 -88
  73. data/spec/paperclip/media_type_spoof_detector_spec.rb +0 -126
  74. data/spec/paperclip/meta_class_spec.rb +0 -30
  75. data/spec/paperclip/migration_guide_example_spec.rb +0 -44
  76. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +0 -88
  77. data/spec/paperclip/paperclip_spec.rb +0 -196
  78. data/spec/paperclip/plural_cache_spec.rb +0 -37
  79. data/spec/paperclip/processor_helpers_spec.rb +0 -57
  80. data/spec/paperclip/processor_spec.rb +0 -60
  81. data/spec/paperclip/rails_environment_spec.rb +0 -30
  82. data/spec/paperclip/rake_spec.rb +0 -103
  83. data/spec/paperclip/schema_spec.rb +0 -298
  84. data/spec/paperclip/storage/filesystem_spec.rb +0 -102
  85. data/spec/paperclip/storage/fog_spec.rb +0 -606
  86. data/spec/paperclip/storage/s3_live_spec.rb +0 -188
  87. data/spec/paperclip/storage/s3_spec.rb +0 -1974
  88. data/spec/paperclip/style_spec.rb +0 -309
  89. data/spec/paperclip/tempfile_factory_spec.rb +0 -33
  90. data/spec/paperclip/tempfile_spec.rb +0 -35
  91. data/spec/paperclip/thumbnail_custom_options_spec.rb +0 -225
  92. data/spec/paperclip/thumbnail_loader_options_spec.rb +0 -53
  93. data/spec/paperclip/thumbnail_security_spec.rb +0 -42
  94. data/spec/paperclip/thumbnail_spec.rb +0 -1460
  95. data/spec/paperclip/url_generator_spec.rb +0 -231
  96. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +0 -410
  97. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +0 -249
  98. data/spec/paperclip/validators/attachment_presence_validator_spec.rb +0 -85
  99. data/spec/paperclip/validators/attachment_size_validator_spec.rb +0 -325
  100. data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +0 -48
  101. data/spec/paperclip/validators_spec.rb +0 -179
  102. data/spec/spec_helper.rb +0 -52
  103. data/spec/support/assertions.rb +0 -84
  104. data/spec/support/fake_model.rb +0 -24
  105. data/spec/support/fake_rails.rb +0 -12
  106. data/spec/support/fixtures/12k.png +0 -0
  107. data/spec/support/fixtures/50x50.png +0 -0
  108. data/spec/support/fixtures/5k.png +0 -0
  109. data/spec/support/fixtures/animated +0 -0
  110. data/spec/support/fixtures/animated.gif +0 -0
  111. data/spec/support/fixtures/animated.unknown +0 -0
  112. data/spec/support/fixtures/aws_s3.yml +0 -13
  113. data/spec/support/fixtures/bad.png +0 -1
  114. data/spec/support/fixtures/empty.html +0 -1
  115. data/spec/support/fixtures/empty.xlsx +0 -0
  116. data/spec/support/fixtures/fog.yml +0 -8
  117. data/spec/support/fixtures/rotated.jpg +0 -0
  118. data/spec/support/fixtures/s3.yml +0 -8
  119. data/spec/support/fixtures/sample.xlsm +0 -0
  120. data/spec/support/fixtures/spaced file.jpg +0 -0
  121. data/spec/support/fixtures/spaced file.png +0 -0
  122. data/spec/support/fixtures/text.txt +0 -1
  123. data/spec/support/fixtures/twopage.pdf +0 -0
  124. data/spec/support/fixtures/uppercase.PNG +0 -0
  125. data/spec/support/matchers/accept.rb +0 -5
  126. data/spec/support/matchers/exist.rb +0 -5
  127. data/spec/support/matchers/have_column.rb +0 -23
  128. data/spec/support/mock_attachment.rb +0 -24
  129. data/spec/support/mock_interpolator.rb +0 -24
  130. data/spec/support/mock_url_generator_builder.rb +0 -26
  131. data/spec/support/model_reconstruction.rb +0 -72
  132. data/spec/support/reporting.rb +0 -11
  133. data/spec/support/test_data.rb +0 -13
  134. data/spec/support/version_helper.rb +0 -9
@@ -1,313 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Attachment Definitions" do
4
- it "returns all of the attachments on the class" do
5
- reset_class "Dummy"
6
- Dummy.has_attached_file :avatar, path: "abc"
7
- Dummy.has_attached_file :other_attachment, url: "123"
8
- Dummy.do_not_validate_attachment_file_type :avatar
9
- expected = { avatar: { path: "abc" }, other_attachment: { url: "123" } }
10
-
11
- expect(Dummy.attachment_definitions).to eq expected
12
- end
13
-
14
- describe "configuration isolation between models" do
15
- # Helper method to safely remove a constant and clean up its registry entries
16
- def cleanup_model(class_name)
17
- return unless Object.const_defined?(class_name)
18
-
19
- # Remove from Paperclip's AttachmentRegistry to prevent test pollution
20
- Paperclip::AttachmentRegistry.clear
21
- # Remove the constant
22
- Object.send(:remove_const, class_name)
23
- end
24
-
25
- before do
26
- # Clean up any existing class definitions before each test
27
- cleanup_model(:ModelA)
28
- cleanup_model(:ModelB)
29
-
30
- # Create table for ModelA
31
- ActiveRecord::Migration.create_table :model_as, force: true do |table|
32
- table.column :attachment_file_name, :string
33
- table.column :attachment_content_type, :string
34
- table.column :attachment_file_size, :bigint
35
- table.column :attachment_updated_at, :datetime
36
- end
37
-
38
- # Create table for ModelB
39
- ActiveRecord::Migration.create_table :model_bs, force: true do |table|
40
- table.column :attachment_file_name, :string
41
- table.column :attachment_content_type, :string
42
- table.column :attachment_file_size, :bigint
43
- table.column :attachment_updated_at, :datetime
44
- end
45
- end
46
-
47
- after do
48
- # Clean up model classes to prevent test pollution
49
- cleanup_model(:ModelA)
50
- cleanup_model(:ModelB)
51
-
52
- # Drop tables
53
- ActiveRecord::Migration.drop_table :model_as, if_exists: true
54
- ActiveRecord::Migration.drop_table :model_bs, if_exists: true
55
- end
56
-
57
- it "does not mutate default_options when configuring multiple models" do
58
- # Capture original values of mutable options
59
- original_path = Paperclip::Attachment.default_options[:path].dup
60
- original_url = Paperclip::Attachment.default_options[:url].dup
61
- original_default_url = Paperclip::Attachment.default_options[:default_url].dup
62
- original_styles = Paperclip::Attachment.default_options[:styles].deep_dup
63
- original_convert_options = Paperclip::Attachment.default_options[:convert_options].deep_dup
64
-
65
- # Define ModelA with specific configuration
66
- class ::ModelA < ActiveRecord::Base
67
- include Paperclip::Glue
68
- has_attached_file :attachment,
69
- path: "/model_a/:filename",
70
- styles: { thumb: "100x100" }
71
- do_not_validate_attachment_file_type :attachment
72
- end
73
-
74
- # Define ModelB with different configuration
75
- class ::ModelB < ActiveRecord::Base
76
- include Paperclip::Glue
77
- has_attached_file :attachment,
78
- path: "/model_b/:filename",
79
- styles: { large: "500x500" }
80
- do_not_validate_attachment_file_type :attachment
81
- end
82
-
83
- # Verify default_options was not mutated
84
- expect(Paperclip::Attachment.default_options[:path]).to eq original_path
85
- expect(Paperclip::Attachment.default_options[:url]).to eq original_url
86
- expect(Paperclip::Attachment.default_options[:default_url]).to eq original_default_url
87
- expect(Paperclip::Attachment.default_options[:styles]).to eq original_styles
88
- expect(Paperclip::Attachment.default_options[:convert_options]).to eq original_convert_options
89
- end
90
-
91
- it "keeps attachment configurations isolated between models" do
92
- # Define ModelA with specific configuration
93
- class ::ModelA < ActiveRecord::Base
94
- include Paperclip::Glue
95
- has_attached_file :attachment,
96
- path: "/model_a/:filename",
97
- styles: { thumb: "100x100" },
98
- default_url: "/missing_a.png"
99
- do_not_validate_attachment_file_type :attachment
100
- end
101
-
102
- # Define ModelB with different configuration
103
- class ::ModelB < ActiveRecord::Base
104
- include Paperclip::Glue
105
- has_attached_file :attachment,
106
- path: "/model_b/:filename",
107
- styles: { large: "500x500" },
108
- default_url: "/missing_b.png"
109
- do_not_validate_attachment_file_type :attachment
110
- end
111
-
112
- # Create instances and access attachments
113
- model_a = ModelA.new
114
- model_b = ModelB.new
115
-
116
- # Access attachment on ModelA first
117
- attachment_a = model_a.attachment
118
-
119
- # Access attachment on ModelB
120
- attachment_b = model_b.attachment
121
-
122
- # Verify configurations are isolated
123
- expect(attachment_a.options[:path]).to eq "/model_a/:filename"
124
- expect(attachment_a.options[:styles]).to eq({ thumb: "100x100" })
125
- expect(attachment_a.options[:default_url]).to eq "/missing_a.png"
126
-
127
- expect(attachment_b.options[:path]).to eq "/model_b/:filename"
128
- expect(attachment_b.options[:styles]).to eq({ large: "500x500" })
129
- expect(attachment_b.options[:default_url]).to eq "/missing_b.png"
130
-
131
- # Verify attachment_definitions are also isolated
132
- expect(ModelA.attachment_definitions[:attachment][:path]).to eq "/model_a/:filename"
133
- expect(ModelB.attachment_definitions[:attachment][:path]).to eq "/model_b/:filename"
134
- end
135
-
136
- it "does not leak configuration when accessing attachments in different order" do
137
- # Define ModelA with specific configuration
138
- class ::ModelA < ActiveRecord::Base
139
- include Paperclip::Glue
140
- has_attached_file :attachment,
141
- path: "/model_a/:filename",
142
- styles: { thumb: "100x100" }
143
- do_not_validate_attachment_file_type :attachment
144
- end
145
-
146
- # Define ModelB with different configuration
147
- class ::ModelB < ActiveRecord::Base
148
- include Paperclip::Glue
149
- has_attached_file :attachment,
150
- path: "/model_b/:filename",
151
- styles: { large: "500x500" }
152
- do_not_validate_attachment_file_type :attachment
153
- end
154
-
155
- # Access ModelB first, then ModelA (reverse order of definition)
156
- model_b = ModelB.new
157
- attachment_b = model_b.attachment
158
-
159
- model_a = ModelA.new
160
- attachment_a = model_a.attachment
161
-
162
- # Verify configurations remain correct
163
- expect(attachment_a.options[:path]).to eq "/model_a/:filename"
164
- expect(attachment_a.options[:styles]).to eq({ thumb: "100x100" })
165
-
166
- expect(attachment_b.options[:path]).to eq "/model_b/:filename"
167
- expect(attachment_b.options[:styles]).to eq({ large: "500x500" })
168
- end
169
-
170
- it "does not share options between multiple instances of the same model" do
171
- class ::ModelA < ActiveRecord::Base
172
- include Paperclip::Glue
173
- has_attached_file :attachment,
174
- path: "/model_a/:filename",
175
- styles: { thumb: "100x100" }
176
- do_not_validate_attachment_file_type :attachment
177
- end
178
-
179
- instance1 = ModelA.new
180
- instance2 = ModelA.new
181
-
182
- attachment1 = instance1.attachment
183
- attachment2 = instance2.attachment
184
-
185
- # Verify they have the same configuration values
186
- expect(attachment1.options[:path]).to eq attachment2.options[:path]
187
- expect(attachment1.options[:styles]).to eq attachment2.options[:styles]
188
-
189
- # Verify the values are correct for both instances
190
- expect(attachment1.options[:path]).to eq "/model_a/:filename"
191
- expect(attachment2.options[:path]).to eq "/model_a/:filename"
192
- end
193
-
194
- context "with global default_options configured first" do
195
- let(:original_default_options) { Paperclip::Attachment.default_options.deep_dup }
196
-
197
- before do
198
- # Simulate a Rails initializer setting global defaults
199
- Paperclip::Attachment.default_options[:path] = "/global/:class/:attachment/:id/:style/:filename"
200
- Paperclip::Attachment.default_options[:url] = "/global/:class/:attachment/:id/:style/:filename"
201
- Paperclip::Attachment.default_options[:default_url] = "/global/missing.png"
202
- Paperclip::Attachment.default_options[:styles] = { global_thumb: "50x50" }
203
- end
204
-
205
- after do
206
- # Restore original default_options
207
- Paperclip::Attachment.instance_variable_set(:@default_options, nil)
208
- end
209
-
210
- it "keeps model configurations isolated when global defaults are set" do
211
- # Define ModelA that overrides some global defaults
212
- class ::ModelA < ActiveRecord::Base
213
- include Paperclip::Glue
214
- has_attached_file :attachment,
215
- path: "/model_a/:filename",
216
- styles: { thumb: "100x100" }
217
- do_not_validate_attachment_file_type :attachment
218
- end
219
-
220
- # Define ModelB that overrides different global defaults
221
- class ::ModelB < ActiveRecord::Base
222
- include Paperclip::Glue
223
- has_attached_file :attachment,
224
- path: "/model_b/:filename",
225
- styles: { large: "500x500" }
226
- do_not_validate_attachment_file_type :attachment
227
- end
228
-
229
- model_a = ModelA.new
230
- model_b = ModelB.new
231
-
232
- attachment_a = model_a.attachment
233
- attachment_b = model_b.attachment
234
-
235
- # Verify ModelA has its own path, and styles are deep_merged with global defaults
236
- expect(attachment_a.options[:path]).to eq "/model_a/:filename"
237
- expect(attachment_a.options[:styles]).to include(thumb: "100x100")
238
- expect(attachment_a.options[:styles]).to include(global_thumb: "50x50") # inherited from global
239
- expect(attachment_a.options[:url]).to eq "/global/:class/:attachment/:id/:style/:filename"
240
- expect(attachment_a.options[:default_url]).to eq "/global/missing.png"
241
-
242
- # Verify ModelB has its own path, and styles are deep_merged with global defaults
243
- expect(attachment_b.options[:path]).to eq "/model_b/:filename"
244
- expect(attachment_b.options[:styles]).to include(large: "500x500")
245
- expect(attachment_b.options[:styles]).to include(global_thumb: "50x50") # inherited from global
246
- expect(attachment_b.options[:url]).to eq "/global/:class/:attachment/:id/:style/:filename"
247
- expect(attachment_b.options[:default_url]).to eq "/global/missing.png"
248
-
249
- # Verify ModelA's styles do NOT leak to ModelB and vice versa
250
- expect(attachment_a.options[:styles]).not_to have_key(:large)
251
- expect(attachment_b.options[:styles]).not_to have_key(:thumb)
252
- end
253
-
254
- it "does not mutate global defaults when models override them" do
255
- # Capture global defaults before defining models
256
- global_path = Paperclip::Attachment.default_options[:path]
257
- global_styles = Paperclip::Attachment.default_options[:styles].deep_dup
258
-
259
- class ::ModelA < ActiveRecord::Base
260
- include Paperclip::Glue
261
- has_attached_file :attachment,
262
- path: "/model_a/:filename",
263
- styles: { thumb: "100x100" }
264
- do_not_validate_attachment_file_type :attachment
265
- end
266
-
267
- # Access the attachment to trigger any potential mutation
268
- model_a = ModelA.new
269
- _attachment_a = model_a.attachment
270
-
271
- # Global defaults should remain unchanged
272
- expect(Paperclip::Attachment.default_options[:path]).to eq global_path
273
- expect(Paperclip::Attachment.default_options[:styles]).to eq global_styles
274
- end
275
-
276
- it "does not leak ModelA config to ModelB when both override global defaults" do
277
- class ::ModelA < ActiveRecord::Base
278
- include Paperclip::Glue
279
- has_attached_file :attachment,
280
- path: "/model_a/:filename",
281
- styles: { thumb: "100x100" },
282
- convert_options: { all: "-quality 80" }
283
- do_not_validate_attachment_file_type :attachment
284
- end
285
-
286
- class ::ModelB < ActiveRecord::Base
287
- include Paperclip::Glue
288
- has_attached_file :attachment,
289
- path: "/model_b/:filename",
290
- styles: { large: "500x500" },
291
- convert_options: { all: "-quality 90" }
292
- do_not_validate_attachment_file_type :attachment
293
- end
294
-
295
- # Access ModelA first
296
- model_a = ModelA.new
297
- attachment_a = model_a.attachment
298
-
299
- # Then access ModelB
300
- model_b = ModelB.new
301
- attachment_b = model_b.attachment
302
-
303
- # Verify convert_options are isolated
304
- expect(attachment_a.options[:convert_options]).to eq({ all: "-quality 80" })
305
- expect(attachment_b.options[:convert_options]).to eq({ all: "-quality 90" })
306
-
307
- # Verify other options remain isolated
308
- expect(attachment_a.options[:path]).to eq "/model_a/:filename"
309
- expect(attachment_b.options[:path]).to eq "/model_b/:filename"
310
- end
311
- end
312
- end
313
- end
@@ -1,79 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Attachment Processing" do
4
- before { rebuild_class }
5
-
6
- context "using validates_attachment_content_type" do
7
- it "processes attachments given a valid assignment" do
8
- file = File.new(fixture_file("5k.png"))
9
- Dummy.validates_attachment_content_type :avatar, content_type: "image/png"
10
- instance = Dummy.new
11
- attachment = instance.avatar
12
- expect(attachment).to receive(:post_process_styles)
13
-
14
- attachment.assign(file)
15
- end
16
-
17
- it "does not process attachments given an invalid assignment with :not" do
18
- file = File.new(fixture_file("5k.png"))
19
- Dummy.validates_attachment_content_type :avatar, not: "image/png"
20
- instance = Dummy.new
21
- attachment = instance.avatar
22
- expect(attachment).not_to receive(:post_process_styles)
23
-
24
- attachment.assign(file)
25
- end
26
-
27
- it "does not process attachments given an invalid assignment with :content_type" do
28
- file = File.new(fixture_file("5k.png"))
29
- Dummy.validates_attachment_content_type :avatar, content_type: "image/tiff"
30
- instance = Dummy.new
31
- attachment = instance.avatar
32
- expect(attachment).not_to receive(:post_process_styles)
33
-
34
- attachment.assign(file)
35
- end
36
-
37
- it "allows what would be an invalid assignment when validation :if clause returns false" do
38
- invalid_assignment = File.new(fixture_file("5k.png"))
39
- Dummy.validates_attachment_content_type :avatar, content_type: "image/tiff", if: lambda { false }
40
- instance = Dummy.new
41
- attachment = instance.avatar
42
- expect(attachment).to receive(:post_process_styles)
43
-
44
- attachment.assign(invalid_assignment)
45
- end
46
- end
47
-
48
- context "using validates_attachment" do
49
- it "processes attachments given a valid assignment" do
50
- file = File.new(fixture_file("5k.png"))
51
- Dummy.validates_attachment :avatar, content_type: { content_type: "image/png" }
52
- instance = Dummy.new
53
- attachment = instance.avatar
54
- expect(attachment).to receive(:post_process_styles)
55
-
56
- attachment.assign(file)
57
- end
58
-
59
- it "does not process attachments given an invalid assignment with :not" do
60
- file = File.new(fixture_file("5k.png"))
61
- Dummy.validates_attachment :avatar, content_type: { not: "image/png" }
62
- instance = Dummy.new
63
- attachment = instance.avatar
64
- expect(attachment).not_to receive(:post_process_styles)
65
-
66
- attachment.assign(file)
67
- end
68
-
69
- it "does not process attachments given an invalid assignment with :content_type" do
70
- file = File.new(fixture_file("5k.png"))
71
- Dummy.validates_attachment :avatar, content_type: { content_type: "image/tiff" }
72
- instance = Dummy.new
73
- attachment = instance.avatar
74
- expect(attachment).not_to receive(:post_process_styles)
75
-
76
- attachment.assign(file)
77
- end
78
- end
79
- end
@@ -1,158 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Attachment Registry" do
4
- before do
5
- Paperclip::AttachmentRegistry.clear
6
- end
7
-
8
- context ".names_for" do
9
- it "includes attachment names for the given class" do
10
- foo = Class.new
11
- Paperclip::AttachmentRegistry.register(foo, :avatar, {})
12
-
13
- assert_equal [:avatar], Paperclip::AttachmentRegistry.names_for(foo)
14
- end
15
-
16
- it "does not include attachment names for other classes" do
17
- foo = Class.new
18
- bar = Class.new
19
- Paperclip::AttachmentRegistry.register(foo, :avatar, {})
20
- Paperclip::AttachmentRegistry.register(bar, :lover, {})
21
-
22
- assert_equal [:lover], Paperclip::AttachmentRegistry.names_for(bar)
23
- end
24
-
25
- it "produces the empty array for a missing key" do
26
- assert_empty Paperclip::AttachmentRegistry.names_for(Class.new)
27
- end
28
- end
29
-
30
- context ".each_definition" do
31
- it "calls the block with the class, attachment name, and options" do
32
- foo = Class.new
33
- expected_accumulations = [
34
- [foo, :avatar, { yo: "greeting" }],
35
- [foo, :greeter, { ciao: "greeting" }]
36
- ]
37
- expected_accumulations.each do |args|
38
- Paperclip::AttachmentRegistry.register(*args)
39
- end
40
- accumulations = []
41
-
42
- Paperclip::AttachmentRegistry.each_definition do |*args|
43
- accumulations << args
44
- end
45
-
46
- assert_equal expected_accumulations, accumulations
47
- end
48
- end
49
-
50
- context ".definitions_for" do
51
- it "produces the attachment name and options" do
52
- expected_definitions = {
53
- avatar: { yo: "greeting" },
54
- greeter: { ciao: "greeting" }
55
- }
56
- foo = Class.new
57
- Paperclip::AttachmentRegistry.register(
58
- foo,
59
- :avatar,
60
- yo: "greeting"
61
- )
62
- Paperclip::AttachmentRegistry.register(
63
- foo,
64
- :greeter,
65
- ciao: "greeting"
66
- )
67
-
68
- definitions = Paperclip::AttachmentRegistry.definitions_for(foo)
69
-
70
- assert_equal expected_definitions, definitions
71
- end
72
-
73
- it "produces defintions for subclasses" do
74
- expected_definitions = { avatar: { yo: "greeting" } }
75
- foo = Class.new
76
- bar = Class.new(foo)
77
- Paperclip::AttachmentRegistry.register(
78
- foo,
79
- :avatar,
80
- expected_definitions[:avatar]
81
- )
82
-
83
- definitions = Paperclip::AttachmentRegistry.definitions_for(bar)
84
-
85
- assert_equal expected_definitions, definitions
86
- end
87
-
88
- it "produces defintions for subclasses but deep merging them" do
89
- foo_definitions = { avatar: { yo: "greeting" } }
90
- bar_definitions = { avatar: { ciao: "greeting" } }
91
- expected_definitions = {
92
- avatar: {
93
- yo: "greeting",
94
- ciao: "greeting"
95
- }
96
- }
97
- foo = Class.new
98
- bar = Class.new(foo)
99
- Paperclip::AttachmentRegistry.register(
100
- foo,
101
- :avatar,
102
- foo_definitions[:avatar]
103
- )
104
- Paperclip::AttachmentRegistry.register(
105
- bar,
106
- :avatar,
107
- bar_definitions[:avatar]
108
- )
109
-
110
- definitions = Paperclip::AttachmentRegistry.definitions_for(bar)
111
-
112
- assert_equal expected_definitions, definitions
113
- end
114
-
115
- it "allows subclasses to override attachment defitions" do
116
- foo_definitions = { avatar: { yo: "greeting" } }
117
- bar_definitions = { avatar: { yo: "hello" } }
118
-
119
- expected_definitions = {
120
- avatar: {
121
- yo: "hello"
122
- }
123
- }
124
-
125
- foo = Class.new
126
- bar = Class.new(foo)
127
- Paperclip::AttachmentRegistry.register(
128
- foo,
129
- :avatar,
130
- foo_definitions[:avatar]
131
- )
132
- Paperclip::AttachmentRegistry.register(
133
- bar,
134
- :avatar,
135
- bar_definitions[:avatar]
136
- )
137
-
138
- definitions = Paperclip::AttachmentRegistry.definitions_for(bar)
139
-
140
- assert_equal expected_definitions, definitions
141
- end
142
- end
143
-
144
- context ".clear" do
145
- it "removes all of the existing attachment definitions" do
146
- foo = Class.new
147
- Paperclip::AttachmentRegistry.register(
148
- foo,
149
- :greeter,
150
- ciao: "greeting"
151
- )
152
-
153
- Paperclip::AttachmentRegistry.clear
154
-
155
- assert_empty Paperclip::AttachmentRegistry.names_for(foo)
156
- end
157
- end
158
- end