paperclip 4.1.1 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of paperclip might be problematic. Click here for more details.

Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -6
  3. data/.travis.yml +4 -13
  4. data/Appraisals +0 -10
  5. data/CONTRIBUTING.md +10 -5
  6. data/Gemfile +8 -4
  7. data/NEWS +1 -1
  8. data/README.md +51 -10
  9. data/Rakefile +6 -8
  10. data/features/basic_integration.feature +5 -5
  11. data/features/step_definitions/attachment_steps.rb +4 -4
  12. data/features/step_definitions/rails_steps.rb +4 -4
  13. data/features/step_definitions/web_steps.rb +2 -2
  14. data/features/support/env.rb +2 -2
  15. data/features/support/fixtures/gemfile.txt +1 -1
  16. data/features/support/rails.rb +2 -1
  17. data/gemfiles/3.2.gemfile +5 -3
  18. data/gemfiles/4.0.gemfile +5 -3
  19. data/gemfiles/4.1.gemfile +5 -3
  20. data/lib/generators/paperclip/paperclip_generator.rb +0 -2
  21. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +1 -1
  22. data/lib/paperclip.rb +4 -1
  23. data/lib/paperclip/attachment.rb +90 -29
  24. data/lib/paperclip/content_type_detector.rb +1 -1
  25. data/lib/paperclip/geometry_detector_factory.rb +3 -1
  26. data/lib/paperclip/has_attached_file.rb +2 -1
  27. data/lib/paperclip/interpolations.rb +8 -0
  28. data/lib/paperclip/io_adapters/abstract_adapter.rb +1 -1
  29. data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
  30. data/lib/paperclip/io_adapters/stringio_adapter.rb +5 -11
  31. data/lib/paperclip/locales/de.yml +18 -0
  32. data/lib/paperclip/locales/es.yml +18 -0
  33. data/lib/paperclip/matchers/have_attached_file_matcher.rb +2 -1
  34. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +2 -1
  35. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +2 -1
  36. data/lib/paperclip/media_type_spoof_detector.rb +10 -2
  37. data/lib/paperclip/storage/filesystem.rb +1 -1
  38. data/lib/paperclip/storage/s3.rb +26 -4
  39. data/lib/paperclip/style.rb +1 -1
  40. data/lib/paperclip/thumbnail.rb +6 -6
  41. data/lib/paperclip/validators.rb +5 -3
  42. data/lib/paperclip/validators/attachment_size_validator.rb +7 -3
  43. data/lib/paperclip/version.rb +1 -1
  44. data/lib/tasks/paperclip.rake +1 -2
  45. data/paperclip.gemspec +5 -3
  46. data/shoulda_macros/paperclip.rb +0 -1
  47. data/{test → spec}/database.yml +0 -0
  48. data/spec/paperclip/attachment_definitions_spec.rb +13 -0
  49. data/{test/attachment_processing_test.rb → spec/paperclip/attachment_processing_spec.rb} +20 -21
  50. data/{test/attachment_registry_test.rb → spec/paperclip/attachment_registry_spec.rb} +10 -11
  51. data/{test/attachment_test.rb → spec/paperclip/attachment_spec.rb} +367 -360
  52. data/{test/content_type_detector_test.rb → spec/paperclip/content_type_detector_spec.rb} +8 -8
  53. data/{test/file_command_content_type_detector_test.rb → spec/paperclip/file_command_content_type_detector_spec.rb} +5 -5
  54. data/spec/paperclip/filename_cleaner_spec.rb +14 -0
  55. data/spec/paperclip/geometry_detector_spec.rb +39 -0
  56. data/{test/geometry_parser_test.rb → spec/paperclip/geometry_parser_spec.rb} +27 -27
  57. data/{test/geometry_test.rb → spec/paperclip/geometry_spec.rb} +49 -51
  58. data/{test/has_attached_file_test.rb → spec/paperclip/has_attached_file_spec.rb} +18 -27
  59. data/{test/integration_test.rb → spec/paperclip/integration_spec.rb} +134 -126
  60. data/{test/interpolations_test.rb → spec/paperclip/interpolations_spec.rb} +54 -40
  61. data/{test/io_adapters/abstract_adapter_test.rb → spec/paperclip/io_adapters/abstract_adapter_spec.rb} +21 -10
  62. data/{test/io_adapters/attachment_adapter_test.rb → spec/paperclip/io_adapters/attachment_adapter_spec.rb} +27 -29
  63. data/{test/io_adapters/data_uri_adapter_test.rb → spec/paperclip/io_adapters/data_uri_adapter_spec.rb} +22 -18
  64. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +17 -0
  65. data/{test/io_adapters/file_adapter_test.rb → spec/paperclip/io_adapters/file_adapter_spec.rb} +32 -28
  66. data/{test/io_adapters/http_url_proxy_adapter_test.rb → spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb} +22 -22
  67. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +8 -0
  68. data/{test/io_adapters/nil_adapter_test.rb → spec/paperclip/io_adapters/nil_adapter_spec.rb} +7 -7
  69. data/{test/io_adapters/registry_test.rb → spec/paperclip/io_adapters/registry_spec.rb} +10 -7
  70. data/{test/io_adapters/stringio_adapter_test.rb → spec/paperclip/io_adapters/stringio_adapter_spec.rb} +16 -17
  71. data/{test/io_adapters/uploaded_file_adapter_test.rb → spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb} +41 -41
  72. data/{test/io_adapters/uri_adapter_test.rb → spec/paperclip/io_adapters/uri_adapter_spec.rb} +22 -22
  73. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +19 -0
  74. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +99 -0
  75. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +69 -0
  76. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +88 -0
  77. data/{test/media_type_spoof_detector_test.rb → spec/paperclip/media_type_spoof_detector_spec.rb} +13 -8
  78. data/spec/paperclip/meta_class_spec.rb +30 -0
  79. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +84 -0
  80. data/{test/paperclip_test.rb → spec/paperclip/paperclip_spec.rb} +47 -47
  81. data/{test/plural_cache_test.rb → spec/paperclip/plural_cache_spec.rb} +6 -6
  82. data/{test/processor_test.rb → spec/paperclip/processor_spec.rb} +5 -5
  83. data/{test/rake_test.rb → spec/paperclip/rake_spec.rb} +15 -15
  84. data/spec/paperclip/schema_spec.rb +206 -0
  85. data/{test/storage/filesystem_test.rb → spec/paperclip/storage/filesystem_spec.rb} +18 -18
  86. data/{test/storage/fog_test.rb → spec/paperclip/storage/fog_spec.rb} +145 -140
  87. data/spec/paperclip/storage/s3_live_spec.rb +182 -0
  88. data/spec/paperclip/storage/s3_spec.rb +1475 -0
  89. data/spec/paperclip/style_spec.rb +255 -0
  90. data/spec/paperclip/tempfile_factory_spec.rb +29 -0
  91. data/{test/thumbnail_test.rb → spec/paperclip/thumbnail_spec.rb} +107 -107
  92. data/{test/url_generator_test.rb → spec/paperclip/url_generator_spec.rb} +55 -56
  93. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +322 -0
  94. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +160 -0
  95. data/{test/validators/attachment_presence_validator_test.rb → spec/paperclip/validators/attachment_presence_validator_spec.rb} +19 -19
  96. data/{test/validators/attachment_size_validator_test.rb → spec/paperclip/validators/attachment_size_validator_spec.rb} +65 -58
  97. data/{test/validators/media_type_spoof_detection_validator_test.rb → spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb} +8 -8
  98. data/spec/paperclip/validators_spec.rb +164 -0
  99. data/spec/spec_helper.rb +40 -0
  100. data/spec/support/assertions.rb +71 -0
  101. data/spec/support/fake_model.rb +21 -0
  102. data/spec/support/fake_rails.rb +12 -0
  103. data/{test → spec/support}/fixtures/12k.png +0 -0
  104. data/{test → spec/support}/fixtures/50x50.png +0 -0
  105. data/{test → spec/support}/fixtures/5k.png +0 -0
  106. data/{test → spec/support}/fixtures/animated +0 -0
  107. data/{test → spec/support}/fixtures/animated.gif +0 -0
  108. data/{test → spec/support}/fixtures/animated.unknown +0 -0
  109. data/{test → spec/support}/fixtures/bad.png +0 -0
  110. data/{test → spec/support}/fixtures/empty.html +0 -0
  111. data/{test → spec/support}/fixtures/fog.yml +0 -0
  112. data/{test → spec/support}/fixtures/rotated.jpg +0 -0
  113. data/{test → spec/support}/fixtures/s3.yml +0 -0
  114. data/spec/support/fixtures/spaced file.jpg +0 -0
  115. data/test/fixtures/spaced file.png b/data/spec/support/fixtures/spaced → file.png +0 -0
  116. data/{test → spec/support}/fixtures/text.txt +0 -0
  117. data/{test → spec/support}/fixtures/twopage.pdf +0 -0
  118. data/{test → spec/support}/fixtures/uppercase.PNG +0 -0
  119. data/spec/support/matchers/accept.rb +5 -0
  120. data/spec/support/matchers/exist.rb +5 -0
  121. data/{test → spec}/support/mock_attachment.rb +0 -0
  122. data/{test → spec}/support/mock_interpolator.rb +0 -0
  123. data/{test → spec}/support/mock_model.rb +0 -0
  124. data/{test → spec}/support/mock_url_generator_builder.rb +0 -0
  125. data/spec/support/model_reconstruction.rb +60 -0
  126. data/spec/support/rails_helpers.rb +7 -0
  127. data/spec/support/test_data.rb +13 -0
  128. data/spec/support/version_helper.rb +9 -0
  129. metadata +256 -210
  130. data/gemfiles/3.0.gemfile +0 -11
  131. data/gemfiles/3.1.gemfile +0 -11
  132. data/test/attachment_definitions_test.rb +0 -13
  133. data/test/filename_cleaner_test.rb +0 -14
  134. data/test/generator_test.rb +0 -84
  135. data/test/geometry_detector_test.rb +0 -24
  136. data/test/helper.rb +0 -239
  137. data/test/io_adapters/empty_string_adapter_test.rb +0 -18
  138. data/test/io_adapters/identity_adapter_test.rb +0 -8
  139. data/test/matchers/have_attached_file_matcher_test.rb +0 -25
  140. data/test/matchers/validate_attachment_content_type_matcher_test.rb +0 -111
  141. data/test/matchers/validate_attachment_presence_matcher_test.rb +0 -70
  142. data/test/matchers/validate_attachment_size_matcher_test.rb +0 -87
  143. data/test/meta_class_test.rb +0 -32
  144. data/test/paperclip_missing_attachment_styles_test.rb +0 -90
  145. data/test/schema_test.rb +0 -206
  146. data/test/storage/s3_live_test.rb +0 -179
  147. data/test/storage/s3_test.rb +0 -1357
  148. data/test/style_test.rb +0 -251
  149. data/test/tempfile_factory_test.rb +0 -29
  150. data/test/validators/attachment_content_type_validator_test.rb +0 -324
  151. data/test/validators/attachment_file_name_validator_test.rb +0 -162
  152. data/test/validators_test.rb +0 -101
