kt-paperclip 4.4.0 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +17 -0
  3. data/.hound.yml +5 -16
  4. data/.travis.yml +15 -12
  5. data/Appraisals +4 -8
  6. data/CONTRIBUTING.md +16 -5
  7. data/Gemfile +3 -8
  8. data/LICENSE +1 -1
  9. data/NEWS +105 -31
  10. data/README.md +239 -153
  11. data/Rakefile +1 -1
  12. data/UPGRADING +12 -9
  13. data/features/basic_integration.feature +3 -2
  14. data/features/migration.feature +0 -24
  15. data/features/step_definitions/attachment_steps.rb +6 -6
  16. data/features/step_definitions/rails_steps.rb +29 -28
  17. data/features/step_definitions/s3_steps.rb +2 -2
  18. data/features/support/env.rb +1 -0
  19. data/features/support/paths.rb +1 -1
  20. data/features/support/rails.rb +0 -24
  21. data/gemfiles/4.2.gemfile +3 -5
  22. data/gemfiles/{3.2.gemfile → 5.0.gemfile} +4 -6
  23. data/lib/generators/paperclip/paperclip_generator.rb +9 -1
  24. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +1 -1
  25. data/lib/paperclip/attachment.rb +25 -14
  26. data/lib/paperclip/attachment_registry.rb +2 -1
  27. data/lib/paperclip/callbacks.rb +8 -6
  28. data/lib/paperclip/content_type_detector.rb +3 -2
  29. data/lib/paperclip/errors.rb +3 -1
  30. data/lib/paperclip/file_command_content_type_detector.rb +1 -1
  31. data/lib/paperclip/geometry_detector_factory.rb +2 -2
  32. data/lib/paperclip/glue.rb +1 -1
  33. data/lib/paperclip/has_attached_file.rb +7 -1
  34. data/lib/paperclip/helpers.rb +15 -11
  35. data/lib/paperclip/interpolations.rb +1 -1
  36. data/lib/paperclip/io_adapters/abstract_adapter.rb +29 -3
  37. data/lib/paperclip/io_adapters/attachment_adapter.rb +10 -5
  38. data/lib/paperclip/io_adapters/data_uri_adapter.rb +8 -8
  39. data/lib/paperclip/io_adapters/empty_string_adapter.rb +5 -4
  40. data/lib/paperclip/io_adapters/file_adapter.rb +12 -6
  41. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +7 -7
  42. data/lib/paperclip/io_adapters/identity_adapter.rb +12 -6
  43. data/lib/paperclip/io_adapters/nil_adapter.rb +8 -5
  44. data/lib/paperclip/io_adapters/registry.rb +6 -2
  45. data/lib/paperclip/io_adapters/stringio_adapter.rb +9 -6
  46. data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +10 -6
  47. data/lib/paperclip/io_adapters/uri_adapter.rb +17 -14
  48. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
  49. data/lib/paperclip/media_type_spoof_detector.rb +3 -2
  50. data/lib/paperclip/processor.rb +5 -4
  51. data/lib/paperclip/schema.rb +4 -10
  52. data/lib/paperclip/storage/filesystem.rb +13 -2
  53. data/lib/paperclip/storage/fog.rb +19 -13
  54. data/lib/paperclip/storage/s3.rb +87 -58
  55. data/lib/paperclip/thumbnail.rb +18 -8
  56. data/lib/paperclip/url_generator.rb +18 -14
  57. data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
  58. data/lib/paperclip/validators.rb +1 -1
  59. data/lib/paperclip/version.rb +3 -1
  60. data/lib/paperclip.rb +13 -12
  61. data/lib/tasks/paperclip.rake +18 -4
  62. data/paperclip.gemspec +13 -11
  63. data/spec/paperclip/attachment_processing_spec.rb +2 -4
  64. data/spec/paperclip/attachment_registry_spec.rb +28 -0
  65. data/spec/paperclip/attachment_spec.rb +72 -18
  66. data/spec/paperclip/content_type_detector_spec.rb +1 -1
  67. data/spec/paperclip/file_command_content_type_detector_spec.rb +15 -1
  68. data/spec/paperclip/has_attached_file_spec.rb +24 -8
  69. data/spec/paperclip/integration_spec.rb +4 -3
  70. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +76 -22
  71. data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +6 -3
  72. data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +7 -1
  73. data/spec/paperclip/io_adapters/file_adapter_spec.rb +2 -2
  74. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +18 -1
  75. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
  76. data/spec/paperclip/io_adapters/registry_spec.rb +2 -2
  77. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +1 -1
  78. data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +5 -5
  79. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +48 -3
  80. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
  81. data/spec/paperclip/media_type_spoof_detector_spec.rb +15 -0
  82. data/spec/paperclip/paperclip_spec.rb +15 -45
  83. data/spec/paperclip/processor_spec.rb +4 -4
  84. data/spec/paperclip/storage/fog_spec.rb +26 -0
  85. data/spec/paperclip/storage/s3_live_spec.rb +20 -14
  86. data/spec/paperclip/storage/s3_spec.rb +357 -190
  87. data/spec/paperclip/tempfile_spec.rb +35 -0
  88. data/spec/paperclip/thumbnail_spec.rb +38 -35
  89. data/spec/paperclip/url_generator_spec.rb +53 -42
  90. data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
  91. data/spec/paperclip/validators_spec.rb +5 -5
  92. data/spec/spec_helper.rb +6 -2
  93. data/spec/support/assertions.rb +12 -1
  94. data/spec/support/conditional_filter_helper.rb +5 -0
  95. data/spec/support/mock_attachment.rb +2 -0
  96. data/spec/support/mock_url_generator_builder.rb +2 -2
  97. data/spec/support/model_reconstruction.rb +10 -2
  98. data/spec/support/reporting.rb +11 -0
  99. metadata +69 -75
  100. data/cucumber/paperclip_steps.rb +0 -6
  101. data/gemfiles/4.1.gemfile +0 -19
  102. data/lib/paperclip/deprecations.rb +0 -42
  103. data/lib/paperclip/locales/de.yml +0 -18
  104. data/lib/paperclip/locales/es.yml +0 -18
  105. data/lib/paperclip/locales/ja.yml +0 -18
  106. data/lib/paperclip/locales/pt-BR.yml +0 -18
  107. data/lib/paperclip/locales/zh-CN.yml +0 -18
  108. data/lib/paperclip/locales/zh-HK.yml +0 -18
  109. data/lib/paperclip/locales/zh-TW.yml +0 -18
  110. data/spec/paperclip/deprecations_spec.rb +0 -65
  111. data/spec/support/deprecations.rb +0 -9
  112. data/spec/support/rails_helpers.rb +0 -7
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe Paperclip::Tempfile do
4
+ context "A Paperclip Tempfile" do
5
+ before do
6
+ @tempfile = described_class.new(["file", ".jpg"])
7
+ end
8
+
9
+ after { @tempfile.close }
10
+
11
+ it "has its path contain a real extension" do
12
+ assert_equal ".jpg", File.extname(@tempfile.path)
13
+ end
14
+
15
+ it "is a real Tempfile" do
16
+ assert @tempfile.is_a?(::Tempfile)
17
+ end
18
+ end
19
+
20
+ context "Another Paperclip Tempfile" do
21
+ before do
22
+ @tempfile = described_class.new("file")
23
+ end
24
+
25
+ after { @tempfile.close }
26
+
27
+ it "does not have an extension if not given one" do
28
+ assert_equal "", File.extname(@tempfile.path)
29
+ end
30
+
31
+ it "is a real Tempfile" do
32
+ assert @tempfile.is_a?(::Tempfile)
33
+ end
34
+ end
35
+ end
@@ -1,38 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Paperclip::Thumbnail do
4
- context "A Paperclip Tempfile" do
5
- before do
6
- @tempfile = Paperclip::Tempfile.new(["file", ".jpg"])
7
- end
8
-
9
- after { @tempfile.close }
10
-
11
- it "has its path contain a real extension" do
12
- assert_equal ".jpg", File.extname(@tempfile.path)
13
- end
14
-
15
- it "is a real Tempfile" do
16
- assert @tempfile.is_a?(::Tempfile)
17
- end
18
- end
19
-
20
- context "Another Paperclip Tempfile" do
21
- before do
22
- @tempfile = Paperclip::Tempfile.new("file")
23
- end
24
-
25
- after { @tempfile.close }
26
-
27
- it "does not have an extension if not given one" do
28
- assert_equal "", File.extname(@tempfile.path)
29
- end
30
-
31
- it "is a real Tempfile" do
32
- assert @tempfile.is_a?(::Tempfile)
33
- end
34
- end
35
-
36
4
  context "An image" do
