kt-paperclip 5.4.0 → 7.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  4. data/.github/ISSUE_TEMPLATE/custom.md +10 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.hound.yml +3 -1055
  7. data/.rubocop.yml +1061 -1
  8. data/.travis.yml +23 -4
  9. data/Appraisals +23 -0
  10. data/CONTRIBUTING.md +4 -5
  11. data/Gemfile +10 -7
  12. data/NEWS +52 -0
  13. data/README.md +58 -46
  14. data/Rakefile +29 -21
  15. data/UPGRADING +3 -3
  16. data/features/basic_integration.feature +4 -0
  17. data/features/migration.feature +10 -51
  18. data/features/step_definitions/attachment_steps.rb +23 -13
  19. data/features/step_definitions/html_steps.rb +5 -5
  20. data/features/step_definitions/rails_steps.rb +29 -9
  21. data/features/step_definitions/s3_steps.rb +3 -3
  22. data/features/step_definitions/web_steps.rb +5 -6
  23. data/features/support/env.rb +4 -4
  24. data/features/support/fakeweb.rb +3 -5
  25. data/features/support/file_helpers.rb +2 -2
  26. data/features/support/paths.rb +4 -4
  27. data/features/support/rails.rb +7 -7
  28. data/features/support/selectors.rb +1 -1
  29. data/gemfiles/4.2.gemfile +7 -4
  30. data/gemfiles/5.0.gemfile +7 -4
  31. data/gemfiles/5.1.gemfile +20 -0
  32. data/gemfiles/5.2.gemfile +20 -0
  33. data/gemfiles/6.0.gemfile +20 -0
  34. data/gemfiles/6.1.gemfile +21 -0
  35. data/gemfiles/7.0.gemfile +21 -0
  36. data/lib/generators/paperclip/paperclip_generator.rb +6 -8
  37. data/lib/paperclip/attachment.rb +103 -105
  38. data/lib/paperclip/attachment_registry.rb +2 -2
  39. data/lib/paperclip/content_type_detector.rb +10 -5
  40. data/lib/paperclip/file_command_content_type_detector.rb +1 -3
  41. data/lib/paperclip/filename_cleaner.rb +0 -1
  42. data/lib/paperclip/geometry.rb +18 -19
  43. data/lib/paperclip/geometry_detector_factory.rb +13 -16
  44. data/lib/paperclip/geometry_parser_factory.rb +5 -5
  45. data/lib/paperclip/glue.rb +3 -3
  46. data/lib/paperclip/has_attached_file.rb +5 -4
  47. data/lib/paperclip/helpers.rb +3 -3
  48. data/lib/paperclip/interpolations.rb +42 -38
  49. data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
  50. data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
  51. data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
  52. data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
  53. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
  54. data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
  55. data/lib/paperclip/io_adapters/registry.rb +1 -1
  56. data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
  57. data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
  58. data/lib/paperclip/io_adapters/uri_adapter.rb +21 -9
  59. data/lib/paperclip/logger.rb +1 -1
  60. data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
  61. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
  62. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
  63. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
  64. data/lib/paperclip/matchers.rb +4 -4
  65. data/lib/paperclip/media_type_spoof_detector.rb +13 -13
  66. data/lib/paperclip/missing_attachment_styles.rb +11 -6
  67. data/lib/paperclip/processor.rb +13 -6
  68. data/lib/paperclip/processor_helpers.rb +3 -1
  69. data/lib/paperclip/rails_environment.rb +1 -5
  70. data/lib/paperclip/railtie.rb +5 -5
  71. data/lib/paperclip/schema.rb +16 -12
  72. data/lib/paperclip/storage/filesystem.rb +6 -8
  73. data/lib/paperclip/storage/fog.rb +36 -32
  74. data/lib/paperclip/storage/s3.rb +68 -76
  75. data/lib/paperclip/style.rb +3 -6
  76. data/lib/paperclip/tempfile.rb +4 -5
  77. data/lib/paperclip/tempfile_factory.rb +0 -1
  78. data/lib/paperclip/thumbnail.rb +11 -11
  79. data/lib/paperclip/url_generator.rb +5 -5
  80. data/lib/paperclip/validators/attachment_content_type_validator.rb +11 -4
  81. data/lib/paperclip/validators/attachment_file_name_validator.rb +14 -12
  82. data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
  83. data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
  84. data/lib/paperclip/validators/attachment_size_validator.rb +28 -11
  85. data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
  86. data/lib/paperclip/validators.rb +16 -17
  87. data/lib/paperclip/version.rb +1 -3
  88. data/lib/paperclip.rb +49 -48
  89. data/lib/tasks/paperclip.rake +23 -24
  90. data/paperclip.gemspec +29 -33
  91. data/shoulda_macros/paperclip.rb +16 -16
  92. data/spec/paperclip/attachment_definitions_spec.rb +5 -5
  93. data/spec/paperclip/attachment_processing_spec.rb +22 -23
  94. data/spec/paperclip/attachment_registry_spec.rb +15 -15
  95. data/spec/paperclip/attachment_spec.rb +238 -196
  96. data/spec/paperclip/content_type_detector_spec.rb +18 -12
  97. data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
  98. data/spec/paperclip/filename_cleaner_spec.rb +3 -4
  99. data/spec/paperclip/geometry_detector_spec.rb +7 -8
  100. data/spec/paperclip/geometry_parser_spec.rb +31 -31
  101. data/spec/paperclip/geometry_spec.rb +24 -24
  102. data/spec/paperclip/glue_spec.rb +3 -5
  103. data/spec/paperclip/has_attached_file_spec.rb +46 -126
  104. data/spec/paperclip/integration_spec.rb +111 -77
  105. data/spec/paperclip/interpolations_spec.rb +101 -93
  106. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
  107. data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
  108. data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
  109. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
  110. data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
  111. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +58 -37
  112. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
  113. data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
  114. data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
  115. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
  116. data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
  117. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +90 -31
  118. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
  119. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
  120. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
  121. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
  122. data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
  123. data/spec/paperclip/meta_class_spec.rb +3 -3
  124. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
  125. data/spec/paperclip/paperclip_spec.rb +15 -11
  126. data/spec/paperclip/plural_cache_spec.rb +8 -8
  127. data/spec/paperclip/processor_helpers_spec.rb +35 -35
  128. data/spec/paperclip/processor_spec.rb +8 -8
  129. data/spec/paperclip/rails_environment_spec.rb +7 -10
  130. data/spec/paperclip/rake_spec.rb +39 -39
  131. data/spec/paperclip/schema_spec.rb +57 -53
  132. data/spec/paperclip/storage/filesystem_spec.rb +29 -6
  133. data/spec/paperclip/storage/fog_spec.rb +122 -82
  134. data/spec/paperclip/storage/s3_live_spec.rb +22 -22
  135. data/spec/paperclip/storage/s3_spec.rb +649 -583
  136. data/spec/paperclip/style_spec.rb +67 -71
  137. data/spec/paperclip/tempfile_factory_spec.rb +5 -5
  138. data/spec/paperclip/thumbnail_spec.rb +68 -67
  139. data/spec/paperclip/url_generator_spec.rb +18 -19
  140. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +115 -27
  141. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +105 -16
  142. data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
  143. data/spec/paperclip/validators/attachment_size_validator_spec.rb +111 -21
  144. data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
  145. data/spec/paperclip/validators_spec.rb +61 -46
  146. data/spec/spec_helper.rb +21 -23
  147. data/spec/support/assertions.rb +8 -6
  148. data/spec/support/fake_model.rb +1 -2
  149. data/spec/support/fake_rails.rb +1 -1
  150. data/spec/support/fixtures/aws_s3.yml +13 -0
  151. data/spec/support/fixtures/sample.xlsm +0 -0
  152. data/spec/support/matchers/exist.rb +1 -1
  153. data/spec/support/matchers/have_column.rb +1 -1
  154. data/spec/support/mock_url_generator_builder.rb +2 -3
  155. data/spec/support/model_reconstruction.rb +16 -12
  156. data/spec/support/reporting.rb +1 -1
  157. data/spec/support/test_data.rb +2 -2
  158. metadata +58 -106
  159. data/spec/support/conditional_filter_helper.rb +0 -5