@@ -1,81 +1,82 @@
1
- require './test/helper'
1
+ require 'spec_helper'
2
2
  require 'fog'
3
+ require 'timecop'
3
4
 
4
- class FogTest < Test::Unit::TestCase
5
+ describe Paperclip::Storage::Fog do
5
6
  context "" do
6
- setup { Fog.mock! }
7
+ before { Fog.mock! }
7
8
 
8
9
  context "with credentials provided in a path string" do
9
- setup do
10
- rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
11
- :storage => :fog,
12
- :url => '/:attachment/:filename',
13
- :fog_directory => "paperclip",
14
- :fog_credentials => fixture_file('fog.yml')
10
+ before do
11
+ rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
12
+ storage: :fog,
13
+ url: '/:attachment/:filename',
14
+ fog_directory: "paperclip",
15
+ fog_credentials: fixture_file('fog.yml')
15
16
  @file = File.new(fixture_file('5k.png'), 'rb')
16
17
  @dummy = Dummy.new
17
18
  @dummy.avatar = @file
18
19
  end
19
20
 
20
- teardown { @file.close }
21
+ after { @file.close }
21
22
 
22
- should "have the proper information loading credentials from a file" do
23
+ it "has the proper information loading credentials from a file" do
23
24
  assert_equal @dummy.avatar.fog_credentials[:provider], 'AWS'