37
5
  before do
38
6
  @file = File.new(fixture_file("5k.png"), 'rb')
@@ -80,7 +48,7 @@ describe Paperclip::Thumbnail do
80
48
  it "lets us know when a command isn't found versus a processing error" do
81
49
  old_path = ENV['PATH']
82
50
  begin
83
- Cocaine::CommandLine.path = ''
51
+ Terrapin::CommandLine.path = ''
84
52
  Paperclip.options[:command_path] = ''
85
53
  ENV['PATH'] = ''
86
54
  assert_raises(Paperclip::Errors::CommandNotFoundError) do
@@ -134,7 +102,7 @@ describe Paperclip::Thumbnail do
134
102
 
135
103
  output_file = thumb.make
136
104
 
137
- command = Cocaine::CommandLine.new("identify", "-format %wx%h :file")
105
+ command = Terrapin::CommandLine.new("identify", "-format %wx%h :file")
138
106
  assert_equal "50x50", command.run(file: output_file.path).strip
139
107
  end
140
108
 
@@ -221,7 +189,7 @@ describe Paperclip::Thumbnail do
221
189
  it "lets us know when a command isn't found versus a processing error" do
222
190
  old_path = ENV['PATH']
223
191
  begin
224
- Cocaine::CommandLine.path = ''
192
+ Terrapin::CommandLine.path = ''
225
193
  Paperclip.options[:command_path] = ''