@@ -1,11 +1,11 @@
1
- require 'spec_helper'
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 ! methods.include?(:[])
7
- assert ! methods.include?(:[]=)
8
- assert ! methods.include?(:all)
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 ; end
28
- attachment = mock
29
- attachment.expects(:instance).returns(attachment)
30
- attachment.expects(:class).returns(Thing)
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 = mock
36
- attachment.expects(:original_filename).returns("one.jpg").times(1)
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 = mock
42
- attachment.expects(:original_filename).returns("one.jpg")
43
- attachment.expects(:styles).returns({})
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 = mock
49
- attachment.expects(:original_filename).never
50
- attachment.expects(:styles).twice.returns({style: {format: "png"}})
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, 'style'].each do |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 = mock
59
- attachment.expects(:content_type).returns('image/png')
60
- attachment.expects(:styles).returns({})
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.expects(:extension).returns('random')
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 = mock
68
- attachment.expects(:content_type).returns('image/jpeg')
69
- attachment.expects(:styles).returns({})
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.expects(:extension).returns('jpe')
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 = mock
77
- attachment.expects(:original_filename).returns("one.jpg")
78
- attachment.expects(:styles).returns({})
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 = mock
84
- attachment.expects(:original_filename).returns("one")
85
- attachment.expects(:styles).returns({})
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 = mock
91
- attachment.expects(:content_type).at_least_once().returns('not/found')
92
- attachment.expects(:styles).returns({})
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.expects(:extension).returns('random')
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 = mock
100
- attachment.expects(:content_type).returns('image/jpeg')
101
- attachment.expects(:styles).returns({style: {format: "png"}})
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.expects(:extension).returns('random')
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 = mock(
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 = mock
116
- attachment.expects(:to_param).returns("23-awesome")
117
- attachment.expects(:instance).returns(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 = mock
123
- attachment.expects(:id).returns(23)
124
- attachment.expects(:instance).returns(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 = mock
130
- attachment.expects(:id).returns(nil)
131
- attachment.expects(:instance).returns(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 = mock
137
- attachment.expects(:id).returns(23)
138
- attachment.expects(:instance).returns(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 = mock
144
- attachment.expects(:id).returns("32fnj23oio2f")
145
- attachment.expects(:instance).returns(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 = mock
151
- attachment.expects(:id).returns(nil)
152
- attachment.expects(:instance).returns(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 = mock
158
- attachment.expects(:name).returns("file")
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 = mock
168
- attachment.expects(:default_style).returns(:default_style)
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 = mock
174
- attachment.expects(:url).with(:style, timestamp: false, escape: false).returns("1234")
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(*args)
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 = mock
190
- attachment.expects(:styles).returns({})
191
- attachment.expects(:original_filename).returns("one.jpg").times(2)
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 = mock
197
- attachment.expects(:styles).returns({style: {format: :png}})
198
- attachment.expects(:original_filename).returns("one.jpg").times(1)
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 = mock
204
- attachment.stubs(:styles).returns({})
205
- attachment.stubs(:original_filename).returns("one")
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 = mock
211
- attachment.stubs(:styles).returns({})
212
- attachment.stubs(:original_filename).returns("one.ab)")
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 = 'UTC'
219
- attachment = mock
220
- attachment.expects(:instance_read).with(:updated_at).returns(now)
221
- attachment.expects(:time_zone).returns(zone)
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 = mock
234
+ attachment = spy
227
235
  seconds_since_epoch = 1234567890
228
- attachment.expects(:updated_at).returns(seconds_since_epoch)
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 = mock
241
+ attachment = spy
234
242
  fake_hash = "a_wicked_secure_hash"
235
- attachment.expects(:hash_key).returns(fake_hash)
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 = mock
248
+ attachment = spy
241
249
  fake_hash = "a_wicked_secure_hash"
242
- attachment.expects(:hash_key).never.returns(fake_hash)
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.expects(:id).with(:attachment, :style).returns(1234)
248
- Paperclip::Interpolations.expects(:attachment).with(:attachment, :style).returns("attachments")
249
- Paperclip::Interpolations.expects(:notreal).never
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.expects(:fool).never
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 'spec_helper'
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.stubs(:path).returns("image.png")
17
- Paperclip.stubs(:run).returns("image/png\n")
18
- Paperclip::ContentTypeDetector.any_instance.stubs(:type_from_mime_magic).returns("image/png")
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_marcel).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 = stub("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.stubs(method)
39
+ allow(subject.tempfile).to receive(method)
40
40
  subject.public_send(method)
41
- assert_received subject.tempfile, method
41
+ expect(subject.tempfile).to have_received(method)
42
42
  end
43
43
  end
44
44
  end
45
45
 
46
- it 'gets rid of slashes and colons in filenames' do
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 'is an assignment' do
52
+ it "is an assignment" do
53
53
  assert subject.assignment?
54
54
  end
55
55
 
56
- it 'is not nil' do
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 'uses the original filename to generate the tempfile' do
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.stubs(:path).returns(fixture_file("50x50.png"))
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.expects(:ln).raises(Errno::EXDEV)
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 'spec_helper'
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: '50x50'}
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 ! @subject.nil?
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.length > 0
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.stubs(:original_filename).returns('image:restricted.gif')
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 'image_restricted.gif', @subject.original_filename
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 ! @subject.nil?
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.length > 0
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 'spec_helper'
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 'allows a missing mime-type' do
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 'alows mime type that has dot in it' do
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 'accepts a content_type' do
61
- @subject.content_type = 'image/png'
62
- assert_equal 'image/png', @subject.content_type
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 'accepts an original_filename' do
66
- @subject.original_filename = 'image.png'
67
- assert_equal 'image.png', @subject.original_filename
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 = 'image:restricted.png'
72
- assert_equal 'image_restricted.png', @subject.original_filename
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 = 'image:restricted.png'
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('5k.png'))
86
+ @original_file_contents ||= File.read(fixture_file("5k.png"))
88
87
  end
89
88
  end
@@ -1,16 +1,16 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip::EmptyStringAdapter do
4
- context 'a new instance' do
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 'returns false for a call to assignment?' do
13
+ it "returns false for a call to assignment?" do
14
14
  assert !@subject.assignment?
15
15
  end
16
16
  end