24
25
  end
25
26
  end
26
27
 
27
28
  context "with credentials provided in a File object" do
28
- setup do
29
- rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
30
- :storage => :fog,
31
- :url => '/:attachment/:filename',
32
- :fog_directory => "paperclip",
33
- :fog_credentials => File.open(fixture_file('fog.yml'))
29
+ before do
30
+ rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
31
+ storage: :fog,
32
+ url: '/:attachment/:filename',
33
+ fog_directory: "paperclip",
34
+ fog_credentials: File.open(fixture_file('fog.yml'))
34
35
  @file = File.new(fixture_file('5k.png'), 'rb')
35
36
  @dummy = Dummy.new
36
37
  @dummy.avatar = @file
37
38
  end
38
39
 
39
- teardown { @file.close }
40
+ after { @file.close }
40
41
 
41
- should "have the proper information loading credentials from a file" do
42
+ it "has the proper information loading credentials from a file" do
42
43
  assert_equal @dummy.avatar.fog_credentials[:provider], 'AWS'
43
44
  end
44
45
  end
45
46
 
46
47
  context "with default values for path and url" do
47
- setup do
48
- rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
49
- :storage => :fog,
50
- :url => '/:attachment/:filename',
51
- :fog_directory => "paperclip",
52
- :fog_credentials => {
53
- :provider => 'AWS',
54
- :aws_access_key_id => 'AWS_ID',
55
- :aws_secret_access_key => 'AWS_SECRET'
48
+ before do
49
+ rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
50
+ storage: :fog,
51
+ url: '/:attachment/:filename',
52
+ fog_directory: "paperclip",
53
+ fog_credentials: {
54
+ provider: 'AWS',
55
+ aws_access_key_id: 'AWS_ID',
56
+ aws_secret_access_key: 'AWS_SECRET'
56
57
  }
57
58
  @file = File.new(fixture_file('5k.png'), 'rb')
58
59
  @dummy = Dummy.new
59
60
  @dummy.avatar = @file
60
61
  end
61
62
 
62
- teardown { @file.close }
63
+ after { @file.close }
63
64
 
64
- should "be able to interpolate the path without blowing up" do
65
- assert_equal File.expand_path(File.join(File.dirname(__FILE__), "../../tmp/public/avatars/5k.png")),
66
- @dummy.avatar.path
65
+ it "is able to interpolate the path without blowing up" do
66
+ assert_equal File.expand_path(File.join(File.dirname(__FILE__), "../../../tmp/public/avatars/5k.png")),
67
+ @dummy.avatar.path
67
68
  end
68
69
  end
69
70
 
70
71
  context "with no path or url given and using defaults" do
71
- setup do
72
- rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
73
- :storage => :fog,
74
- :fog_directory => "paperclip",
75
- :fog_credentials => {
76
- :provider => 'AWS',
77
- :aws_access_key_id => 'AWS_ID',
78
- :aws_secret_access_key => 'AWS_SECRET'
72
+ before do
73
+ rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
74
+ storage: :fog,
75
+ fog_directory: "paperclip",
76
+ fog_credentials: {
77
+ provider: 'AWS',
78
+ aws_access_key_id: 'AWS_ID',
79
+ aws_secret_access_key: 'AWS_SECRET'
79
80
  }
80
81
  @file = File.new(fixture_file('5k.png'), 'rb')
81
82
  @dummy = Dummy.new
@@ -83,18 +84,18 @@ class FogTest < Test::Unit::TestCase
83
84
  @dummy.avatar = @file
84
85
  end
85
86
 
86
- teardown { @file.close }
87
+ after { @file.close }
87
88
 
88
- should "have correct path and url from interpolated defaults" do
89
+ it "has correct path and url from interpolated defaults" do
89
90
  assert_equal "dummies/avatars/000/000/001/original/5k.png", @dummy.avatar.path
90
91
  end
91
92
  end
92
93
 
93
94
  context "with file params provided as lambda" do
94
- setup do
95
- fog_file = lambda{ |a| { :custom_header => a.instance.custom_method }}
96
- klass = rebuild_model :storage => :fog,
97
- :fog_file => fog_file
95
+ before do
96
+ fog_file = lambda{ |a| { custom_header: a.instance.custom_method }}
97
+ klass = rebuild_model storage: :fog,
98
+ fog_file: fog_file
98
99
 
99
100
  klass.class_eval do
100
101
  def custom_method
@@ -106,56 +107,56 @@ class FogTest < Test::Unit::TestCase
106
107
  @dummy = Dummy.new
107
108
  end
108
109
 
109
- should "be able to evaluate correct values for file headers" do
110
- assert_equal @dummy.avatar.send(:fog_file), { :custom_header => 'foobar' }
110
+ it "is able to evaluate correct values for file headers" do
111
+ assert_equal @dummy.avatar.send(:fog_file), { custom_header: 'foobar' }
111
112
  end
112
113
  end
113
114
 
114
- setup do
115
+ before do
115
116
  @fog_directory = 'papercliptests'
116
117
 
117
118
  @credentials = {
118
- :provider => 'AWS',
119
- :aws_access_key_id => 'ID',
120
- :aws_secret_access_key => 'SECRET'
119
+ provider: 'AWS',
120
+ aws_access_key_id: 'ID',
121
+ aws_secret_access_key: 'SECRET'
121
122
  }
122
123
 
123
124
  @connection = Fog::Storage.new(@credentials)
124
125
  @connection.directories.create(
125
- :key => @fog_directory
126
+ key: @fog_directory
126
127
  )
127
128
 
128
129
  @options = {
129
- :fog_directory => @fog_directory,
130
- :fog_credentials => @credentials,
131
- :fog_host => nil,
132
- :fog_file => {:cache_control => 1234},
133
- :path => ":attachment/:basename.:extension",
134
- :storage => :fog
130
+ fog_directory: @fog_directory,
131
+ fog_credentials: @credentials,
132
+ fog_host: nil,
133
+ fog_file: {cache_control: 1234},
134
+ path: ":attachment/:basename:dotextension",
135
+ storage: :fog
135
136
  }
136
137
 
137
138
  rebuild_model(@options)
138
139
  end
139
140
 
140
- should "be extended by the Fog module" do
141
+ it "is extended by the Fog module" do
141
142
  assert Dummy.new.avatar.is_a?(Paperclip::Storage::Fog)
142
143
  end
143
144
 
144
145
  context "when assigned" do
145
- setup do
146
+ before do
146
147
  @file = File.new(fixture_file('5k.png'), 'rb')
147
148
  @dummy = Dummy.new
148
149
  @dummy.avatar = @file
149
150
  end
150
151
 
151
- teardown do
152
+ after do
152
153
  @file.close
153
- directory = @connection.directories.new(:key => @fog_directory)
154
+ directory = @connection.directories.new(key: @fog_directory)
154
155
  directory.files.each {|file| file.destroy}
155
156
  directory.destroy
156
157
  end
157
158
 
158
- should "be rewinded after flush_writes" do
159
+ it "is rewound after flush_writes" do
159
160
  @dummy.avatar.instance_eval "def after_flush_writes; end"
160
161
 
161
162
  files = @dummy.avatar.queued_for_write.values
@@ -163,14 +164,14 @@ class FogTest < Test::Unit::TestCase
163
164
  assert files.none?(&:eof?), "Expect all the files to be rewinded."
164
165
  end
165
166
 
166
- should "be removed after after_flush_writes" do
167
+ it "is removed after after_flush_writes" do
167
168
  paths = @dummy.avatar.queued_for_write.values.map(&:path)
168
169
  @dummy.save
169
- assert paths.none?{ |path| File.exists?(path) },
170
+ assert paths.none?{ |path| File.exist?(path) },
170
171
  "Expect all the files to be deleted."
171
172
  end
172
173
 
173
- should 'be able to be copied to a local file' do
174
+ it 'is able to be copied to a local file' do
174
175
  @dummy.save
175
176
  tempfile = Tempfile.new("known_location")
176
177
  tempfile.binmode
@@ -181,7 +182,7 @@ class FogTest < Test::Unit::TestCase
181
182
  tempfile.close
182
183
  end
183
184
 
184
- should "pass the content type to the Fog::Storage::AWS::Files instance" do
185
+ it "passes the content type to the Fog::Storage::AWS::Files instance" do
185
186
  Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
186
187
  hash[:content_type]
187
188
  end
@@ -189,235 +190,239 @@ class FogTest < Test::Unit::TestCase
189
190
  end
190
191
 
191
192
  context "without a bucket" do
192
- setup do
193
+ before do
193
194
  @connection.directories.get(@fog_directory).destroy
194
195
  end
195
196
 
196
- should "create the bucket" do
197
+ it "creates the bucket" do
197
198
  assert @dummy.save
198
199
  assert @connection.directories.get(@fog_directory)
199
200
  end
200
201
  end
201
202
 
202
203
  context "with a bucket" do
203
- should "succeed" do
204
+ it "succeeds" do
204
205
  assert @dummy.save
205
206
  end
206
207
  end
207
208
 
208
209
  context "without a fog_host" do
209
- setup do
210
- rebuild_model(@options.merge(:fog_host => nil))
210
+ before do
211
+ rebuild_model(@options.merge(fog_host: nil))
211
212
  @dummy = Dummy.new
212
213
  @dummy.avatar = StringIO.new('.')
213
214
  @dummy.save
214
215
  end
215
216
 
216
- should "provide a public url" do
217
+ it "provides a public url" do
217
218
  assert !@dummy.avatar.url.nil?
218
219
  end
219
220
  end
220
221
 
221
222
  context "with a fog_host" do
222
- setup do
223
- rebuild_model(@options.merge(:fog_host => 'http://example.com'))
223
+ before do
224
+ rebuild_model(@options.merge(fog_host: 'http://example.com'))
224
225
  @dummy = Dummy.new
225
226
  @dummy.avatar = StringIO.new(".\n")
226
227
  @dummy.save
227
228
  end
228
229
 
229
- should "provide a public url" do
230
- assert @dummy.avatar.url =~ /^http:\/\/example\.com\/avatars\/data\.txt\?\d*$/
230
+ it "provides a public url" do
231
+ expect(@dummy.avatar.url).to match(/^http:\/\/example\.com\/avatars\/data\?\d*$/)
231
232
  end
232
233
  end
233
234
 
234
235
  context "with a fog_host that includes a wildcard placeholder" do
235
- setup do
236
+ before do
236
237
  rebuild_model(
237
- :fog_directory => @fog_directory,
238
- :fog_credentials => @credentials,
239
- :fog_host => 'http://img%d.example.com',
240
- :path => ":attachment/:basename.:extension",
241
- :storage => :fog
238
+ fog_directory: @fog_directory,
239
+ fog_credentials: @credentials,
240
+ fog_host: 'http://img%d.example.com',
241
+ path: ":attachment/:basename:dotextension",
242
+ storage: :fog
242
243
  )
243
244
  @dummy = Dummy.new
244
245
  @dummy.avatar = StringIO.new(".\n")
245
246
  @dummy.save
246
247
  end
247
248
 
248
- should "provide a public url" do
249
- assert @dummy.avatar.url =~ /^http:\/\/img[0123]\.example\.com\/avatars\/data\.txt\?\d*$/
249
+ it "provides a public url" do
250
+ expect(@dummy.avatar.url).to match(/^http:\/\/img[0123]\.example\.com\/avatars\/data\?\d*$/)
250
251
  end
251
252
  end
252
253
 
253
254
  context "with fog_public set to false" do
254
- setup do
255
- rebuild_model(@options.merge(:fog_public => false))
255
+ before do
256
+ rebuild_model(@options.merge(fog_public: false))
256
257
  @dummy = Dummy.new
257
258
  @dummy.avatar = StringIO.new('.')
258
259
  @dummy.save
259
260
  end
260
261
 
261
- should 'set the @fog_public instance variable to false' do
262
+ it 'sets the @fog_public instance variable to false' do
262
263
  assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public]
263
264
  assert_equal false, @dummy.avatar.fog_public
264
265
  end
265
266
  end
266
267
 
267
268
  context "with styles set and fog_public set to false" do
268
- setup do
269
- rebuild_model(@options.merge(:fog_public => false, :styles => { :medium => "300x300>", :thumb => "100x100>" }))
269
+ before do
270
+ rebuild_model(@options.merge(fog_public: false, styles: { medium: "300x300>", thumb: "100x100>" }))
270
271
  @file = File.new(fixture_file('5k.png'), 'rb')
271
272
  @dummy = Dummy.new
272
273
  @dummy.avatar = @file
273
274
  @dummy.save
274
275
  end
275
276
 
276
- should 'set the @fog_public for a particular style to false' do
277
+ it 'sets the @fog_public for a particular style to false' do
277
278
  assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public]