226
194
  ENV['PATH'] = ''
227
195
  assert_raises(Paperclip::Errors::CommandNotFoundError) do
@@ -480,6 +448,41 @@ describe Paperclip::Thumbnail do
480
448
  assert_equal "50x50", `#{cmd}`.chomp
481
449
  end
482
450
  end
451
+
452
+ context "with a specified frame_index" do
453
+ before do
454
+ @thumb = Paperclip::Thumbnail.new(
455
+ @file,
456
+ geometry: "50x50",
457
+ frame_index: 5,
458
+ format: :jpg,
459
+ )
460
+ end
461
+
462
+ it "creates the thumbnail from the frame index when sent #make" do
463
+ @thumb.make
464
+ assert_equal 5, @thumb.frame_index
465
+ end
466
+ end
467
+
468
+ context "with a specified frame_index out of bounds" do
469
+ before do
470
+ @thumb = Paperclip::Thumbnail.new(
471
+ @file,
472
+ geometry: "50x50",
473
+ frame_index: 20,
474
+ format: :jpg,
475
+ )
476
+ end
477
+
478
+ it "errors when trying to create the thumbnail" do
479
+ assert_raises(Paperclip::Error) do
480
+ silence_stream(STDERR) do
481
+ @thumb.make
482
+ end
483
+ end
484
+ end
485
+ end
483
486
  end
484
487
 
485
488
  context "with a really long file name" do
@@ -4,11 +4,10 @@ require 'spec_helper'
4
4
  describe Paperclip::UrlGenerator do
5
5
  it "uses the given interpolator" do
6
6
  expected = "the expected result"
7
- mock_attachment = MockAttachment.new
8
7
  mock_interpolator = MockInterpolator.new(result: expected)
8
+ mock_attachment = MockAttachment.new(interpolator: mock_interpolator)
9
9
 
