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.
- checksums.yaml +4 -4
- data/.github/issue_template.md +3 -0
- data/.hound.yml +27 -32
- data/.travis.yml +23 -2
- data/Appraisals +17 -0
- data/Gemfile +9 -7
- data/NEWS +21 -0
- data/README.md +27 -37
- data/Rakefile +29 -21
- data/UPGRADING +3 -3
- data/features/basic_integration.feature +4 -0
- data/features/migration.feature +10 -51
- data/features/step_definitions/attachment_steps.rb +12 -12
- data/features/step_definitions/html_steps.rb +5 -5
- data/features/step_definitions/rails_steps.rb +29 -9
- data/features/step_definitions/s3_steps.rb +3 -3
- data/features/step_definitions/web_steps.rb +5 -6
- data/features/support/env.rb +4 -4
- data/features/support/fakeweb.rb +3 -5
- data/features/support/file_helpers.rb +2 -2
- data/features/support/paths.rb +4 -4
- data/features/support/rails.rb +7 -7
- data/features/support/selectors.rb +1 -1
- data/gemfiles/4.2.gemfile +7 -4
- data/gemfiles/5.0.gemfile +7 -4
- data/gemfiles/5.1.gemfile +20 -0
- data/gemfiles/5.2.gemfile +20 -0
- data/gemfiles/6.0.gemfile +20 -0
- data/lib/generators/paperclip/paperclip_generator.rb +6 -8
- data/lib/paperclip/attachment.rb +102 -104
- data/lib/paperclip/attachment_registry.rb +2 -2
- data/lib/paperclip/file_command_content_type_detector.rb +1 -3
- data/lib/paperclip/filename_cleaner.rb +0 -1
- data/lib/paperclip/geometry.rb +18 -19
- data/lib/paperclip/geometry_detector_factory.rb +13 -16
- data/lib/paperclip/geometry_parser_factory.rb +5 -5
- data/lib/paperclip/glue.rb +3 -3
- data/lib/paperclip/has_attached_file.rb +5 -4
- data/lib/paperclip/helpers.rb +3 -3
- data/lib/paperclip/interpolations.rb +42 -38
- data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
- data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +3 -3
- data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
- data/lib/paperclip/io_adapters/registry.rb +1 -1
- data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
- data/lib/paperclip/io_adapters/uri_adapter.rb +9 -7
- data/lib/paperclip/logger.rb +1 -1
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
- data/lib/paperclip/matchers.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +13 -13
- data/lib/paperclip/missing_attachment_styles.rb +11 -6
- data/lib/paperclip/processor.rb +13 -6
- data/lib/paperclip/processor_helpers.rb +3 -1
- data/lib/paperclip/rails_environment.rb +1 -5
- data/lib/paperclip/railtie.rb +5 -5
- data/lib/paperclip/schema.rb +18 -14
- data/lib/paperclip/storage/filesystem.rb +5 -7
- data/lib/paperclip/storage/fog.rb +36 -32
- data/lib/paperclip/storage/s3.rb +67 -75
- data/lib/paperclip/style.rb +3 -6
- data/lib/paperclip/tempfile.rb +4 -5
- data/lib/paperclip/tempfile_factory.rb +0 -1
- data/lib/paperclip/thumbnail.rb +11 -11
- data/lib/paperclip/url_generator.rb +5 -12
- data/lib/paperclip/validators/attachment_content_type_validator.rb +3 -3
- data/lib/paperclip/validators/attachment_file_name_validator.rb +5 -10
- data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
- data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
- data/lib/paperclip/validators/attachment_size_validator.rb +8 -8
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
- data/lib/paperclip/validators.rb +12 -13
- data/lib/paperclip/version.rb +1 -3
- data/lib/paperclip.rb +49 -48
- data/lib/tasks/paperclip.rake +23 -24
- data/paperclip.gemspec +29 -33
- data/shoulda_macros/paperclip.rb +16 -16
- data/spec/paperclip/attachment_definitions_spec.rb +5 -5
- data/spec/paperclip/attachment_processing_spec.rb +22 -23
- data/spec/paperclip/attachment_registry_spec.rb +15 -15
- data/spec/paperclip/attachment_spec.rb +238 -196
- data/spec/paperclip/content_type_detector_spec.rb +11 -12
- data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
- data/spec/paperclip/filename_cleaner_spec.rb +3 -4
- data/spec/paperclip/geometry_detector_spec.rb +7 -8
- data/spec/paperclip/geometry_parser_spec.rb +31 -31
- data/spec/paperclip/geometry_spec.rb +24 -24
- data/spec/paperclip/glue_spec.rb +3 -5
- data/spec/paperclip/has_attached_file_spec.rb +46 -126
- data/spec/paperclip/integration_spec.rb +111 -77
- data/spec/paperclip/interpolations_spec.rb +101 -93
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +42 -26
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
- data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +80 -31
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
- data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
- data/spec/paperclip/meta_class_spec.rb +3 -3
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
- data/spec/paperclip/paperclip_spec.rb +15 -11
- data/spec/paperclip/plural_cache_spec.rb +8 -8
- data/spec/paperclip/processor_helpers_spec.rb +35 -35
- data/spec/paperclip/processor_spec.rb +8 -8
- data/spec/paperclip/rails_environment_spec.rb +7 -10
- data/spec/paperclip/rake_spec.rb +39 -39
- data/spec/paperclip/schema_spec.rb +57 -53
- data/spec/paperclip/storage/filesystem_spec.rb +6 -6
- data/spec/paperclip/storage/fog_spec.rb +76 -82
- data/spec/paperclip/storage/s3_live_spec.rb +22 -22
- data/spec/paperclip/storage/s3_spec.rb +585 -583
- data/spec/paperclip/style_spec.rb +67 -71
- data/spec/paperclip/tempfile_factory_spec.rb +5 -5
- data/spec/paperclip/thumbnail_spec.rb +68 -67
- data/spec/paperclip/url_generator_spec.rb +18 -29
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +27 -27
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +15 -16
- data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +21 -21
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
- data/spec/paperclip/validators_spec.rb +40 -40
- data/spec/spec_helper.rb +21 -23
- data/spec/support/assertions.rb +8 -6
- data/spec/support/fake_model.rb +1 -2
- data/spec/support/fake_rails.rb +1 -1
- data/spec/support/matchers/exist.rb +1 -1
- data/spec/support/matchers/have_column.rb +1 -1
- data/spec/support/mock_url_generator_builder.rb +2 -3
- data/spec/support/model_reconstruction.rb +16 -12
- data/spec/support/reporting.rb +1 -1
- data/spec/support/test_data.rb +2 -2
- metadata +49 -105
- data/lib/kt-paperclip.rb +0 -1
- data/spec/support/conditional_filter_helper.rb +0 -5
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::Interpolations do
|
4
4
|
it "returns all methods but the infrastructure when sent #all" do
|
5
5
|
methods = Paperclip::Interpolations.all
|
6
|
-
assert !
|
7
|
-
assert !
|
8
|
-
assert !
|
6
|
+
assert !methods.include?(:[])
|
7
|
+
assert !methods.include?(:[]=)
|
8
|
+
assert !methods.include?(:all)
|
9
9
|
methods.each do |m|
|
10
10
|
assert Paperclip::Interpolations.respond_to?(m)
|
11
11
|
end
|
@@ -24,138 +24,146 @@ describe Paperclip::Interpolations do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "returns the class of the instance" do
|
27
|
-
class Thing
|
28
|
-
attachment =
|
29
|
-
attachment.
|
30
|
-
attachment.
|
27
|
+
class Thing; end
|
28
|
+
attachment = spy
|
29
|
+
expect(attachment).to receive(:instance).and_return(attachment)
|
30
|
+
expect(attachment).to receive(:class).and_return(Thing)
|
31
31
|
assert_equal "things", Paperclip::Interpolations.class(attachment, :style)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "returns the basename of the file" do
|
35
|
-
attachment =
|
36
|
-
attachment.
|
35
|
+
attachment = spy
|
36
|
+
expect(attachment).to receive(:original_filename).and_return("one.jpg")
|
37
37
|
assert_equal "one", Paperclip::Interpolations.basename(attachment, :style)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "returns the extension of the file" do
|
41
|
-
attachment =
|
42
|
-
attachment.
|
43
|
-
attachment.
|
41
|
+
attachment = spy
|
42
|
+
expect(attachment).to receive(:original_filename).and_return("one.jpg")
|
43
|
+
expect(attachment).to receive(:styles).and_return({})
|
44
44
|
assert_equal "jpg", Paperclip::Interpolations.extension(attachment, :style)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "returns the extension of the file as the format if defined in the style" do
|
48
|
-
attachment =
|
49
|
-
attachment.
|
50
|
-
attachment.
|
48
|
+
attachment = spy
|
49
|
+
expect(attachment).to_not receive(:original_filename)
|
50
|
+
expect(attachment).to receive(:styles).at_least(2).times.and_return(style: { format: "png" })
|
51
51
|
|
52
|
-
[:style,
|
52
|
+
[:style, "style"].each do |style|
|
53
53
|
assert_equal "png", Paperclip::Interpolations.extension(attachment, style)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
it "returns the extension of the file based on the content type" do
|
58
|
-
attachment =
|
59
|
-
attachment.
|
60
|
-
attachment.
|
58
|
+
attachment = spy
|
59
|
+
expect(attachment).to receive(:content_type).and_return("image/png")
|
60
|
+
expect(attachment).to receive(:styles).and_return({})
|
61
61
|
interpolations = Paperclip::Interpolations
|
62
|
-
interpolations.
|
62
|
+
expect(interpolations).to receive(:extension).and_return("random")
|
63
63
|
assert_equal "png", interpolations.content_type_extension(attachment, :style)
|
64
64
|
end
|
65
65
|
|
66
66
|
it "returns the original extension of the file if it matches a content type extension" do
|
67
|
-
attachment =
|
68
|
-
attachment.
|
69
|
-
attachment.
|
67
|
+
attachment = spy
|
68
|
+
expect(attachment).to receive(:content_type).and_return("image/jpeg")
|
69
|
+
expect(attachment).to receive(:styles).and_return({})
|
70
70
|
interpolations = Paperclip::Interpolations
|
71
|
-
interpolations.
|
71
|
+
expect(interpolations).to receive(:extension).and_return("jpe")
|
72
72
|
assert_equal "jpe", interpolations.content_type_extension(attachment, :style)
|
73
73
|
end
|
74
74
|
|
75
75
|
it "returns the extension of the file with a dot" do
|
76
|
-
attachment =
|
77
|
-
attachment.
|
78
|
-
attachment.
|
76
|
+
attachment = spy
|
77
|
+
expect(attachment).to receive(:original_filename).and_return("one.jpg")
|
78
|
+
expect(attachment).to receive(:styles).and_return({})
|
79
79
|
assert_equal ".jpg", Paperclip::Interpolations.dotextension(attachment, :style)
|
80
80
|
end
|
81
81
|
|
82
82
|
it "returns the extension of the file without a dot if the extension is empty" do
|
83
|
-
attachment =
|
84
|
-
attachment.
|
85
|
-
attachment.
|
83
|
+
attachment = spy
|
84
|
+
expect(attachment).to receive(:original_filename).and_return("one")
|
85
|
+
expect(attachment).to receive(:styles).and_return({})
|
86
86
|
assert_equal "", Paperclip::Interpolations.dotextension(attachment, :style)
|
87
87
|
end
|
88
88
|
|
89
89
|
it "returns the latter half of the content type of the extension if no match found" do
|
90
|
-
attachment =
|
91
|
-
attachment.
|
92
|
-
attachment.
|
90
|
+
attachment = spy
|
91
|
+
allow(attachment).to receive(:content_type).at_least(1).times.and_return("not/found")
|
92
|
+
allow(attachment).to receive(:styles).and_return({})
|
93
93
|
interpolations = Paperclip::Interpolations
|
94
|
-
interpolations.
|
94
|
+
expect(interpolations).to receive(:extension).and_return("random")
|
95
95
|
assert_equal "found", interpolations.content_type_extension(attachment, :style)
|
96
96
|
end
|
97
97
|
|
98
98
|
it "returns the format if defined in the style, ignoring the content type" do
|
99
|
-
attachment =
|
100
|
-
attachment.
|
101
|
-
attachment.
|
99
|
+
attachment = spy
|
100
|
+
expect(attachment).to receive(:content_type).and_return("image/jpeg")
|
101
|
+
expect(attachment).to receive(:styles).and_return(style: { format: "png" })
|
102
102
|
interpolations = Paperclip::Interpolations
|
103
|
-
interpolations.
|
103
|
+
expect(interpolations).to receive(:extension).and_return("random")
|
104
104
|
assert_equal "png", interpolations.content_type_extension(attachment, :style)
|
105
105
|
end
|
106
106
|
|
107
107
|
it "is able to handle numeric style names" do
|
108
|
-
attachment =
|
108
|
+
attachment = spy(
|
109
109
|
styles: {:"4" => {format: :expected_extension}}
|
110
110
|
)
|
111
111
|
assert_equal :expected_extension, Paperclip::Interpolations.extension(attachment, 4)
|
112
112
|
end
|
113
113
|
|
114
114
|
it "returns the #to_param of the attachment" do
|
115
|
-
attachment =
|
116
|
-
attachment.
|
117
|
-
attachment.
|
115
|
+
attachment = spy
|
116
|
+
expect(attachment).to receive(:to_param).and_return("23-awesome")
|
117
|
+
expect(attachment).to receive(:instance).and_return(attachment)
|
118
118
|
assert_equal "23-awesome", Paperclip::Interpolations.param(attachment, :style)
|
119
119
|
end
|
120
120
|
|
121
121
|
it "returns the id of the attachment" do
|
122
|
-
attachment =
|
123
|
-
attachment.
|
124
|
-
attachment.
|
122
|
+
attachment = spy
|
123
|
+
expect(attachment).to receive(:id).and_return(23)
|
124
|
+
expect(attachment).to receive(:instance).and_return(attachment)
|
125
125
|
assert_equal 23, Paperclip::Interpolations.id(attachment, :style)
|
126
126
|
end
|
127
127
|
|
128
128
|
it "returns nil for attachments to new records" do
|
129
|
-
attachment =
|
130
|
-
attachment.
|
131
|
-
attachment.
|
129
|
+
attachment = spy
|
130
|
+
expect(attachment).to receive(:id).and_return(nil)
|
131
|
+
expect(attachment).to receive(:instance).and_return(attachment)
|
132
132
|
assert_nil Paperclip::Interpolations.id(attachment, :style)
|
133
133
|
end
|
134
134
|
|
135
135
|
it "returns the partitioned id of the attachment when the id is an integer" do
|
136
|
-
attachment =
|
137
|
-
attachment.
|
138
|
-
attachment.
|
136
|
+
attachment = spy
|
137
|
+
expect(attachment).to receive(:id).and_return(23)
|
138
|
+
expect(attachment).to receive(:instance).and_return(attachment)
|
139
139
|
assert_equal "000/000/023", Paperclip::Interpolations.id_partition(attachment, :style)
|
140
140
|
end
|
141
141
|
|
142
|
+
it "returns the partitioned id when the id is above 999_999_999" do
|
143
|
+
attachment = spy
|
144
|
+
expect(attachment).to receive(:id).and_return(Paperclip::Interpolations::ID_PARTITION_LIMIT)
|
145
|
+
expect(attachment).to receive(:instance).and_return(attachment)
|
146
|
+
assert_equal "001/000/000/000",
|
147
|
+
Paperclip::Interpolations.id_partition(attachment, :style)
|
148
|
+
end
|
149
|
+
|
142
150
|
it "returns the partitioned id of the attachment when the id is a string" do
|
143
|
-
attachment =
|
144
|
-
attachment.
|
145
|
-
attachment.
|
151
|
+
attachment = spy
|
152
|
+
expect(attachment).to receive(:id).and_return("32fnj23oio2f")
|
153
|
+
expect(attachment).to receive(:instance).and_return(attachment)
|
146
154
|
assert_equal "32f/nj2/3oi", Paperclip::Interpolations.id_partition(attachment, :style)
|
147
155
|
end
|
148
156
|
|
149
157
|
it "returns nil for the partitioned id of an attachment to a new record (when the id is nil)" do
|
150
|
-
attachment =
|
151
|
-
attachment.
|
152
|
-
attachment.
|
158
|
+
attachment = spy
|
159
|
+
expect(attachment).to receive(:id).and_return(nil)
|
160
|
+
expect(attachment).to receive(:instance).and_return(attachment)
|
153
161
|
assert_nil Paperclip::Interpolations.id_partition(attachment, :style)
|
154
162
|
end
|
155
163
|
|
156
164
|
it "returns the name of the attachment" do
|
157
|
-
attachment =
|
158
|
-
attachment.
|
165
|
+
attachment = spy
|
166
|
+
expect(attachment).to receive(:name).and_return("file")
|
159
167
|
assert_equal "files", Paperclip::Interpolations.attachment(attachment, :style)
|
160
168
|
end
|
161
169
|
|
@@ -164,89 +172,89 @@ describe Paperclip::Interpolations do
|
|
164
172
|
end
|
165
173
|
|
166
174
|
it "returns the default style" do
|
167
|
-
attachment =
|
168
|
-
attachment.
|
175
|
+
attachment = spy
|
176
|
+
expect(attachment).to receive(:default_style).and_return(:default_style)
|
169
177
|
assert_equal :default_style, Paperclip::Interpolations.style(attachment, nil)
|
170
178
|
end
|
171
179
|
|
172
180
|
it "reinterpolates :url" do
|
173
|
-
attachment =
|
174
|
-
attachment.
|
181
|
+
attachment = spy
|
182
|
+
expect(attachment).to receive(:url).with(:style, timestamp: false, escape: false).and_return("1234")
|
175
183
|
assert_equal "1234", Paperclip::Interpolations.url(attachment, :style)
|
176
184
|
end
|
177
185
|
|
178
186
|
it "raises if infinite loop detcted reinterpolating :url" do
|
179
187
|
attachment = Object.new
|
180
188
|
class << attachment
|
181
|
-
def url(*
|
189
|
+
def url(*_args)
|
182
190
|
Paperclip::Interpolations.url(self, :style)
|
183
191
|
end
|
184
192
|
end
|
185
|
-
assert_raises(Paperclip::Errors::InfiniteInterpolationError){ Paperclip::Interpolations.url(attachment, :style) }
|
193
|
+
assert_raises(Paperclip::Errors::InfiniteInterpolationError) { Paperclip::Interpolations.url(attachment, :style) }
|
186
194
|
end
|
187
195
|
|
188
196
|
it "returns the filename as basename.extension" do
|
189
|
-
attachment =
|
190
|
-
attachment.
|
191
|
-
attachment.
|
197
|
+
attachment = spy
|
198
|
+
expect(attachment).to receive(:styles).and_return({})
|
199
|
+
expect(attachment).to receive(:original_filename).and_return("one.jpg").twice
|
192
200
|
assert_equal "one.jpg", Paperclip::Interpolations.filename(attachment, :style)
|
193
201
|
end
|
194
202
|
|
195
203
|
it "returns the filename as basename.extension when format supplied" do
|
196
|
-
attachment =
|
197
|
-
attachment.
|
198
|
-
attachment.
|
204
|
+
attachment = spy
|
205
|
+
expect(attachment).to receive(:styles).and_return(style: { format: :png })
|
206
|
+
expect(attachment).to receive(:original_filename).and_return("one.jpg").once
|
199
207
|
assert_equal "one.png", Paperclip::Interpolations.filename(attachment, :style)
|
200
208
|
end
|
201
209
|
|
202
210
|
it "returns the filename as basename when extension is blank" do
|
203
|
-
attachment =
|
204
|
-
attachment.
|
205
|
-
attachment.
|
211
|
+
attachment = spy
|
212
|
+
allow(attachment).to receive(:styles).and_return({})
|
213
|
+
allow(attachment).to receive(:original_filename).and_return("one")
|
206
214
|
assert_equal "one", Paperclip::Interpolations.filename(attachment, :style)
|
207
215
|
end
|
208
|
-
|
216
|
+
|
209
217
|
it "returns the basename when the extension contains regexp special characters" do
|
210
|
-
attachment =
|
211
|
-
attachment.
|
212
|
-
attachment.
|
218
|
+
attachment = spy
|
219
|
+
allow(attachment).to receive(:styles).and_return({})
|
220
|
+
allow(attachment).to receive(:original_filename).and_return("one.ab)")
|
213
221
|
assert_equal "one", Paperclip::Interpolations.basename(attachment, :style)
|
214
222
|
end
|
215
223
|
|
216
224
|
it "returns the timestamp" do
|
217
225
|
now = Time.now
|
218
|
-
zone =
|
219
|
-
attachment =
|
220
|
-
attachment.
|
221
|
-
attachment.
|
226
|
+
zone = "UTC"
|
227
|
+
attachment = spy
|
228
|
+
expect(attachment).to receive(:instance_read).with(:updated_at).and_return(now)
|
229
|
+
expect(attachment).to receive(:time_zone).and_return(zone)
|
222
230
|
assert_equal now.in_time_zone(zone).to_s, Paperclip::Interpolations.timestamp(attachment, :style)
|
223
231
|
end
|
224
232
|
|
225
233
|
it "returns updated_at" do
|
226
|
-
attachment =
|
234
|
+
attachment = spy
|
227
235
|
seconds_since_epoch = 1234567890
|
228
|
-
attachment.
|
236
|
+
expect(attachment).to receive(:updated_at).and_return(seconds_since_epoch)
|
229
237
|
assert_equal seconds_since_epoch, Paperclip::Interpolations.updated_at(attachment, :style)
|
230
238
|
end
|
231
239
|
|
232
240
|
it "returns attachment's hash when passing both arguments" do
|
233
|
-
attachment =
|
241
|
+
attachment = spy
|
234
242
|
fake_hash = "a_wicked_secure_hash"
|
235
|
-
attachment.
|
243
|
+
expect(attachment).to receive(:hash_key).and_return(fake_hash)
|
236
244
|
assert_equal fake_hash, Paperclip::Interpolations.hash(attachment, :style)
|
237
245
|
end
|
238
246
|
|
239
247
|
it "returns Object#hash when passing no argument" do
|
240
|
-
attachment =
|
248
|
+
attachment = spy
|
241
249
|
fake_hash = "a_wicked_secure_hash"
|
242
|
-
attachment.
|
250
|
+
expect(attachment).to_not receive(:hash_key)
|
243
251
|
assert_not_equal fake_hash, Paperclip::Interpolations.hash
|
244
252
|
end
|
245
253
|
|
246
254
|
it "calls all expected interpolations with the given arguments" do
|
247
|
-
Paperclip::Interpolations.
|
248
|
-
Paperclip::Interpolations.
|
249
|
-
Paperclip::Interpolations.
|
255
|
+
expect(Paperclip::Interpolations).to receive(:id).with(:attachment, :style).and_return(1234)
|
256
|
+
expect(Paperclip::Interpolations).to receive(:attachment).with(:attachment, :style).and_return("attachments")
|
257
|
+
expect(Paperclip::Interpolations).to_not receive(:notreal)
|
250
258
|
value = Paperclip::Interpolations.interpolate(":notreal/:id/:attachment", :attachment, :style)
|
251
259
|
assert_equal ":notreal/1234/attachments", value
|
252
260
|
end
|
@@ -255,7 +263,7 @@ describe Paperclip::Interpolations do
|
|
255
263
|
Paperclip.interpolates :foo? do
|
256
264
|
"bar"
|
257
265
|
end
|
258
|
-
Paperclip::Interpolations.
|
266
|
+
expect(Paperclip::Interpolations).to_not receive(:fool)
|
259
267
|
value = Paperclip::Interpolations.interpolate(":fo/:foo?")
|
260
268
|
assert_equal ":fo/bar", value
|
261
269
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::AbstractAdapter do
|
4
4
|
class TestAdapter < Paperclip::AbstractAdapter
|
@@ -13,9 +13,9 @@ describe Paperclip::AbstractAdapter do
|
|
13
13
|
|
14
14
|
context "content type from file contents" do
|
15
15
|
before do
|
16
|
-
subject.
|
17
|
-
Paperclip.
|
18
|
-
Paperclip::ContentTypeDetector.
|
16
|
+
allow(subject).to receive(:path).and_return("image.png")
|
17
|
+
allow(Paperclip).to receive(:run).and_return("image/png\n")
|
18
|
+
allow_any_instance_of(Paperclip::ContentTypeDetector).to receive(:type_from_mime_magic).and_return("image/png")
|
19
19
|
end
|
20
20
|
|
21
21
|
it "returns the content type without newline" do
|
@@ -31,29 +31,29 @@ describe Paperclip::AbstractAdapter do
|
|
31
31
|
|
32
32
|
context "delegation" do
|
33
33
|
before do
|
34
|
-
subject.tempfile =
|
34
|
+
subject.tempfile = double("Tempfile")
|
35
35
|
end
|
36
36
|
|
37
37
|
[:binmode, :binmode?, :close, :close!, :closed?, :eof?, :path, :readbyte, :rewind, :unlink].each do |method|
|
38
38
|
it "delegates #{method} to @tempfile" do
|
39
|
-
subject.tempfile.
|
39
|
+
allow(subject.tempfile).to receive(method)
|
40
40
|
subject.public_send(method)
|
41
|
-
|
41
|
+
expect(subject.tempfile).to have_received(method)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
46
|
+
it "gets rid of slashes and colons in filenames" do
|
47
47
|
subject.original_filename = "awesome/file:name.png"
|
48
48
|
|
49
49
|
assert_equal "awesome_file_name.png", subject.original_filename
|
50
50
|
end
|
51
51
|
|
52
|
-
it
|
52
|
+
it "is an assignment" do
|
53
53
|
assert subject.assignment?
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
56
|
+
it "is not nil" do
|
57
57
|
assert !subject.nil?
|
58
58
|
end
|
59
59
|
|
@@ -61,7 +61,7 @@ describe Paperclip::AbstractAdapter do
|
|
61
61
|
expect(subject.send(:destination).path).to_not be_nil
|
62
62
|
end
|
63
63
|
|
64
|
-
it
|
64
|
+
it "uses the original filename to generate the tempfile" do
|
65
65
|
subject.original_filename = "file.png"
|
66
66
|
expect(subject.send(:destination).path).to end_with(".png")
|
67
67
|
end
|
@@ -70,7 +70,7 @@ describe Paperclip::AbstractAdapter do
|
|
70
70
|
subject { TestAdapter.new(nil, options) }
|
71
71
|
|
72
72
|
before do
|
73
|
-
subject.
|
73
|
+
allow(subject).to receive(:path).and_return(fixture_file("50x50.png"))
|
74
74
|
end
|
75
75
|
|
76
76
|
context "MD5" do
|
@@ -93,6 +93,34 @@ describe Paperclip::AbstractAdapter do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
+
context "#copy_to_tempfile" do
|
97
|
+
around do |example|
|
98
|
+
FileUtils.module_eval do
|
99
|
+
class << self
|
100
|
+
alias paperclip_ln ln
|
101
|
+
|
102
|
+
def ln(*)
|
103
|
+
raise Errno::EXDEV
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
example.run
|
109
|
+
|
110
|
+
FileUtils.module_eval do
|
111
|
+
class << self
|
112
|
+
alias ln paperclip_ln
|
113
|
+
undef paperclip_ln
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should return a readable file even when linking fails" do
|
119
|
+
src = open(fixture_file("5k.png"), "rb")
|
120
|
+
expect(subject.send(:copy_to_tempfile, src).read).to eq src.read
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
96
124
|
context "#original_filename=" do
|
97
125
|
it "should not fail with a nil original filename" do
|
98
126
|
expect { subject.original_filename = nil }.not_to raise_error
|
@@ -124,7 +152,7 @@ describe Paperclip::AbstractAdapter do
|
|
124
152
|
end
|
125
153
|
|
126
154
|
it "should be able to reopen the file after symlink has failed" do
|
127
|
-
FileUtils.
|
155
|
+
expect(FileUtils).to receive(:ln).and_raise(Errno::EXDEV)
|
128
156
|
|
129
157
|
expect(subject.copy_to_tempfile(file).read).to eq(body)
|
130
158
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::AttachmentAdapter do
|
4
4
|
before do
|
5
|
-
rebuild_model path: "tmp/:class/:attachment/:style/:filename", styles: {thumb:
|
5
|
+
rebuild_model path: "tmp/:class/:attachment/:style/:filename", styles: { thumb: "50x50" }
|
6
6
|
@attachment = Dummy.new.avatar
|
7
7
|
end
|
8
8
|
|
@@ -39,7 +39,7 @@ describe Paperclip::AttachmentAdapter do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "returns false for a call to nil?" do
|
42
|
-
assert
|
42
|
+
assert !@subject.nil?
|
43
43
|
end
|
44
44
|
|
45
45
|
it "generates a MD5 hash of the contents" do
|
@@ -50,18 +50,17 @@ describe Paperclip::AttachmentAdapter do
|
|
50
50
|
it "reads the contents of the file" do
|
51
51
|
expected = @file.read
|
52
52
|
actual = @subject.read
|
53
|
-
assert expected.
|
53
|
+
assert !expected.empty?
|
54
54
|
assert_equal expected.length, actual.length
|
55
55
|
assert_equal expected, actual
|
56
56
|
end
|
57
|
-
|
58
57
|
end
|
59
58
|
|
60
59
|
context "for a file with restricted characters in the name" do
|
61
60
|
before do
|
62
61
|
file_contents = IO.read(fixture_file("animated.gif"))
|
63
62
|
@file = StringIO.new(file_contents)
|
64
|
-
@file.
|
63
|
+
allow(@file).to receive(:original_filename).and_return("image:restricted.gif")
|
65
64
|
@file.binmode
|
66
65
|
|
67
66
|
@attachment.assign(@file)
|
@@ -79,7 +78,7 @@ describe Paperclip::AttachmentAdapter do
|
|
79
78
|
end
|
80
79
|
|
81
80
|
it "does not generate filenames that include restricted characters" do
|
82
|
-
assert_equal
|
81
|
+
assert_equal "image_restricted.gif", @subject.original_filename
|
83
82
|
end
|
84
83
|
end
|
85
84
|
|
@@ -121,7 +120,7 @@ describe Paperclip::AttachmentAdapter do
|
|
121
120
|
end
|
122
121
|
|
123
122
|
it "returns false for a call to nil?" do
|
124
|
-
assert
|
123
|
+
assert !@subject.nil?
|
125
124
|
end
|
126
125
|
|
127
126
|
it "generates a MD5 hash of the contents" do
|
@@ -133,10 +132,9 @@ describe Paperclip::AttachmentAdapter do
|
|
133
132
|
@thumb.rewind
|
134
133
|
expected = @thumb.read
|
135
134
|
actual = @subject.read
|
136
|
-
assert expected.
|
135
|
+
assert !expected.empty?
|
137
136
|
assert_equal expected.length, actual.length
|
138
137
|
assert_equal expected, actual
|
139
138
|
end
|
140
|
-
|
141
139
|
end
|
142
140
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::DataUriAdapter do
|
4
4
|
before do
|
@@ -13,12 +13,12 @@ describe Paperclip::DataUriAdapter do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it "allows a missing mime-type" do
|
17
17
|
adapter = Paperclip.io_adapters.for("data:;base64,#{original_base64_content}")
|
18
18
|
assert_equal Paperclip::DataUriAdapter, adapter.class
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it "alows mime type that has dot in it" do
|
22
22
|
adapter = Paperclip.io_adapters.for("data:image/vnd.microsoft.icon;base64,#{original_base64_content}")
|
23
23
|
assert_equal Paperclip::DataUriAdapter, adapter.class
|
24
24
|
end
|
@@ -57,26 +57,25 @@ describe Paperclip::DataUriAdapter do
|
|
57
57
|
assert_equal @subject.fingerprint, @subject.fingerprint
|
58
58
|
end
|
59
59
|
|
60
|
-
it
|
61
|
-
@subject.content_type =
|
62
|
-
assert_equal
|
60
|
+
it "accepts a content_type" do
|
61
|
+
@subject.content_type = "image/png"
|
62
|
+
assert_equal "image/png", @subject.content_type
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
66
|
-
@subject.original_filename =
|
67
|
-
assert_equal
|
65
|
+
it "accepts an original_filename" do
|
66
|
+
@subject.original_filename = "image.png"
|
67
|
+
assert_equal "image.png", @subject.original_filename
|
68
68
|
end
|
69
69
|
|
70
70
|
it "does not generate filenames that include restricted characters" do
|
71
|
-
@subject.original_filename =
|
72
|
-
assert_equal
|
71
|
+
@subject.original_filename = "image:restricted.png"
|
72
|
+
assert_equal "image_restricted.png", @subject.original_filename
|
73
73
|
end
|
74
74
|
|
75
75
|
it "does not generate paths that include restricted characters" do
|
76
|
-
@subject.original_filename =
|
76
|
+
@subject.original_filename = "image:restricted.png"
|
77
77
|
expect(@subject.path).to_not match(/:/)
|
78
78
|
end
|
79
|
-
|
80
79
|
end
|
81
80
|
|
82
81
|
def original_base64_content
|
@@ -84,6 +83,6 @@ describe Paperclip::DataUriAdapter do
|
|
84
83
|
end
|
85
84
|
|
86
85
|
def original_file_contents
|
87
|
-
@original_file_contents ||= File.read(fixture_file(
|
86
|
+
@original_file_contents ||= File.read(fixture_file("5k.png"))
|
88
87
|
end
|
89
88
|
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::EmptyStringAdapter do
|
4
|
-
context
|
4
|
+
context "a new instance" do
|
5
5
|
before do
|
6
|
-
@subject = Paperclip.io_adapters.for(
|
6
|
+
@subject = Paperclip.io_adapters.for("")
|
7
7
|
end
|
8
8
|
|
9
9
|
it "returns false for a call to nil?" do
|
10
10
|
assert !@subject.nil?
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it "returns false for a call to assignment?" do
|
14
14
|
assert !@subject.assignment?
|
15
15
|
end
|
16
16
|
end
|