278
279
  assert_equal false, @dummy.avatar.fog_public(:thumb)
279
280
  end
280
281
  end
281
282
 
282
283
  context "with styles set and fog_public set per-style" do
283
- setup do
284
- rebuild_model(@options.merge(:fog_public => { :medium => false, :thumb => true}, :styles => { :medium => "300x300>", :thumb => "100x100>" }))
284
+ before do
285
+ rebuild_model(@options.merge(fog_public: { medium: false, thumb: true}, styles: { medium: "300x300>", thumb: "100x100>" }))
285
286
  @file = File.new(fixture_file('5k.png'), 'rb')
286
287
  @dummy = Dummy.new
287
288
  @dummy.avatar = @file
288
289
  @dummy.save
289
290
  end
290
291
 
291
- should 'set the fog_public for a particular style to correct value' do
292
+ it 'sets the fog_public for a particular style to correct value' do
292
293
  assert_equal false, @dummy.avatar.fog_public(:medium)
293
294
  assert_equal true, @dummy.avatar.fog_public(:thumb)
294
295
  end
295
296
  end
296
297
 
297
298
  context "with fog_public not set" do
298
- setup do
299
+ before do
299
300
  rebuild_model(@options)
300
301
  @dummy = Dummy.new
301
302
  @dummy.avatar = StringIO.new('.')