10
- url_generator = Paperclip::UrlGenerator.new(mock_attachment,
11
- { interpolator: mock_interpolator })
10
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
12
11
  result = url_generator.for(:style_name, {})
13
12
 
14
13
  assert_equal expected, result
@@ -17,12 +16,12 @@ describe Paperclip::UrlGenerator do
17
16
  end
18
17
 
19
18
  it "uses the default URL when no file is assigned" do
20
- mock_attachment = MockAttachment.new
21
19
  mock_interpolator = MockInterpolator.new
22
20
  default_url = "the default url"
23
- options = { interpolator: mock_interpolator, default_url: default_url}
21
+ options = { interpolator: mock_interpolator, default_url: default_url }
22
+ mock_attachment = MockAttachment.new(options)
24
23
 
25
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
24
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
26
25
  url_generator.for(:style_name, {})
27
26
 
28
27
  assert mock_interpolator.has_interpolated_pattern?(default_url),
@@ -30,12 +29,12 @@ describe Paperclip::UrlGenerator do
30
29
  end
31
30
 
32
31
  it "executes the default URL lambda when no file is assigned" do
33
- mock_attachment = MockAttachment.new
34
32
  mock_interpolator = MockInterpolator.new
35
33
  default_url = lambda {|attachment| "the #{attachment.class.name} default url" }
36
34
  options = { interpolator: mock_interpolator, default_url: default_url}
35
+ mock_attachment = MockAttachment.new(options)
37
36
 
38
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
37
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
39
38
  url_generator.for(:style_name, {})
40
39
 
41
40
  assert mock_interpolator.has_interpolated_pattern?("the MockAttachment default url"),
@@ -44,12 +43,16 @@ describe Paperclip::UrlGenerator do
44
43
 
45
44
  it "executes the method named by the symbol as the default URL when no file is assigned" do
46
45
  mock_model = FakeModel.new
47
- mock_attachment = MockAttachment.new(model: mock_model)
48
- mock_interpolator = MockInterpolator.new
49
46
  default_url = :to_s
50
- options = { interpolator: mock_interpolator, default_url: default_url}
47
+ mock_interpolator = MockInterpolator.new
48
+ options = {
49
+ interpolator: mock_interpolator,
50
+ default_url: default_url,
51
+ model: mock_model,
52
+ }
53
+ mock_attachment = MockAttachment.new(options)
51
54
 
52
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
55
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
53
56
  url_generator.for(:style_name, {})
54
57
 
55
58
  assert mock_interpolator.has_interpolated_pattern?(mock_model.to_s),
@@ -58,10 +61,10 @@ describe Paperclip::UrlGenerator do
58
61
 
59
62
  it "URL-escapes spaces if asked to" do
60
63
  expected = "the expected result"
61
- mock_attachment = MockAttachment.new
62
64
  mock_interpolator = MockInterpolator.new(result: expected)
63
65
  options = { interpolator: mock_interpolator }
64
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
66
+ mock_attachment = MockAttachment.new(options)
67
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
65
68
 
66
69
  result = url_generator.for(:style_name, {escape: true})
67
70
 
@@ -74,10 +77,10 @@ describe Paperclip::UrlGenerator do
74
77
  "the escaped result"
75
78
  end
76
79
  end.new
77
- mock_attachment = MockAttachment.new
78
80
  mock_interpolator = MockInterpolator.new(result: expected)
79
81
  options = { interpolator: mock_interpolator }
80
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
82
+ mock_attachment = MockAttachment.new(options)
83
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
81
84
 
82
85
  result = url_generator.for(:style_name, {escape: true})
83
86
 
@@ -86,10 +89,10 @@ describe Paperclip::UrlGenerator do
86
89
 
87
90
  it "leaves spaces unescaped as asked to" do
88
91
  expected = "the expected result"
89
- mock_attachment = MockAttachment.new
90
92
  mock_interpolator = MockInterpolator.new(result: expected)
91
93
  options = { interpolator: mock_interpolator }
92
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
94
+ mock_attachment = MockAttachment.new(options)
95
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
93
96
 
