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.
- checksums.yaml +4 -4
- data/NEWS +9 -0
- data/lib/paperclip/thumbnail.rb +18 -15
- data/lib/paperclip/version.rb +1 -1
- metadata +3 -245
- data/.github/FUNDING.yml +0 -3
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -18
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- data/.github/workflows/reviewdog.yml +0 -23
- data/.github/workflows/tests.yml +0 -56
- data/.gitignore +0 -19
- data/.qlty/.gitignore +0 -7
- data/.qlty/qlty.toml +0 -89
- data/Appraisals +0 -29
- data/Gemfile +0 -18
- data/bin/console +0 -11
- data/features/basic_integration.feature +0 -112
- data/features/migration.feature +0 -29
- data/features/rake_tasks.feature +0 -62
- data/features/step_definitions/attachment_steps.rb +0 -138
- data/features/step_definitions/html_steps.rb +0 -15
- data/features/step_definitions/rails_steps.rb +0 -271
- data/features/step_definitions/s3_steps.rb +0 -16
- data/features/step_definitions/web_steps.rb +0 -106
- data/features/support/env.rb +0 -12
- data/features/support/file_helpers.rb +0 -34
- data/features/support/fixtures/boot_config.txt +0 -15
- data/features/support/fixtures/gemfile.txt +0 -5
- data/features/support/fixtures/preinitializer.txt +0 -20
- data/features/support/paths.rb +0 -28
- data/features/support/rails.rb +0 -39
- data/features/support/selectors.rb +0 -19
- data/features/support/webmock_setup.rb +0 -8
- data/gemfiles/7.0.gemfile +0 -21
- data/gemfiles/7.1.gemfile +0 -21
- data/gemfiles/7.2.gemfile +0 -21
- data/gemfiles/8.0.gemfile +0 -21
- data/gemfiles/8.1.gemfile +0 -21
- data/paperclip.gemspec +0 -52
- data/spec/database.yml +0 -4
- data/spec/paperclip/attachment_definitions_spec.rb +0 -313
- data/spec/paperclip/attachment_processing_spec.rb +0 -79
- data/spec/paperclip/attachment_registry_spec.rb +0 -158
- data/spec/paperclip/attachment_spec.rb +0 -1617
- data/spec/paperclip/content_type_detector_spec.rb +0 -58
- data/spec/paperclip/file_command_content_type_detector_spec.rb +0 -40
- data/spec/paperclip/filename_cleaner_spec.rb +0 -13
- data/spec/paperclip/geometry_detector_spec.rb +0 -96
- data/spec/paperclip/geometry_parser_spec.rb +0 -73
- data/spec/paperclip/geometry_spec.rb +0 -270
- data/spec/paperclip/glue_spec.rb +0 -63
- data/spec/paperclip/has_attached_file_spec.rb +0 -78
- data/spec/paperclip/helpers_spec.rb +0 -49
- data/spec/paperclip/integration_spec.rb +0 -702
- data/spec/paperclip/interpolations_spec.rb +0 -270
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +0 -160
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +0 -167
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +0 -88
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +0 -17
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +0 -134
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +0 -142
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +0 -8
- data/spec/paperclip/io_adapters/nil_adapter_spec.rb +0 -25
- data/spec/paperclip/io_adapters/registry_spec.rb +0 -35
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +0 -64
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +0 -146
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +0 -231
- data/spec/paperclip/lazy_thumbnail_compatibility_spec.rb +0 -266
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +0 -19
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +0 -108
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +0 -69
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +0 -88
- data/spec/paperclip/media_type_spoof_detector_spec.rb +0 -126
- data/spec/paperclip/meta_class_spec.rb +0 -30
- data/spec/paperclip/migration_guide_example_spec.rb +0 -44
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +0 -88
- data/spec/paperclip/paperclip_spec.rb +0 -196
- data/spec/paperclip/plural_cache_spec.rb +0 -37
- data/spec/paperclip/processor_helpers_spec.rb +0 -57
- data/spec/paperclip/processor_spec.rb +0 -60
- data/spec/paperclip/rails_environment_spec.rb +0 -30
- data/spec/paperclip/rake_spec.rb +0 -103
- data/spec/paperclip/schema_spec.rb +0 -298
- data/spec/paperclip/storage/filesystem_spec.rb +0 -102
- data/spec/paperclip/storage/fog_spec.rb +0 -606
- data/spec/paperclip/storage/s3_live_spec.rb +0 -188
- data/spec/paperclip/storage/s3_spec.rb +0 -1974
- data/spec/paperclip/style_spec.rb +0 -309
- data/spec/paperclip/tempfile_factory_spec.rb +0 -33
- data/spec/paperclip/tempfile_spec.rb +0 -35
- data/spec/paperclip/thumbnail_custom_options_spec.rb +0 -225
- data/spec/paperclip/thumbnail_loader_options_spec.rb +0 -53
- data/spec/paperclip/thumbnail_security_spec.rb +0 -42
- data/spec/paperclip/thumbnail_spec.rb +0 -1460
- data/spec/paperclip/url_generator_spec.rb +0 -231
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +0 -410
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +0 -249
- data/spec/paperclip/validators/attachment_presence_validator_spec.rb +0 -85
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +0 -325
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +0 -48
- data/spec/paperclip/validators_spec.rb +0 -179
- data/spec/spec_helper.rb +0 -52
- data/spec/support/assertions.rb +0 -84
- data/spec/support/fake_model.rb +0 -24
- data/spec/support/fake_rails.rb +0 -12
- data/spec/support/fixtures/12k.png +0 -0
- data/spec/support/fixtures/50x50.png +0 -0
- data/spec/support/fixtures/5k.png +0 -0
- data/spec/support/fixtures/animated +0 -0
- data/spec/support/fixtures/animated.gif +0 -0
- data/spec/support/fixtures/animated.unknown +0 -0
- data/spec/support/fixtures/aws_s3.yml +0 -13
- data/spec/support/fixtures/bad.png +0 -1
- data/spec/support/fixtures/empty.html +0 -1
- data/spec/support/fixtures/empty.xlsx +0 -0
- data/spec/support/fixtures/fog.yml +0 -8
- data/spec/support/fixtures/rotated.jpg +0 -0
- data/spec/support/fixtures/s3.yml +0 -8
- data/spec/support/fixtures/sample.xlsm +0 -0
- data/spec/support/fixtures/spaced file.jpg +0 -0
- data/spec/support/fixtures/spaced file.png +0 -0
- data/spec/support/fixtures/text.txt +0 -1
- data/spec/support/fixtures/twopage.pdf +0 -0
- data/spec/support/fixtures/uppercase.PNG +0 -0
- data/spec/support/matchers/accept.rb +0 -5
- data/spec/support/matchers/exist.rb +0 -5
- data/spec/support/matchers/have_column.rb +0 -23
- data/spec/support/mock_attachment.rb +0 -24
- data/spec/support/mock_interpolator.rb +0 -24
- data/spec/support/mock_url_generator_builder.rb +0 -26
- data/spec/support/model_reconstruction.rb +0 -72
- data/spec/support/reporting.rb +0 -11
- data/spec/support/test_data.rb +0 -13
- 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
|