302
303
  @dummy.save
303
304
  end
304
305
 
305
- should "default fog_public to true" do
306
+ it "defaults fog_public to true" do
306
307
  assert_equal true, @dummy.avatar.fog_public
307
308
  end
308
309
  end
309
310
 
310
311
  context "with a valid bucket name for a subdomain" do
311
- should "provide an url in subdomain style" do
312
+ it "provides an url in subdomain style" do
312
313
  assert_match(/^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png/, @dummy.avatar.url)
313
314
  end
314
315
 
315
- should "provide an url that expires in subdomain style" do
316
+ it "provides an url that expires in subdomain style" do
316
317
  assert_match(/^http:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png\?AWSAccessKeyId=.+$/, @dummy.avatar.expiring_url)
317
318
  end
318
319
  end
319
320
 
320
321
  context "generating an expiring url" do
321
- should "generate the same url when using Times and Integer offsets" do
322
- rebuild_model(@options)
323
- dummy = Dummy.new
324
- dummy.avatar = StringIO.new('.')
325
-
326
- assert_equal dummy.avatar.expiring_url(1234), dummy.avatar.expiring_url(Time.now + 1234)
322
+ it "generates the same url when using Times and Integer offsets" do
323
+ Timecop.freeze do
324
+ offset = 1234
325
+ rebuild_model(@options)
326
+ dummy = Dummy.new
327
+ dummy.avatar = StringIO.new('.')
328
+
329
+ assert_equal dummy.avatar.expiring_url(offset),
330
+ dummy.avatar.expiring_url(Time.now + offset )
331
+ end
327
332
  end