94
97
  result = url_generator.for(:style_name, {escape: false})
95
98
 
@@ -98,10 +101,10 @@ describe Paperclip::UrlGenerator do
98
101
 
99
102
  it "defaults to leaving spaces unescaped" do
100
103
  expected = "the expected result"
101
- mock_attachment = MockAttachment.new
102
104
  mock_interpolator = MockInterpolator.new(result: expected)
103
105
  options = { interpolator: mock_interpolator }
104
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
106
+ mock_attachment = MockAttachment.new(options)
107
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
105
108
 
106
109
  result = url_generator.for(:style_name, {})
107
110
 
@@ -111,9 +114,9 @@ describe Paperclip::UrlGenerator do
111
114
  it "produces URLs without the updated_at value when the object does not respond to updated_at" do
112
115
  expected = "the expected result"
113
116
  mock_interpolator = MockInterpolator.new(result: expected)
114
- mock_attachment = MockAttachment.new(responds_to_updated_at: false)
115
- options = { interpolator: mock_interpolator }
116
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
117
+ options = { interpolator: mock_interpolator, responds_to_updated_at: false }
118
+ mock_attachment = MockAttachment.new(options)
119
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
117
120
 
118
121
  result = url_generator.for(:style_name, {timestamp: true})
119
122
 
@@ -123,9 +126,13 @@ describe Paperclip::UrlGenerator do
123
126
  it "produces URLs without the updated_at value when the updated_at value is nil" do
124
127
  expected = "the expected result"
125
128
  mock_interpolator = MockInterpolator.new(result: expected)
126
- mock_attachment = MockAttachment.new(responds_to_updated_at: true, updated_at: nil)
127
- options = { interpolator: mock_interpolator }
128
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
129
+ options = {
130
+ responds_to_updated_at: true,
131
+ updated_at: nil,
132
+ interpolator: mock_interpolator,
133
+ }
134
+ mock_attachment = MockAttachment.new(options)
135
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
129
136
 
130
137
  result = url_generator.for(:style_name, {timestamp: true})
131
138
 
@@ -136,9 +143,9 @@ describe Paperclip::UrlGenerator do
136
143
  expected = "the expected result"
137
144
  updated_at = 1231231234
138
145
  mock_interpolator = MockInterpolator.new(result: expected)
139
- mock_attachment = MockAttachment.new(updated_at: updated_at)
140
- options = { interpolator: mock_interpolator }
141
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
146
+ options = { interpolator: mock_interpolator, updated_at: updated_at }
147
+ mock_attachment = MockAttachment.new(options)
148
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
142
149
 
143
150
  result = url_generator.for(:style_name, {timestamp: true})
144
151
 
@@ -149,9 +156,9 @@ describe Paperclip::UrlGenerator do
149
156
  expected = "the?expected=result"
150
157
  updated_at = 1231231234
151
158
  mock_interpolator = MockInterpolator.new(result: expected)
152
- mock_attachment = MockAttachment.new(updated_at: updated_at)
153
- options = { interpolator: mock_interpolator }
154
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
159
+ options = { interpolator: mock_interpolator, updated_at: updated_at }
160
+ mock_attachment = MockAttachment.new(options)
161
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
155
162
 
156
163
  result = url_generator.for(:style_name, {timestamp: true})
157
164
 
@@ -162,9 +169,9 @@ describe Paperclip::UrlGenerator do
162
169
  expected = "the expected result"
163
170
  updated_at = 1231231234
164
171
  mock_interpolator = MockInterpolator.new(result: expected)
165
- mock_attachment = MockAttachment.new(updated_at: updated_at)
166
- options = { interpolator: mock_interpolator }
167
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
172
+ options = { interpolator: mock_interpolator, updated_at: updated_at }
173
+ mock_attachment = MockAttachment.new(options)
174
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
168
175
 
169
176
  result = url_generator.for(:style_name, {timestamp: false})
170
177
 
@@ -173,11 +180,15 @@ describe Paperclip::UrlGenerator do
173
180
 
174
181
  it "produces the correct URL when the instance has a file name" do