328
333
 
329
- should 'match the default url if there is no assignment' do
334
+ it 'matches the default url if there is no assignment' do
330
335
  dummy = Dummy.new
331
336
  assert_equal dummy.avatar.url, dummy.avatar.expiring_url
332
337
  end
333
338
 
334
- should 'match the default url when given a style if there is no assignment' do
339
+ it 'matches the default url when given a style if there is no assignment' do
335
340
  dummy = Dummy.new
336
341
  assert_equal dummy.avatar.url(:thumb), dummy.avatar.expiring_url(3600, :thumb)
337
342
  end
338
343
  end
339
344
 
340
345
  context "with an invalid bucket name for a subdomain" do
341
- setup do
342
- rebuild_model(@options.merge(:fog_directory => "this_is_invalid"))
346
+ before do
347
+ rebuild_model(@options.merge(fog_directory: "this_is_invalid"))
343
348
  @dummy = Dummy.new
344
349
  @dummy.avatar = @file
345
350
  @dummy.save
346
351
  end
347
352
 
348
- should "not match the bucket-subdomain restrictions" do
353
+ it "does not match the bucket-subdomain restrictions" do
349
354
  invalid_subdomains = %w(this_is_invalid in iamareallylongbucketnameiamareallylongbucketnameiamareallylongbu invalid- inval..id inval-.id inval.-id -invalid 192.168.10.2)
350
355
  invalid_subdomains.each do |name|
351
356
  assert_no_match Paperclip::Storage::Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX, name
352
357
  end
353
358
  end
354
359
 
355
- should "provide an url in folder style" do
360
+ it "provides an url in folder style" do
356
361
  assert_match(/^https:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png\?\d*$/, @dummy.avatar.url)
357
362
  end
358
363
 
359
- should "provide a url that expires in folder style" do
364
+ it "provides a url that expires in folder style" do
360
365
  assert_match(/^http:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png\?AWSAccessKeyId=.+$/, @dummy.avatar.expiring_url)
361
366
  end
362
367
 
363
368
  end
364
369
 
365
370
  context "with a proc for a bucket name evaluating a model method" do
366
- setup do
371
+ before do
367
372
  @dynamic_fog_directory = 'dynamicpaperclip'
368
- rebuild_model(@options.merge(:fog_directory => lambda { |attachment| attachment.instance.bucket_name }))
373
+ rebuild_model(@options.merge(fog_directory: lambda { |attachment| attachment.instance.bucket_name }))
369
374
  @dummy = Dummy.new
370
375
  @dummy.stubs(:bucket_name).returns(@dynamic_fog_directory)
371
376
  @dummy.avatar = @file
372
377
  @dummy.save
373
378
  end
374
379
 
375
- should "have created the bucket" do
380
+ it "has created the bucket" do
376
381
  assert @connection.directories.get(@dynamic_fog_directory).inspect
377
382
  end
378
383
 
379
384
  end
380
385
 
381
386
  context "with a proc for the fog_host evaluating a model method" do