175
182
  expected = "the expected result"
176
- mock_attachment = MockAttachment.new(original_filename: 'exists')
177
183
  mock_interpolator = MockInterpolator.new
178
- options = { interpolator: mock_interpolator, url: expected}
184
+ options = {
185
+ interpolator: mock_interpolator,
186
+ url: expected,
187
+ original_filename: "exists",
188
+ }
189
+ mock_attachment = MockAttachment.new(options)
179
190
 
180
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
191
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
181
192
  url_generator.for(:style_name, {})
182
193
 
183
194
  assert mock_interpolator.has_interpolated_pattern?(expected),
@@ -189,17 +200,17 @@ describe Paperclip::UrlGenerator do
189
200
  mock_interpolator = MockInterpolator.new(result: expected)
190
201
  options = { interpolator: mock_interpolator }
191
202
  mock_attachment = MockAttachment.new(options)
192
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
203
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
193
204
 
194
205
  expect { url_generator.for(:style_name, escape: true) }.to_not(output(/URI\.(un)?escape is obsolete/).to_stderr)
195
206
  end
196
207
 
197
208
  describe "should be able to escape (, ), [, and ]." do
198
209
  def generate(expected, updated_at=nil)
199
- mock_attachment = MockAttachment.new(updated_at: updated_at)
200
210
  mock_interpolator = MockInterpolator.new(result: expected)
201
- options = { interpolator: mock_interpolator }
202
- url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
211
+ options = { interpolator: mock_interpolator, updated_at: updated_at }
212
+ mock_attachment = MockAttachment.new(options)
213
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
203
214
  def url_generator.respond_to(params)
204
215
  false if params == :escape
205
216
  end
@@ -12,14 +12,6 @@ describe Paperclip::Validators::AttachmentSizeValidator do
12
12
  ))
13
13
  end
14
14
 
15
- def self.storage_units
16
- if defined?(ActiveSupport::NumberHelper) # Rails 4.0+
17
- { 5120 => '5 KB', 10240 => '10 KB' }
18
- else
19
- { 5120 => '5120 Bytes', 10240 => '10240 Bytes' }
20
- end
21
- end
22
-
23
15
  def self.should_allow_attachment_file_size(size)
24
16
  context "when the attachment size is #{size}" do
25
17
  it "adds error to dummy object" do
@@ -158,8 +150,10 @@ describe Paperclip::Validators::AttachmentSizeValidator do
158
150
  message: "is invalid. (Between %{min} and %{max} please.)"
159
151
  end
160
152
 
161
- should_not_allow_attachment_file_size 11.kilobytes,
162
- message: "is invalid. (Between #{storage_units[5120]} and #{storage_units[10240]} please.)"
153
+ should_not_allow_attachment_file_size(
154
+ 11.kilobytes,
155
+ message: "is invalid. (Between 5 KB and 10 KB please.)"
156
+ )
163
157
  end
164
158
 
165
159
  context "given :less_than and :greater_than" do
@@ -169,8 +163,10 @@ describe Paperclip::Validators::AttachmentSizeValidator do
169
163
  message: "is invalid. (Between %{min} and %{max} please.)"
170
164
  end
171
165
 
172
- should_not_allow_attachment_file_size 11.kilobytes,
173
- message: "is invalid. (Between #{storage_units[5120]} and #{storage_units[10240]} please.)"
166
+ should_not_allow_attachment_file_size(
167
+ 11.kilobytes,
168
+ message: "is invalid. (Between 5 KB and 10 KB please.)"
169
+ )
174
170
  end
175
171
  end
176
172
 
@@ -181,10 +177,15 @@ describe Paperclip::Validators::AttachmentSizeValidator do
181
177
  less_than: 10.kilobytes
182
178
  end
183
179
 