382
- setup do
383
- rebuild_model(@options.merge(:fog_host => lambda { |attachment| attachment.instance.fog_host }))
387
+ before do
388
+ rebuild_model(@options.merge(fog_host: lambda { |attachment| attachment.instance.fog_host }))
384
389
  @dummy = Dummy.new
385
390
  @dummy.stubs(:fog_host).returns('http://dynamicfoghost.com')
386
391
  @dummy.avatar = @file
387
392
  @dummy.save
388
393
  end
389
394
 
390
- should "provide a public url" do
395
+ it "provides a public url" do
391
396
  assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.url)
392
397
  end
393
398
 
394
399
  end
395
400
 
396
401
  context "with a custom fog_host" do
397
- setup do
398
- rebuild_model(@options.merge(:fog_host => "http://dynamicfoghost.com"))
402
+ before do
403
+ rebuild_model(@options.merge(fog_host: "http://dynamicfoghost.com"))
399
404
  @dummy = Dummy.new
400
405
  @dummy.avatar = @file
401
406
  @dummy.save
402
407
  end
403
408
 
404
- should "provide a public url" do
409
+ it "provides a public url" do
405
410
  assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.url)
406
411
  end
407
412
 
408
- should "provide an expiring url" do
413
+ it "provides an expiring url" do
409
414
  assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.expiring_url)
410
415
  end
411
416
 
412
417
  context "with an invalid bucket name for a subdomain" do
413
- setup do
414
- rebuild_model(@options.merge({:fog_directory => "this_is_invalid", :fog_host => "http://dynamicfoghost.com"}))
418
+ before do
419
+ rebuild_model(@options.merge({fog_directory: "this_is_invalid", fog_host: "http://dynamicfoghost.com"}))
415
420
  @dummy = Dummy.new
416
421
  @dummy.avatar = @file
417
422
  @dummy.save
418
423
  end
419
424
 
420
- should "provide an expiring url" do
425
+ it "provides an expiring url" do
421
426
  assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.expiring_url)
422
427
  end
423
428
  end
@@ -425,20 +430,20 @@ class FogTest < Test::Unit::TestCase
425
430
  end
426
431
 
427
432
  context "with a proc for the fog_credentials evaluating a model method" do
428
- setup do
433
+ before do
429
434
  @dynamic_fog_credentials = {
430
- :provider => 'AWS',
431
- :aws_access_key_id => 'DYNAMIC_ID',
432
- :aws_secret_access_key => 'DYNAMIC_SECRET'
435
+ provider: 'AWS',
436
+ aws_access_key_id: 'DYNAMIC_ID',
437
+ aws_secret_access_key: 'DYNAMIC_SECRET'
433
438
  }
434
- rebuild_model(@options.merge(:fog_credentials => lambda { |attachment| attachment.instance.fog_credentials }))
439
+ rebuild_model(@options.merge(fog_credentials: lambda { |attachment| attachment.instance.fog_credentials }))
435
440
  @dummy = Dummy.new
436
441
  @dummy.stubs(:fog_credentials).returns(@dynamic_fog_credentials)
437
442
  @dummy.avatar = @file
438
443
  @dummy.save
439
444
  end
440
445
 
441
- should "provide a public url" do
446
+ it "provides a public url" do
442
447
  assert_equal @dummy.avatar.fog_credentials, @dynamic_fog_credentials
443
448
  end
444
449
  end
@@ -447,26 +452,26 @@ class FogTest < Test::Unit::TestCase
447
452
  end
448
453
 
449
454
  context "when using local storage" do
450
- setup do
455
+ before do
451
456
  Fog.unmock!
452
- rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
453
- :storage => :fog,
454
- :url => '/:attachment/:filename',
455
- :fog_directory => "paperclip",
456
- :fog_credentials => { :provider => :local, :local_root => "." },
457
- :fog_host => 'localhost'
457
+ rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
458
+ storage: :fog,
459
+ url: '/:attachment/:filename',
460
+ fog_directory: "paperclip",
461
+ fog_credentials: { provider: :local, local_root: "." },
462
+ fog_host: 'localhost'
458
463
 
459
464
  @file = File.new(fixture_file('5k.png'), 'rb')
460
465
  @dummy = Dummy.new
461
466
  @dummy.avatar = @file
462
467
  end
463
468
 
464
- teardown do
469
+ after do
465
470
  @file.close
466
471
  Fog.mock!
467
472
  end
468
473
 
469
- should "return the public url in place of the expiring url" do
474
+ it "returns the public url in place of the expiring url" do
470
475
  assert_match @dummy.avatar.public_url, @dummy.avatar.expiring_url
471
476
  end
472
477
  end