184
- should_not_allow_attachment_file_size 11.kilobytes,
185
- message: "must be less than #{storage_units[10240]}"
186
- should_not_allow_attachment_file_size 4.kilobytes,
187
- message: "must be greater than #{storage_units[5120]}"
180
+ should_not_allow_attachment_file_size(
181
+ 11.kilobytes,
182
+ message: "must be less than 10 KB"
183
+ )
184
+
185
+ should_not_allow_attachment_file_size(
186
+ 4.kilobytes,
187
+ message: "must be greater than 5 KB"
188
+ )
188
189
  end
189
190
 
190
191
  context "given a size range" do
@@ -192,10 +193,15 @@ describe Paperclip::Validators::AttachmentSizeValidator do
192
193
  build_validator in: (5.kilobytes..10.kilobytes)
193
194
  end
194
195
 
195
- should_not_allow_attachment_file_size 11.kilobytes,
196
- message: "must be in between #{storage_units[5120]} and #{storage_units[10240]}"
197
- should_not_allow_attachment_file_size 4.kilobytes,
198
- message: "must be in between #{storage_units[5120]} and #{storage_units[10240]}"
196
+ should_not_allow_attachment_file_size(
197
+ 11.kilobytes,
198
+ message: "must be in between 5 KB and 10 KB"
199
+ )
200
+
201
+ should_not_allow_attachment_file_size(
202
+ 4.kilobytes,
203
+ message: "must be in between 5 KB and 10 KB"
204
+ )
199
205
  end
200
206
  end
201
207
 
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe Paperclip::Validators do
4
4
  context "using the helper" do
5
5
  before do
6
+ rebuild_class
6
7
  Dummy.validates_attachment :avatar, presence: true, content_type: { content_type: "image/jpeg" }, size: { in: 0..10240 }
7
8
  end
8
9
 
@@ -30,8 +31,8 @@ describe Paperclip::Validators do
30
31
  before do
31
32
  rebuild_class
32
33
  Dummy.validates_attachment :avatar, file_type_ignorance: true, file_name: [
33
- { matches: /\A.*\.jpe?g\Z/i, message: :invalid_extension },
34
- { matches: /\A.{,8}\..+\Z/i, message: [:too_long, count: 8] },
34
+ { matches: /\A.*\.jpe?g\z/i, message: :invalid_extension },
35
+ { matches: /\A.{,8}\..+\z/i, message: [:too_long, count: 8] },
35
36
  ]
36
37
  end
37
38
 
@@ -64,12 +65,11 @@ describe Paperclip::Validators do
64
65
  assert_raises(RuntimeError){ dummy.valid? }
65
66
  end
66
67
 
67
- it 'allows you to attach a file that does not violates these validations' do
68
+ it 'allows you to attach a file that does not violate these validations' do
68
69
  dummy = Dummy.new(avatar: File.new(fixture_file('rotated.jpg')))
69
- expect(dummy.errors.keys).to match_array []
70
+ expect(dummy.errors.full_messages).to be_empty
70
71
  assert dummy.valid?
71
72
  end
72
-
73
73
  end
74
74
 
75
75
  context "using the helper with a conditional" do
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,8 @@ require 'active_support/core_ext'
7
7
  require 'mocha/api'
8
8
  require 'bourne'
9
9
  require 'ostruct'
10
+ require 'pathname'
11
+ require 'activerecord-import'
10
12
 
11
13
  ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
12
14
 
@@ -20,7 +22,8 @@ FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
20
22
  config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
21
23
  ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
22
24
  ActiveRecord::Base.establish_connection(config['test'])
23
- unless ActiveRecord::VERSION::STRING < "4.2"
25
+ if ActiveRecord::VERSION::STRING >= "4.2" &&
26
+ ActiveRecord::VERSION::STRING < "5.0"
24
27
  ActiveRecord::Base.raise_in_transactional_callbacks = true
25
28
  end
26
29
  Paperclip.options[:logger] = ActiveRecord::Base.logger
@@ -34,8 +37,9 @@ RSpec.configure do |config|
34
37
  config.include Assertions
35
38
  config.include ModelReconstruction
36
39
  config.include TestData
40
+ config.include Reporting
37
41
  config.extend VersionHelper
38
- config.extend RailsHelpers::ClassMethods
42
+ config.extend ConditionalFilterHelper
39
43
  config.mock_framework = :mocha
40
44
  config.before(:all) do
41
45
  rebuild_model
@@ -48,19 +48,30 @@ module Assertions
48
48
  end
49
49
 
50
50
  def assert_success_response(url)
51
+ url = "http:#{url}" unless url =~ /http/
51
52
  Net::HTTP.get_response(URI.parse(url)) do |response|
52
- assert_equal "200", response.code,
53
+ assert_equal "200",
54
+ response.code,
53
55
  "Expected HTTP response code 200, got #{response.code}"
54
56
  end
55
57
  end
56
58
 
57
59
  def assert_not_found_response(url)
60
+ url = "http:#{url}" unless url =~ /http/
58
61
  Net::HTTP.get_response(URI.parse(url)) do |response|
59
62
  assert_equal "404", response.code,
60
63
  "Expected HTTP response code 404, got #{response.code}"
61
64
  end
62
65
  end
63
66
 
67
+ def assert_forbidden_response(url)
68
+ url = "http:#{url}" unless url =~ /http/
69
+ Net::HTTP.get_response(URI.parse(url)) do |response|
70
+ assert_equal "403", response.code,
71
+ "Expected HTTP response code 403, got #{response.code}"
72
+ end
73
+ end
74
+
64
75
  def assert_frame_dimensions(range, frames)
65
76
  frames.each_with_index do |frame, frame_index|
66
77
  frame.split('x').each_with_index do |dimension, dimension_index |
@@ -0,0 +1,5 @@
1
+ module ConditionalFilterHelper
2
+ def aws_accelerate_available?
3
+ (Gem::Version.new(Aws::VERSION) >= Gem::Version.new("2.3.0"))
4
+ end
5
+ end
@@ -1,7 +1,9 @@
1
1
  class MockAttachment
2
2
  attr_accessor :updated_at, :original_filename
3
+ attr_reader :options
3
4
 
4
5
  def initialize(options = {})
6
+ @options = options
5
7
  @model = options[:model]
6
8
  @responds_to_updated_at = options[:responds_to_updated_at]
7
9
  @updated_at = options[:updated_at]
@@ -2,9 +2,9 @@ class MockUrlGeneratorBuilder
2
2
  def initializer
3
3
  end
4
4
 
5
- def new(attachment, attachment_options)
5
+ def new(attachment)
6
6
  @attachment = attachment
7
- @attachment_options = attachment_options
7
+ @attachment_options = @attachment.options
8
8
  self
9
9
  end
10
10
 
@@ -10,7 +10,15 @@ module ModelReconstruction
10
10
 
11
11
  klass.reset_column_information
12
12
  klass.connection_pool.clear_table_cache!(klass.table_name) if klass.connection_pool.respond_to?(:clear_table_cache!)
13
- klass.connection.schema_cache.clear_table_cache!(klass.table_name) if klass.connection.respond_to?(:schema_cache)
13
+
14
+ if klass.connection.respond_to?(:schema_cache)
15
+ if ActiveRecord::VERSION::STRING >= "5.0"
16
+ klass.connection.schema_cache.clear_data_source_cache!(klass.table_name)
17
+ else
18
+ klass.connection.schema_cache.clear_table_cache!(klass.table_name)
19
+ end
20
+ end
21
+
14
22
  klass
15
23
  end
16
24
 
@@ -20,7 +28,7 @@ module ModelReconstruction
20
28
  end
21
29
 
22
30
  def modify_table table_name, &block
23
- ActiveRecord::Base.connection.create_table :dummies, **{force: true}, &block
31
+ ActiveRecord::Base.connection.change_table :dummies, &block
24
32
  end
25
33
 
26
34
  def rebuild_model options = {}
@@ -0,0 +1,11 @@
1
+ module Reporting
2
+ def silence_stream(stream)
3
+ old_stream = stream.dup
4
+ stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
5
+ stream.sync = true
6
+ yield
7
+ ensure
8
+ stream.reopen(old_stream)
9
+ old_stream.close
10
+ end
11
+ end