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
@@ -69,7 +69,7 @@ module Paperclip
69
69
  while(true)
70
70
  path = File.dirname(path)
71
71
  FileUtils.rmdir(path)
72
- break if File.exists?(path) # Ruby 1.9.2 does not raise if the removal failed.
72
+ break if File.exist?(path) # Ruby 1.9.2 does not raise if the removal failed.
73
73
  end
74
74
  rescue Errno::EEXIST, Errno::ENOTEMPTY, Errno::ENOENT, Errno::EINVAL, Errno::ENOTDIR, Errno::EACCES
75
75
  # Stop trying to remove parent directories
@@ -26,7 +26,7 @@ module Paperclip
26
26
  # put your bucket name in this file, instead of adding it to the code directly.
27
27
  # This is useful when you want the same account but a different bucket for
28
28
  # development versus production.
29
- # When using a Proc it provides a single parameter which is the attachment itself. A
29
+ # When using a Proc it provides a single parameter which is the attachment itself. A
30
30
  # method #instance is available on the attachment which will take you back to your
31
31
  # code. eg.
32
32
  # class User
@@ -51,7 +51,7 @@ module Paperclip
51
51
  # :s3_permissions => :private
52
52
  #
53
53
  # * +s3_protocol+: The protocol for the URLs generated to your S3 assets. Can be either
54
- # 'http', 'https', or an empty string to generate scheme-less URLs. Defaults to 'http'
54
+ # 'http', 'https', or an empty string to generate protocol-relative URLs. Defaults to 'http'
55
55
  # when your :s3_permissions are :public_read (the default), and 'https' when your
56
56
  # :s3_permissions are anything else.
57
57
  # * +s3_headers+: A hash of headers or a Proc. You may specify a hash such as
@@ -102,6 +102,14 @@ module Paperclip
102
102
  # Redundancy Storage. RRS enables customers to reduce their
103
103
  # costs by storing non-critical, reproducible data at lower
104
104
  # levels of redundancy than Amazon S3's standard storage.
105
+ #
106
+ # You can set storage class on a per style bases by doing the following:
107
+ # :s3_storage_class => {
108
+ # :thumb => :reduced_reduncancy
109
+ # }
110
+ # Or globally:
111
+ # :s3_storage_class => :reduced_redundancy
112
+
105
113
  module S3
106
114
  def self.extended base
107
115
  begin
@@ -139,14 +147,14 @@ module Paperclip
139
147
  @s3_headers = {}
140
148
  merge_s3_headers(@options[:s3_headers], @s3_headers, @s3_metadata)
141
149
 
142
- @s3_headers[:storage_class] = @options[:s3_storage_class] if @options[:s3_storage_class]
150
+ @s3_storage_class = set_storage_class(@options[:s3_storage_class])
143
151
 
144
152
  @s3_server_side_encryption = :aes256
145
153
  if @options[:s3_server_side_encryption].blank?
146
154
  @s3_server_side_encryption = false
147
155
  end
148
156
  if @s3_server_side_encryption
149
- @s3_server_side_encryption = @options[:s3_server_side_encryption].to_s.upcase
157
+ @s3_server_side_encryption = @options[:s3_server_side_encryption]
150
158
  end
151
159
 
152
160
  unless @options[:url].to_s.match(/\A:s3.*url\Z/) || @options[:url] == ":asset_host"
@@ -272,6 +280,11 @@ module Paperclip
272
280
  permissions.merge :default => (permissions[:default] || :public_read)
273
281
  end
274
282
 
283
+ def set_storage_class(storage_class)
284
+ storage_class = {:default => storage_class} unless storage_class.respond_to?(:merge)
285
+ storage_class
286
+ end
287
+
275
288
  def parse_credentials creds
276
289
  creds = creds.respond_to?('call') ? creds.call(self) : creds
277
290
  creds = find_credentials(creds).stringify_keys
@@ -295,6 +308,10 @@ module Paperclip
295
308
  s3_permissions
296
309
  end
297
310
 
311
+ def s3_storage_class(style = default_style)
312
+ @s3_storage_class[style] || @s3_storage_class[:default]
313
+ end
314
+
298
315
  def s3_protocol(style = default_style, with_colon = false)
299
316
  protocol = @s3_protocol
300
317
  protocol = protocol.call(style, self) if protocol.respond_to?(:call)
@@ -320,6 +337,11 @@ module Paperclip
320
337
  :content_type => file.content_type,
321
338
  :acl => acl
322
339
  }
340
+
341
+ # add storage class for this style if defined
342
+ storage_class = s3_storage_class(style)
343
+ write_options.merge!(:storage_class => storage_class) if storage_class
344
+
323
345
  if @s3_server_side_encryption
324
346
  write_options[:server_side_encryption] = @s3_server_side_encryption
325
347
  end
@@ -71,7 +71,7 @@ module Paperclip
71
71
  # Arguments other than the standard geometry, format etc are just passed through from
72
72
  # initialization and any procs are called here, just before post-processing.
73
73
  def processor_options
74
- args = {}
74
+ args = {:style => name}
75
75
  @other_args.each do |k,v|
76
76
  args[k] = v.respond_to?(:call) ? v.call(attachment) : v
77
77
  end
@@ -28,17 +28,17 @@ module Paperclip
28
28
  def initialize(file, options = {}, attachment = nil)
29
29
  super
30
30
 
31
- geometry = options[:geometry] # this is not an option
31
+ geometry = options[:geometry].to_s
32
32
  @file = file
33
33
  @crop = geometry[-1,1] == '#'
34
- @target_geometry = (options[:string_geometry_parser] || Geometry).parse(geometry)
35
- @current_geometry = (options[:file_geometry_parser] || Geometry).from_file(@file)
34
+ @target_geometry = options.fetch(:string_geometry_parser, Geometry).parse(geometry)
35
+ @current_geometry = options.fetch(:file_geometry_parser, Geometry).from_file(@file)
36
36
  @source_file_options = options[:source_file_options]
37
37
  @convert_options = options[:convert_options]
38
- @whiny = options[:whiny].nil? ? true : options[:whiny]
38
+ @whiny = options.fetch(:whiny, true)
39
39
  @format = options[:format]
40
- @animated = options[:animated].nil? ? true : options[:animated]
41
- @auto_orient = options[:auto_orient].nil? ? true : options[:auto_orient]
40
+ @animated = options.fetch(:animated, true)
41
+ @auto_orient = options.fetch(:auto_orient, true)
42
42
  if @auto_orient && @current_geometry.respond_to?(:auto_orient)
43
43
  @current_geometry.auto_orient
44
44
  end
@@ -1,5 +1,6 @@
1
1
  require 'active_model'
2
2
  require 'active_support/concern'
3
+ require 'active_support/core_ext/array/wrap'
3
4
  require 'paperclip/validators/attachment_content_type_validator'
4
5
  require 'paperclip/validators/attachment_file_name_validator'
5
6
  require 'paperclip/validators/attachment_presence_validator'
@@ -41,10 +42,11 @@ module Paperclip
41
42
  if options.has_key?(validator_kind)
42
43
  validator_options = options.delete(validator_kind)
43
44
  validator_options = {} if validator_options == true
44
- local_options = attributes + [validator_options]
45
45
  conditional_options = options.slice(:if, :unless)
46
- local_options.last.merge!(conditional_options)
47
- send(Paperclip::Validators.const_get(constant.to_s).helper_method_name, *local_options)
46
+ Array.wrap(validator_options).each do |local_options|
47
+ method_name = Paperclip::Validators.const_get(constant.to_s).helper_method_name
48
+ send(method_name, attributes, local_options.merge(conditional_options))
49
+ end
48
50
  end
49
51
  end
50
52
  end
@@ -71,9 +71,13 @@ module Paperclip
71
71
  end
72
72
 
73
73
  def human_size(size)
74
- storage_units_format = I18n.translate(:'number.human.storage_units.format', :locale => options[:locale], :raise => true)
75
- unit = I18n.translate(:'number.human.storage_units.units.byte', :locale => options[:locale], :count => size.to_i, :raise => true)
76
- storage_units_format.gsub(/%n/, size.to_i.to_s).gsub(/%u/, unit).html_safe
74
+ if defined?(ActiveSupport::NumberHelper) # Rails 4.0+
75
+ ActiveSupport::NumberHelper.number_to_human_size(size)
76
+ else
77
+ storage_units_format = I18n.translate(:'number.human.storage_units.format', :locale => options[:locale], :raise => true)
78
+ unit = I18n.translate(:'number.human.storage_units.units.byte', :locale => options[:locale], :count => size.to_i, :raise => true)
79
+ storage_units_format.gsub(/%n/, size.to_i.to_s).gsub(/%u/, unit).html_safe
80
+ end
77
81
  end
78
82
 
79
83
  def min_value_in_human_size(record)
@@ -1,3 +1,3 @@
1
1
  module Paperclip
2
- VERSION = "4.1.1" unless defined? Paperclip::VERSION
2
+ VERSION = "4.2.0" unless defined? Paperclip::VERSION
3
3
  end
@@ -78,8 +78,7 @@ namespace :paperclip do
78
78
 
79
79
  desc "Regenerates missing thumbnail styles for all classes using Paperclip."
80
80
  task :missing_styles => :environment do
81
- # Force loading all model classes to never miss any has_attached_file declaration:
82
- Dir[Rails.root + 'app/models/**/*.rb'].each { |path| load path }
81
+ Rails.application.eager_load!
83
82
  Paperclip.missing_attachments_styles.each do |klass, attachment_definitions|
84
83
  attachment_definitions.each do |attachment_name, missing_styles|
85
84
  puts "Regenerating #{klass} -> #{attachment_name} -> #{missing_styles.inspect}"
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = "paperclip"
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
@@ -29,12 +29,12 @@ Gem::Specification.new do |s|
29
29
 
30
30
  s.add_development_dependency('activerecord', '>= 3.0.0')
31
31
  s.add_development_dependency('shoulda')
32
+ s.add_development_dependency('rspec')
32
33
  s.add_development_dependency('appraisal')
33
34
  s.add_development_dependency('mocha')
34
35
  s.add_development_dependency('aws-sdk', '>= 1.5.7')
35
36
  s.add_development_dependency('bourne')
36
- s.add_development_dependency('sqlite3', '~> 1.3.4')
37
- s.add_development_dependency('cucumber', '~> 1.2.1')
37
+ s.add_development_dependency('cucumber', '~> 1.3.11')
38
38
  s.add_development_dependency('aruba')
39
39
  s.add_development_dependency('nokogiri')
40
40
  # Ruby version < 1.9.3 can't install capybara > 2.0.3.
@@ -46,4 +46,6 @@ Gem::Specification.new do |s|
46
46
  s.add_development_dependency('fakeweb')
47
47
  s.add_development_dependency('railties')
48
48
  s.add_development_dependency('actionmailer', '>= 3.0.0')
49
+ s.add_development_dependency('generator_spec')
50
+ s.add_development_dependency('timecop')
49
51
  end
@@ -132,4 +132,3 @@ elsif defined?(Test)
132
132
  extend Paperclip::Shoulda
133
133
  end
134
134
  end
135
-
File without changes
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Attachment Definitions" do
4
+ it 'returns all of the attachments on the class' do
5
+ reset_class "Dummy"
6
+ Dummy.has_attached_file :avatar, {path: "abc"}
7
+ Dummy.has_attached_file :other_attachment, {url: "123"}
8
+ Dummy.do_not_validate_attachment_file_type :avatar
9
+ expected = {avatar: {path: "abc"}, other_attachment: {url: "123"}}
10
+
11
+ assert_equal expected, Dummy.attachment_definitions
12
+ end
13
+ end
@@ -1,16 +1,15 @@
1
1
  # encoding: utf-8
2
- require './test/helper'
3
- require 'paperclip/attachment'
4
-
5
- class AttachmentProcessingTest < Test::Unit::TestCase
6
- def setup
7
- rebuild_model
8
- end
2
+ require 'spec_helper'
9
3
 
4
+ describe 'Attachment Processing' do
10
5
  context 'using validates_attachment_content_type' do
11
- should 'process attachments given a valid assignment' do
6
+ before do
7
+ rebuild_class
8
+ end
9
+
10
+ it 'processes attachments given a valid assignment' do
12
11
  file = File.new(fixture_file("5k.png"))
13
- Dummy.validates_attachment_content_type :avatar, :content_type => "image/png"
12
+ Dummy.validates_attachment_content_type :avatar, content_type: "image/png"
14
13
  instance = Dummy.new
15
14
  attachment = instance.avatar
16
15
  attachment.expects(:post_process_styles)
@@ -18,9 +17,9 @@ class AttachmentProcessingTest < Test::Unit::TestCase
18
17
  attachment.assign(file)
19
18
  end
20
19
 
21
- should 'not process attachments given an invalid assignment with :not' do
20
+ it 'does not process attachments given an invalid assignment with :not' do
22
21
  file = File.new(fixture_file("5k.png"))
23
- Dummy.validates_attachment_content_type :avatar, :not => "image/png"
22
+ Dummy.validates_attachment_content_type :avatar, not: "image/png"
24
23
  instance = Dummy.new
25
24
  attachment = instance.avatar
26
25
  attachment.expects(:post_process_styles).never
@@ -28,9 +27,9 @@ class AttachmentProcessingTest < Test::Unit::TestCase
28
27
  attachment.assign(file)
29
28
  end
30
29
 
31
- should 'not process attachments given an invalid assignment with :content_type' do
30
+ it 'does not process attachments given an invalid assignment with :content_type' do
32
31
  file = File.new(fixture_file("5k.png"))
33
- Dummy.validates_attachment_content_type :avatar, :content_type => "image/tiff"
32
+ Dummy.validates_attachment_content_type :avatar, content_type: "image/tiff"
34
33
  instance = Dummy.new
35
34
  attachment = instance.avatar
36
35
  attachment.expects(:post_process_styles).never
@@ -38,9 +37,9 @@ class AttachmentProcessingTest < Test::Unit::TestCase
38
37
  attachment.assign(file)
39
38
  end
40
39
 
41
- should 'when validation :if clause returns false, allow what would be an invalid assignment' do
40
+ it 'allows what would be an invalid assignment when validation :if clause returns false' do
42
41
  invalid_assignment = File.new(fixture_file("5k.png"))
43
- Dummy.validates_attachment_content_type :avatar, :content_type => "image/tiff", :if => lambda{false}
42
+ Dummy.validates_attachment_content_type :avatar, content_type: "image/tiff", if: lambda{false}
44
43
  instance = Dummy.new
45
44
  attachment = instance.avatar
46
45
  attachment.expects(:post_process_styles)
@@ -50,9 +49,9 @@ class AttachmentProcessingTest < Test::Unit::TestCase
50
49
  end
51
50
 
52
51
  context 'using validates_attachment' do
53
- should 'process attachments given a valid assignment' do
52
+ it 'processes attachments given a valid assignment' do
54
53
  file = File.new(fixture_file("5k.png"))
55
- Dummy.validates_attachment :avatar, :content_type => {:content_type => "image/png"}
54
+ Dummy.validates_attachment :avatar, content_type: {content_type: "image/png"}
56
55
  instance = Dummy.new
57
56
  attachment = instance.avatar
58
57
  attachment.expects(:post_process_styles)
@@ -60,9 +59,9 @@ class AttachmentProcessingTest < Test::Unit::TestCase
60
59
  attachment.assign(file)
61
60
  end
62
61
 
63
- should 'not process attachments given an invalid assignment with :not' do
62
+ it 'does not process attachments given an invalid assignment with :not' do
64
63
  file = File.new(fixture_file("5k.png"))
65
- Dummy.validates_attachment :avatar, :content_type => {:not => "image/png"}
64
+ Dummy.validates_attachment :avatar, content_type: {not: "image/png"}
66
65
  instance = Dummy.new
67
66
  attachment = instance.avatar
68
67
  attachment.expects(:post_process_styles).never
@@ -70,9 +69,9 @@ class AttachmentProcessingTest < Test::Unit::TestCase
70
69
  attachment.assign(file)
71
70
  end
72
71
 
73
- should 'not process attachments given an invalid assignment with :content_type' do
72
+ it 'does not process attachments given an invalid assignment with :content_type' do
74
73
  file = File.new(fixture_file("5k.png"))
75
- Dummy.validates_attachment :avatar, :content_type => {:content_type => "image/tiff"}
74
+ Dummy.validates_attachment :avatar, content_type: {content_type: "image/tiff"}
76
75
  instance = Dummy.new
77
76
  attachment = instance.avatar
78
77
  attachment.expects(:post_process_styles).never
@@ -1,20 +1,19 @@
1
- require './test/helper'
2
- require 'paperclip/attachment_registry'
1
+ require 'spec_helper'
3
2
 
4
- class AttachmentRegistryTest < Test::Unit::TestCase
5
- def setup
3
+ describe 'Attachment Registry' do
4
+ before do
6
5
  Paperclip::AttachmentRegistry.clear
7
6
  end
8
7
 
9
8
  context '.names_for' do
10
- should 'include attachment names for the given class' do
9
+ it 'includes attachment names for the given class' do
11
10
  foo = Class.new
12
11
  Paperclip::AttachmentRegistry.register(foo, :avatar, {})
13
12
 
14
13
  assert_equal [:avatar], Paperclip::AttachmentRegistry.names_for(foo)
15
14
  end
16
15
 
17
- should 'not include attachment names for other classes' do
16
+ it 'does not include attachment names for other classes' do
18
17
  foo = Class.new
19
18
  bar = Class.new
20
19
  Paperclip::AttachmentRegistry.register(foo, :avatar, {})
@@ -23,13 +22,13 @@ class AttachmentRegistryTest < Test::Unit::TestCase
23
22
  assert_equal [:lover], Paperclip::AttachmentRegistry.names_for(bar)
24
23
  end
25
24
 
26
- should 'produce the empty array for a missing key' do
25
+ it 'produces the empty array for a missing key' do
27
26
  assert_empty Paperclip::AttachmentRegistry.names_for(Class.new)
28
27
  end
29
28
  end
30
29
 
31
30
  context '.each_definition' do
32
- should 'call the block with the class, attachment name, and options' do
31
+ it 'calls the block with the class, attachment name, and options' do
33
32
  foo = Class.new
34
33
  expected_accumulations = [
35
34
  [foo, :avatar, { yo: 'greeting' }],
@@ -49,7 +48,7 @@ class AttachmentRegistryTest < Test::Unit::TestCase
49
48
  end
50
49
 
51
50
  context '.definitions_for' do
52
- should 'produce the attachment name and options' do
51
+ it 'produces the attachment name and options' do
53
52
  expected_definitions = {
54
53
  avatar: { yo: 'greeting' },
55
54
  greeter: { ciao: 'greeting' }
@@ -63,7 +62,7 @@ class AttachmentRegistryTest < Test::Unit::TestCase
63
62
  assert_equal expected_definitions, definitions
64
63
  end
65
64
 
66
- should "produce defintions for subclasses" do
65
+ it "produces defintions for subclasses" do
67
66
  expected_definitions = { avatar: { yo: 'greeting' } }
68
67
  Foo = Class.new
69
68
  Bar = Class.new(Foo)
@@ -76,7 +75,7 @@ class AttachmentRegistryTest < Test::Unit::TestCase
76
75
  end
77
76
 
78
77
  context '.clear' do
79
- should 'remove all of the existing attachment definitions' do
78
+ it 'removes all of the existing attachment definitions' do
80
79
  foo = Class.new
81
80
  Paperclip::AttachmentRegistry.register(foo, :greeter, { ciao: 'greeting' })
82
81
 
@@ -1,205 +1,196 @@
1
1
  # encoding: utf-8
2
- require './test/helper'
3
- require 'paperclip/attachment'
2
+ require 'spec_helper'
4
3
 
5
- class Dummy; end
4
+ describe Paperclip::Attachment do
6
5
 
7
- class AttachmentTest < Test::Unit::TestCase
8
-
9
- context "presence" do
10
- setup do
11
- rebuild_class
12
- @dummy = Dummy.new
13
- end
14
-
15
- context "when file not set" do
16
- should "not be present" do
17
- assert @dummy.avatar.blank?
18
- refute @dummy.avatar.present?
19
- end
20
- end
21
-
22
- context "when file set" do
23
- setup { @dummy.avatar = File.new(fixture_file("50x50.png"), "rb") }
6
+ it "is not present when file not set" do
7
+ rebuild_class
8
+ dummy = Dummy.new
9
+ expect(dummy.avatar).to be_blank
10
+ expect(dummy.avatar).to_not be_present
11
+ end
24
12
 
25
- should "be present" do
26
- refute @dummy.avatar.blank?
27
- assert @dummy.avatar.present?
28
- end
29
- end
13
+ it "is present when the file is set" do
14
+ rebuild_class
15
+ dummy = Dummy.new
16
+ dummy.avatar = File.new(fixture_file("50x50.png"), "rb")
17
+ expect(dummy.avatar).to_not be_blank
18
+ expect(dummy.avatar).to be_present
30
19
  end
31
20
 
32
- should "process :original style first" do
21
+ it "processes :original style first" do
33
22
  file = File.new(fixture_file("50x50.png"), 'rb')
34
- rebuild_class :styles => { :small => '100x>', :original => '42x42#' }
23
+ rebuild_class styles: { small: '100x>', original: '42x42#' }
35
24
  dummy = Dummy.new
36
25
  dummy.avatar = file
37
26
  dummy.save
38
27
 
39
28
  # :small avatar should be 42px wide (processed original), not 50px (preprocessed original)
40
- assert_equal `identify -format "%w" "#{dummy.avatar.path(:small)}"`.strip, "42"
29
+ expect(`identify -format "%w" "#{dummy.avatar.path(:small)}"`.strip).to eq "42"
41
30
 
42
31
  file.close
43
32
  end
44
33
 
45
- should "not delete styles that don't get reprocessed" do
34
+ it "does not delete styles that don't get reprocessed" do
46
35
  file = File.new(fixture_file("50x50.png"), 'rb')
47
- rebuild_class :styles => { :small => '100x>',
48
- :large => '500x>',
49
- :original => '42x42#' }
36
+ rebuild_class styles: {
37
+ small: '100x>',
38
+ large: '500x>',
39
+ original: '42x42#'
40
+ }
41
+
50
42
  dummy = Dummy.new
51
43
  dummy.avatar = file
52
44
  dummy.save
53
45
 
54
- assert_file_exists(dummy.avatar.path(:small))
55
- assert_file_exists(dummy.avatar.path(:large))
56
- assert_file_exists(dummy.avatar.path(:original))
46
+ expect(dummy.avatar.path(:small)).to exist
47
+ expect(dummy.avatar.path(:large)).to exist
48
+ expect(dummy.avatar.path(:original)).to exist
57
49
 
58
50
  dummy.avatar.reprocess!(:small)
59
51
 
60
- assert_file_exists(dummy.avatar.path(:small))
61
- assert_file_exists(dummy.avatar.path(:large))
62
- assert_file_exists(dummy.avatar.path(:original))
52
+ expect(dummy.avatar.path(:small)).to exist
53
+ expect(dummy.avatar.path(:large)).to exist
54
+ expect(dummy.avatar.path(:original)).to exist
63
55
  end
64
56
 
65
57
  context "having a not empty hash as a default option" do
66
- setup do
58
+ before do
67
59
  @old_default_options = Paperclip::Attachment.default_options.dup
68
- @new_default_options = { :convert_options => { :all => "-background white" } }
60
+ @new_default_options = { convert_options: { all: "-background white" } }
69
61
  Paperclip::Attachment.default_options.merge!(@new_default_options)
70
62
  end
71
63
 
72
- teardown do
64
+ after do
73
65
  Paperclip::Attachment.default_options.merge!(@old_default_options)
74
66
  end
75
67
 
76
- should "deep merge when it is overridden" do
77
- new_options = { :convert_options => { :thumb => "-thumbnailize" } }
68
+ it "deep merges when it is overridden" do
69
+ new_options = { convert_options: { thumb: "-thumbnailize" } }
78
70
  attachment = Paperclip::Attachment.new(:name, :instance, new_options)
79
71
 
80
- assert_equal Paperclip::Attachment.default_options.deep_merge(new_options),
81
- attachment.instance_variable_get("@options")
72
+ expect(Paperclip::Attachment.default_options.deep_merge(new_options)).to eq attachment.instance_variable_get("@options")
82
73
  end
83
74
  end
84
75
 
85
- should "handle a boolean second argument to #url" do
76
+ it "handles a boolean second argument to #url" do
86
77
  mock_url_generator_builder = MockUrlGeneratorBuilder.new
87
- attachment = Paperclip::Attachment.new(:name, :instance, :url_generator => mock_url_generator_builder)
78
+ attachment = Paperclip::Attachment.new(:name, :instance, url_generator: mock_url_generator_builder)
88
79
 
89
80
  attachment.url(:style_name, true)
90
- assert mock_url_generator_builder.has_generated_url_with_options?(:timestamp => true, :escape => true)
81
+ expect(mock_url_generator_builder.has_generated_url_with_options?(timestamp: true, escape: true)).to eq true
91
82
 
92
83
  attachment.url(:style_name, false)
93
- assert mock_url_generator_builder.has_generated_url_with_options?(:timestamp => false, :escape => true)
84
+ expect(mock_url_generator_builder.has_generated_url_with_options?(timestamp: false, escape: true)).to eq true
94
85
  end
95
86
 
96
- should "pass the style and options through to the URL generator on #url" do
87
+ it "passes the style and options through to the URL generator on #url" do
97
88
  mock_url_generator_builder = MockUrlGeneratorBuilder.new
98
- attachment = Paperclip::Attachment.new(:name, :instance, :url_generator => mock_url_generator_builder)
89
+ attachment = Paperclip::Attachment.new(:name, :instance, url_generator: mock_url_generator_builder)
99
90
 
100
- attachment.url(:style_name, :options => :values)
101
- assert mock_url_generator_builder.has_generated_url_with_options?(:options => :values)
91
+ attachment.url(:style_name, options: :values)
92
+ expect(mock_url_generator_builder.has_generated_url_with_options?(options: :values)).to eq true
102
93
  end
103
94
 
104
- should "pass default options through when #url is given one argument" do
95
+ it "passes default options through when #url is given one argument" do
105
96
  mock_url_generator_builder = MockUrlGeneratorBuilder.new
106
97
  attachment = Paperclip::Attachment.new(:name,
107
98
  :instance,
108
- :url_generator => mock_url_generator_builder,
109
- :use_timestamp => true)
99
+ url_generator: mock_url_generator_builder,
100
+ use_timestamp: true)
110
101
 
111
102
  attachment.url(:style_name)
112
- assert mock_url_generator_builder.has_generated_url_with_options?(:escape => true, :timestamp => true)
103
+ assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true)
113
104
  end
114
105
 
115
- should "pass default style and options through when #url is given no arguments" do
106
+ it "passes default style and options through when #url is given no arguments" do
116
107
  mock_url_generator_builder = MockUrlGeneratorBuilder.new
117
108
  attachment = Paperclip::Attachment.new(:name,
118
109
  :instance,
119
- :default_style => 'default style',
120
- :url_generator => mock_url_generator_builder,
121
- :use_timestamp => true)
110
+ default_style: 'default style',
111
+ url_generator: mock_url_generator_builder,
112
+ use_timestamp: true)
122
113
 
123
114
  attachment.url
124
- assert mock_url_generator_builder.has_generated_url_with_options?(:escape => true, :timestamp => true)
115
+ assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true)
125
116
  assert mock_url_generator_builder.has_generated_url_with_style_name?('default style')
126
117
  end
127
118
 
128
- should "pass the option :timestamp => true if :use_timestamp is true and :timestamp is not passed" do
119
+ it "passes the option timestamp: true if :use_timestamp is true and :timestamp is not passed" do
129
120
  mock_url_generator_builder = MockUrlGeneratorBuilder.new
130
121
  attachment = Paperclip::Attachment.new(:name,
131
122
  :instance,
132
- :url_generator => mock_url_generator_builder,
133
- :use_timestamp => true)
123
+ url_generator: mock_url_generator_builder,
124
+ use_timestamp: true)
134
125
 
135
126
  attachment.url(:style_name)
136
- assert mock_url_generator_builder.has_generated_url_with_options?(:escape => true, :timestamp => true)
127
+ assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true)
137
128
  end
138
129
 
139
- should "pass the option :timestamp => false if :use_timestamp is false and :timestamp is not passed" do
130
+ it "passes the option timestamp: false if :use_timestamp is false and :timestamp is not passed" do
140
131
  mock_url_generator_builder = MockUrlGeneratorBuilder.new
141
132
  attachment = Paperclip::Attachment.new(:name,
142
133
  :instance,
143
- :url_generator => mock_url_generator_builder,
144
- :use_timestamp => false)
134
+ url_generator: mock_url_generator_builder,
135
+ use_timestamp: false)
145
136
 
146
137
  attachment.url(:style_name)
147
- assert mock_url_generator_builder.has_generated_url_with_options?(:escape => true, :timestamp => false)
138
+ assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: false)
148
139
  end
149
140
 
150
- should "not change the :timestamp if :timestamp is passed" do
141
+ it "does not change the :timestamp if :timestamp is passed" do
151
142
  mock_url_generator_builder = MockUrlGeneratorBuilder.new
152
143
  attachment = Paperclip::Attachment.new(:name,
153
144
  :instance,
154
- :url_generator => mock_url_generator_builder,
155
- :use_timestamp => false)
145
+ url_generator: mock_url_generator_builder,
146
+ use_timestamp: false)
156
147
 
157
- attachment.url(:style_name, :timestamp => true)
158
- assert mock_url_generator_builder.has_generated_url_with_options?(:escape => true, :timestamp => true)
148
+ attachment.url(:style_name, timestamp: true)
149
+ assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true)
159
150
  end
160
151
 
161
- should "render JSON as default style" do
152
+ it "renders JSON as default style" do
162
153
  mock_url_generator_builder = MockUrlGeneratorBuilder.new
163
154
  attachment = Paperclip::Attachment.new(:name,
164
155
  :instance,
165
- :default_style => 'default style',
166
- :url_generator => mock_url_generator_builder)
156
+ default_style: 'default style',
157
+ url_generator: mock_url_generator_builder)
167
158
 
168
159
  attachment.as_json
169
160
  assert mock_url_generator_builder.has_generated_url_with_style_name?('default style')
170
161
  end
171
162
 
172
- should "pass the option :escape => true if :escape_url is true and :escape is not passed" do
163
+ it "passes the option escape: true if :escape_url is true and :escape is not passed" do
173
164
  mock_url_generator_builder = MockUrlGeneratorBuilder.new
174
165
  attachment = Paperclip::Attachment.new(:name,
175
166
  :instance,
176
- :url_generator => mock_url_generator_builder,
177
- :escape_url => true)
167
+ url_generator: mock_url_generator_builder,
168
+ escape_url: true)
178
169
 
179
170
  attachment.url(:style_name)
180
- assert mock_url_generator_builder.has_generated_url_with_options?(:escape => true)
171
+ assert mock_url_generator_builder.has_generated_url_with_options?(escape: true)
181
172
  end
182
173
 
183
- should "pass the option :escape => false if :escape_url is false and :escape is not passed" do
174
+ it "passes the option escape: false if :escape_url is false and :escape is not passed" do
184
175
  mock_url_generator_builder = MockUrlGeneratorBuilder.new
185
176
  attachment = Paperclip::Attachment.new(:name,
186
177
  :instance,
187
- :url_generator => mock_url_generator_builder,
188
- :escape_url => false)
178
+ url_generator: mock_url_generator_builder,
179
+ escape_url: false)
189
180
 
190
181
  attachment.url(:style_name)
191
- assert mock_url_generator_builder.has_generated_url_with_options?(:escape => false)
182
+ assert mock_url_generator_builder.has_generated_url_with_options?(escape: false)
192
183
  end
193
184
 
194
- should "return the path based on the url by default" do
195
- @attachment = attachment :url => "/:class/:id/:basename"
185
+ it "returns the path based on the url by default" do
186
+ @attachment = attachment url: "/:class/:id/:basename"
196
187
  @model = @attachment.instance
197
188
  @model.id = 1234
198
189
  @model.avatar_file_name = "fake.jpg"
199
190
  assert_equal "#{Rails.root}/public/fake_models/1234/fake", @attachment.path
200
191
  end
201
192
 
202
- should "default to a path that scales" do
193
+ it "defaults to a path that scales" do
203
194
  avatar_attachment = attachment
204
195
  model = avatar_attachment.instance
205
196
  model.id = 1234
@@ -208,7 +199,7 @@ class AttachmentTest < Test::Unit::TestCase
208
199
  assert_equal expected_path, avatar_attachment.path
209
200
  end
210
201
 
211
- should "render JSON as the URL to the attachment" do
202
+ it "renders JSON as the URL to the attachment" do
212
203
  avatar_attachment = attachment
213
204
  model = avatar_attachment.instance
214
205
  model.id = 1234
@@ -216,7 +207,7 @@ class AttachmentTest < Test::Unit::TestCase
216
207
  assert_equal attachment.url, attachment.as_json
217
208
  end
218
209
 
219
- should "render JSON from the model when requested by :methods" do
210
+ it "renders JSON from the model when requested by :methods" do
220
211
  rebuild_model
221
212
  dummy = Dummy.new
222
213
  dummy.id = 1234
@@ -226,25 +217,25 @@ class AttachmentTest < Test::Unit::TestCase
226
217
  expected_string = %({"dummy":#{expected_string}})
227
218
  end
228
219
  # active_model pre-3.2 checks only by calling any? on it, thus it doesn't work if it is empty
229
- assert_equal expected_string, dummy.to_json(:only => [:dummy_key_for_old_active_model], :methods => [:avatar])
220
+ assert_equal expected_string, dummy.to_json(only: [:dummy_key_for_old_active_model], methods: [:avatar])
230
221
  end
231
222
 
232
223
  context "Attachment default_options" do
233
- setup do
224
+ before do
234
225
  rebuild_model
235
226
  @old_default_options = Paperclip::Attachment.default_options.dup
236
227
  @new_default_options = @old_default_options.merge({
237
- :path => "argle/bargle",
238
- :url => "fooferon",
239
- :default_url => "not here.png"
228
+ path: "argle/bargle",
229
+ url: "fooferon",
230
+ default_url: "not here.png"
240
231
  })
241
232
  end
242
233
 
243
- teardown do
234
+ after do
244
235
  Paperclip::Attachment.default_options.merge! @old_default_options
245
236
  end
246
237
 
247
- should "be overrideable" do
238
+ it "is overrideable" do
248
239
  Paperclip::Attachment.default_options.merge!(@new_default_options)
249
240
  @new_default_options.keys.each do |key|
250
241
  assert_equal @new_default_options[key],
@@ -253,41 +244,41 @@ class AttachmentTest < Test::Unit::TestCase
253
244
  end
254
245
 
255
246
  context "without an Attachment" do
256
- setup do
247
+ before do
257
248
  @dummy = Dummy.new
258
249
  end
259
250
 
260
- should "return false when asked exists?" do
251
+ it "returns false when asked exists?" do
261
252
  assert !@dummy.avatar.exists?
262
253
  end
263
254
  end
264
255
 
265
256
  context "on an Attachment" do
266
- setup do
257
+ before do
267
258
  @dummy = Dummy.new
268
259
  @attachment = @dummy.avatar
269
260
  end
270
261
 
271
262
  Paperclip::Attachment.default_options.keys.each do |key|
272
- should "be the default_options for #{key}" do
263
+ it "is the default_options for #{key}" do
273
264
  assert_equal @old_default_options[key],
274
265
  @attachment.instance_variable_get("@options")[key],
275
- key
266
+ key.to_s
276
267
  end
277
268
  end
278
269
 
279
270
  context "when redefined" do
280
- setup do
271
+ before do
281
272
  Paperclip::Attachment.default_options.merge!(@new_default_options)
282
273
  @dummy = Dummy.new
283
274
  @attachment = @dummy.avatar
284
275
  end
285
276
 
286
277
  Paperclip::Attachment.default_options.keys.each do |key|
287
- should "be the new default_options for #{key}" do
278
+ it "is the new default_options for #{key}" do
288
279
  assert_equal @new_default_options[key],
289
280
  @attachment.instance_variable_get("@options")[key],
290
- key
281
+ key.to_s
291
282
  end
292
283
  end
293
284
  end
@@ -295,23 +286,23 @@ class AttachmentTest < Test::Unit::TestCase
295
286
  end
296
287
 
297
288
  context "An attachment with similarly named interpolations" do
298
- setup do
299
- rebuild_model :path => ":id.omg/:id-bbq/:idwhat/:id_partition.wtf"
289
+ before do
290
+ rebuild_model path: ":id.omg/:id-bbq/:idwhat/:id_partition.wtf"
300
291
  @dummy = Dummy.new
301
292
  @dummy.stubs(:id).returns(1024)
302
293
  @file = File.new(fixture_file("5k.png"), 'rb')
303
294
  @dummy.avatar = @file
304
295
  end
305
296
 
306
- teardown { @file.close }
297
+ after { @file.close }
307
298
 
308
- should "make sure that they are interpolated correctly" do
299
+ it "makes sure that they are interpolated correctly" do
309
300
  assert_equal "1024.omg/1024-bbq/1024what/000/001/024.wtf", @dummy.avatar.path
310
301
  end
311
302
  end
312
303
 
313
304
  context "An attachment with :timestamp interpolations" do
314
- setup do
305
+ before do
315
306
  @file = StringIO.new("...")
316
307
  @zone = 'UTC'
317
308
  Time.stubs(:zone).returns(@zone)
@@ -320,73 +311,77 @@ class AttachmentTest < Test::Unit::TestCase
320
311
  end
321
312
 
322
313
  context "using default time zone" do
323
- setup do
324
- rebuild_model :path => ":timestamp", :use_default_time_zone => true
314
+ before do
315
+ rebuild_model path: ":timestamp", use_default_time_zone: true
325
316
  @dummy = Dummy.new
326
317
  @dummy.avatar = @file
327
318
  end
328
319
 
329
- should "return a time in the default zone" do
320
+ it "returns a time in the default zone" do
330
321
  assert_equal @dummy.avatar_updated_at.in_time_zone(@zone_default).to_s, @dummy.avatar.path
331
322
  end
332
323
  end
333
324
 
334
325
  context "using per-thread time zone" do
335
- setup do
336
- rebuild_model :path => ":timestamp", :use_default_time_zone => false
326
+ before do
327
+ rebuild_model path: ":timestamp", use_default_time_zone: false
337
328
  @dummy = Dummy.new
338
329
  @dummy.avatar = @file
339
330
  end
340
331
 
341
- should "return a time in the per-thread zone" do
332
+ it "returns a time in the per-thread zone" do
342
333
  assert_equal @dummy.avatar_updated_at.in_time_zone(@zone).to_s, @dummy.avatar.path
343
334
  end
344
335
  end
345
336
  end
346
337
 
347
338
  context "An attachment with :hash interpolations" do
348
- setup do
349
- @file = StringIO.new("...\n")
339
+ before do
340
+ @file = File.open(fixture_file("5k.png"))
341
+ end
342
+
343
+ after do
344
+ @file.close
350
345
  end
351
346
 
352
- should "raise if no secret is provided" do
353
- rebuild_model :path => ":hash"
347
+ it "raises if no secret is provided" do
348
+ rebuild_model path: ":hash"
354
349
  @attachment = Dummy.new.avatar
355
350
  @attachment.assign @file
356
351
 
357
- assert_raise ArgumentError do
352
+ assert_raises ArgumentError do
358
353
  @attachment.path
359
354
  end
360
355
  end
361
356
 
362
357
  context "when secret is set" do
363
- setup do
364
- rebuild_model :path => ":hash",
365
- :hash_secret => "w00t",
366
- :hash_data => ":class/:attachment/:style/:filename"
358
+ before do
359
+ rebuild_model path: ":hash",
360
+ hash_secret: "w00t",
361
+ hash_data: ":class/:attachment/:style/:filename"
367
362
  @attachment = Dummy.new.avatar
368
363
  @attachment.assign @file
369
364
  end
370
365
 
371
- should "result in the correct interpolation" do
372
- assert_equal "dummies/avatars/original/data.txt",
366
+ it "results in the correct interpolation" do
367
+ assert_equal "dummies/avatars/original/5k.png",
373
368
  @attachment.send(:interpolate, @attachment.options[:hash_data])
374
- assert_equal "dummies/avatars/thumb/data.txt",
369
+ assert_equal "dummies/avatars/thumb/5k.png",
375
370
  @attachment.send(:interpolate, @attachment.options[:hash_data], :thumb)
376
371
  end
377
372
 
378
- should "result in a correct hash" do
379
- assert_equal "e1079a5c34ddbd197ebd0280d07952d98a57fb30", @attachment.path
380
- assert_equal "d740189bd3e49ef226fab84c8d45f7ae4126d043", @attachment.path(:thumb)
373
+ it "results in a correct hash" do
374
+ assert_equal "0a59e9142bba11576de1d353d8747b1acad5ad34", @attachment.path
375
+ assert_equal "b39a062c1e62e85a6c785ed00cf3bebf5f850e2b", @attachment.path(:thumb)
381
376
  end
382
377
  end
383
378
  end
384
379
 
385
380
  context "An attachment with a :rails_env interpolation" do
386
- setup do
381
+ before do
387
382
  @rails_env = "blah"
388
383
  @id = 1024
389
- rebuild_model :path => ":rails_env/:id.png"
384
+ rebuild_model path: ":rails_env/:id.png"
390
385
  @dummy = Dummy.new
391
386
  @dummy.stubs(:id).returns(@id)
392
387
  @file = StringIO.new(".")
@@ -394,84 +389,84 @@ class AttachmentTest < Test::Unit::TestCase
394
389
  Rails.stubs(:env).returns(@rails_env)
395
390
  end
396
391
 
397
- should "return the proper path" do
392
+ it "returns the proper path" do
398
393
  assert_equal "#{@rails_env}/#{@id}.png", @dummy.avatar.path
399
394
  end
400
395
  end
401
396
 
402
397
  context "An attachment with a default style and an extension interpolation" do
403
- setup do
404
- rebuild_model :path => ":basename.:extension",
405
- :styles => { :default => ["100x100", :jpg] },
406
- :default_style => :default
398
+ before do
399
+ rebuild_model path: ":basename.:extension",
400
+ styles: { default: ["100x100", :jpg] },
401
+ default_style: :default
407
402
  @attachment = Dummy.new.avatar
408
403
  @file = File.open(fixture_file("5k.png"))
409
404
  @file.stubs(:original_filename).returns("file.png")
410
405
  end
411
- should "return the right extension for the path" do
406
+ it "returns the right extension for the path" do
412
407
  @attachment.assign(@file)
413
408
  assert_equal "file.jpg", @attachment.path
414
409
  end
415
410
  end
416
411
 
417
412
  context "An attachment with :convert_options" do
418
- setup do
419
- rebuild_model :styles => {
420
- :thumb => "100x100",
421
- :large => "400x400"
413
+ before do
414
+ rebuild_model styles: {
415
+ thumb: "100x100",
416
+ large: "400x400"
422
417
  },
423
- :convert_options => {
424
- :all => "-do_stuff",
425
- :thumb => "-thumbnailize"
418
+ convert_options: {
419
+ all: "-do_stuff",
420
+ thumb: "-thumbnailize"
426
421
  }
427
422
  @dummy = Dummy.new
428
423
  @dummy.avatar
429
424
  end
430
425
 
431
- should "report the correct options when sent #extra_options_for(:thumb)" do
426
+ it "reports the correct options when sent #extra_options_for(:thumb)" do
432
427
  assert_equal "-thumbnailize -do_stuff", @dummy.avatar.send(:extra_options_for, :thumb), @dummy.avatar.convert_options.inspect
433
428
  end
434
429
 
435
- should "report the correct options when sent #extra_options_for(:large)" do
430
+ it "reports the correct options when sent #extra_options_for(:large)" do
436
431
  assert_equal "-do_stuff", @dummy.avatar.send(:extra_options_for, :large)
437
432
  end
438
433
  end
439
434
 
440
435
  context "An attachment with :source_file_options" do
441
- setup do
442
- rebuild_model :styles => {
443
- :thumb => "100x100",
444
- :large => "400x400"
436
+ before do
437
+ rebuild_model styles: {
438
+ thumb: "100x100",
439
+ large: "400x400"
445
440
  },
446
- :source_file_options => {
447
- :all => "-density 400",
448
- :thumb => "-depth 8"
441
+ source_file_options: {
442
+ all: "-density 400",
443
+ thumb: "-depth 8"
449
444
  }
450
445
  @dummy = Dummy.new
451
446
  @dummy.avatar
452
447
  end
453
448
 
454
- should "report the correct options when sent #extra_source_file_options_for(:thumb)" do
449
+ it "reports the correct options when sent #extra_source_file_options_for(:thumb)" do
455
450
  assert_equal "-depth 8 -density 400", @dummy.avatar.send(:extra_source_file_options_for, :thumb), @dummy.avatar.source_file_options.inspect
456
451
  end
457
452
 
458
- should "report the correct options when sent #extra_source_file_options_for(:large)" do
453
+ it "reports the correct options when sent #extra_source_file_options_for(:large)" do
459
454
  assert_equal "-density 400", @dummy.avatar.send(:extra_source_file_options_for, :large)
460
455
  end
461
456
  end
462
457
 
463
458
  context "An attachment with :only_process" do
464
- setup do
465
- rebuild_model :styles => {
466
- :thumb => "100x100",
467
- :large => "400x400"
459
+ before do
460
+ rebuild_model styles: {
461
+ thumb: "100x100",
462
+ large: "400x400"
468
463
  },
469
- :only_process => [:thumb]
464
+ only_process: [:thumb]
470
465
  @file = StringIO.new("...")
471
466
  @attachment = Dummy.new.avatar
472
467
  end
473
468
 
474
- should "only process the provided style" do
469
+ it "only processes the provided style" do
475
470
  @attachment.expects(:post_process).with(:thumb)
476
471
  @attachment.expects(:post_process).with(:large).never
477
472
  @attachment.assign(@file)
@@ -479,18 +474,18 @@ class AttachmentTest < Test::Unit::TestCase
479
474
  end
480
475
 
481
476
  context "An attachment with :only_process that is a proc" do
482
- setup do
483
- rebuild_model :styles => {
484
- :thumb => "100x100",
485
- :large => "400x400"
477
+ before do
478
+ rebuild_model styles: {
479
+ thumb: "100x100",
480
+ large: "400x400"
486
481
  },
487
- :only_process => lambda { |attachment| [:thumb] }
482
+ only_process: lambda { |attachment| [:thumb] }
488
483
 
489
484
  @file = StringIO.new("...")
490
485
  @attachment = Dummy.new.avatar
491
486
  end
492
487
 
493
- should "only process the provided style" do
488
+ it "only processes the provided style" do
494
489
  @attachment.expects(:post_process).with(:thumb)
495
490
  @attachment.expects(:post_process).with(:large).never
496
491
  @attachment.assign(@file)
@@ -498,14 +493,14 @@ class AttachmentTest < Test::Unit::TestCase
498
493
  end
499
494
 
500
495
  context "An attachment with :convert_options that is a proc" do
501
- setup do
502
- rebuild_model :styles => {
503
- :thumb => "100x100",
504
- :large => "400x400"
496
+ before do
497
+ rebuild_model styles: {
498
+ thumb: "100x100",
499
+ large: "400x400"
505
500
  },
506
- :convert_options => {
507
- :all => lambda{|i| i.all },
508
- :thumb => lambda{|i| i.thumb }
501
+ convert_options: {
502
+ all: lambda{|i| i.all },
503
+ thumb: lambda{|i| i.thumb }
509
504
  }
510
505
  Dummy.class_eval do
511
506
  def all; "-all"; end
@@ -515,54 +510,54 @@ class AttachmentTest < Test::Unit::TestCase
515
510
  @dummy.avatar
516
511
  end
517
512
 
518
- should "report the correct options when sent #extra_options_for(:thumb)" do
513
+ it "reports the correct options when sent #extra_options_for(:thumb)" do
519
514
  assert_equal "-thumb -all", @dummy.avatar.send(:extra_options_for, :thumb), @dummy.avatar.convert_options.inspect
520
515
  end
521
516
 
522
- should "report the correct options when sent #extra_options_for(:large)" do
517
+ it "reports the correct options when sent #extra_options_for(:large)" do
523
518
  assert_equal "-all", @dummy.avatar.send(:extra_options_for, :large)
524
519
  end
525
520
  end
526
521
 
527
522
  context "An attachment with :path that is a proc" do
528
- setup do
529
- rebuild_model :path => lambda{ |attachment| "path/#{attachment.instance.other}.:extension" }
523
+ before do
524
+ rebuild_model path: lambda{ |attachment| "path/#{attachment.instance.other}.:extension" }
530
525
 
531
526
  @file = File.new(fixture_file("5k.png"), 'rb')
532
- @dummyA = Dummy.new(:other => 'a')
527
+ @dummyA = Dummy.new(other: 'a')
533
528
  @dummyA.avatar = @file
534
- @dummyB = Dummy.new(:other => 'b')
529
+ @dummyB = Dummy.new(other: 'b')
535
530
  @dummyB.avatar = @file
536
531
  end
537
532
 
538
- teardown { @file.close }
533
+ after { @file.close }
539
534
 
540
- should "return correct path" do
535
+ it "returns correct path" do
541
536
  assert_equal "path/a.png", @dummyA.avatar.path
542
537
  assert_equal "path/b.png", @dummyB.avatar.path
543
538
  end
544
539
  end
545
540
 
546
541
  context "An attachment with :styles that is a proc" do
547
- setup do
548
- rebuild_model :styles => lambda{ |attachment| {:thumb => "50x50#", :large => "400x400"} }
542
+ before do
543
+ rebuild_model styles: lambda{ |attachment| {thumb: "50x50#", large: "400x400"} }
549
544
 
550
545
  @attachment = Dummy.new.avatar
551
546
  end
552
547
 
553
- should "have the correct geometry" do
548
+ it "has the correct geometry" do
554
549
  assert_equal "50x50#", @attachment.styles[:thumb][:geometry]
555
550
  end
556
551
  end
557
552
 
558
553
  context "An attachment with conditional :styles that is a proc" do
559
- setup do
560
- rebuild_model :styles => lambda{ |attachment| attachment.instance.other == 'a' ? {:thumb => "50x50#"} : {:large => "400x400"} }
554
+ before do
555
+ rebuild_model styles: lambda{ |attachment| attachment.instance.other == 'a' ? {thumb: "50x50#"} : {large: "400x400"} }
561
556
 
562
- @dummy = Dummy.new(:other => 'a')
557
+ @dummy = Dummy.new(other: 'a')
563
558
  end
564
559
 
565
- should "have the correct styles for the assigned instance values" do
560
+ it "has the correct styles for the assigned instance values" do
566
561
  assert_equal "50x50#", @dummy.avatar.styles[:thumb][:geometry]
567
562
  assert_nil @dummy.avatar.styles[:large]
568
563
 
@@ -576,22 +571,22 @@ class AttachmentTest < Test::Unit::TestCase
576
571
  geometry_specs = [
577
572
  [ lambda{|z| "50x50#" }, :png ],
578
573
  lambda{|z| "50x50#" },
579
- { :geometry => lambda{|z| "50x50#" } }
574
+ { geometry: lambda{|z| "50x50#" } }
580
575
  ]
581
576
  geometry_specs.each do |geometry_spec|
582
577
  context "An attachment geometry like #{geometry_spec}" do
583
- setup do
584
- rebuild_model :styles => { :normal => geometry_spec }
578
+ before do
579
+ rebuild_model styles: { normal: geometry_spec }
585
580
  @attachment = Dummy.new.avatar
586
581
  end
587
582
 
588
583
  context "when assigned" do
589
- setup do
584
+ before do
590
585
  @file = StringIO.new(".")
591
586
  @attachment.assign(@file)
592
587
  end
593
588
 
594
- should "have the correct geometry" do
589
+ it "has the correct geometry" do
595
590
  assert_equal "50x50#", @attachment.styles[:normal][:geometry]
596
591
  end
597
592
  end
@@ -599,46 +594,46 @@ class AttachmentTest < Test::Unit::TestCase
599
594
  end
600
595
 
601
596
  context "An attachment with both 'normal' and hash-style styles" do
602
- setup do
603
- rebuild_model :styles => {
604
- :normal => ["50x50#", :png],
605
- :hash => { :geometry => "50x50#", :format => :png }
597
+ before do
598
+ rebuild_model styles: {
599
+ normal: ["50x50#", :png],
600
+ hash: { geometry: "50x50#", format: :png }
606
601
  }
607
602
  @dummy = Dummy.new
608
603
  @attachment = @dummy.avatar
609
604
  end
610
605
 
611
606
  [:processors, :whiny, :convert_options, :geometry, :format].each do |field|
612
- should "have the same #{field} field" do
607
+ it "has the same #{field} field" do
613
608
  assert_equal @attachment.styles[:normal][field], @attachment.styles[:hash][field]
614
609
  end
615
610
  end
616
611
  end
617
612
 
618
613
  context "An attachment with :processors that is a proc" do
619
- setup do
614
+ before do
620
615
  class Paperclip::Test < Paperclip::Processor; end
621
616
  @file = StringIO.new("...")
622
617
  Paperclip::Test.stubs(:make).returns(@file)
623
618
 
624
- rebuild_model :styles => { :normal => '' }, :processors => lambda { |a| [ :test ] }
619
+ rebuild_model styles: { normal: '' }, processors: lambda { |a| [ :test ] }
625
620
  @attachment = Dummy.new.avatar
626
621
  end
627
622
 
628
623
  context "when assigned" do
629
- setup do
624
+ before do
630
625
  @attachment.assign(StringIO.new("."))
631
626
  end
632
627
 
633
- should "have the correct processors" do
628
+ it "has the correct processors" do
634
629
  assert_equal [ :test ], @attachment.styles[:normal][:processors]
635
630
  end
636
631
  end
637
632
  end
638
633
 
639
634
  context "An attachment with erroring processor" do
640
- setup do
641
- rebuild_model :processor => [:thumbnail], :styles => { :small => '' }, :whiny_thumbnails => true
635
+ before do
636
+ rebuild_model processor: [:thumbnail], styles: { small: '' }, whiny_thumbnails: true
642
637
  @dummy = Dummy.new
643
638
  Paperclip::Thumbnail.expects(:make).raises(Paperclip::Error, "cannot be processed.")
644
639
  @file = StringIO.new("...")
@@ -646,17 +641,17 @@ class AttachmentTest < Test::Unit::TestCase
646
641
  @dummy.avatar = @file
647
642
  end
648
643
 
649
- should "correctly forward processing error message to the instance" do
644
+ it "correctly forwards processing error message to the instance" do
650
645
  @dummy.valid?
651
646
  assert_contains @dummy.errors.full_messages, "Avatar cannot be processed."
652
647
  end
653
648
  end
654
649
 
655
650
  context "An attachment with multiple processors" do
656
- setup do
651
+ before do
657
652
  class Paperclip::Test < Paperclip::Processor; end
658
- @style_params = { :once => {:one => 1, :two => 2} }
659
- rebuild_model :processors => [:thumbnail, :test], :styles => @style_params
653
+ @style_params = { once: {one: 1, two: 2} }
654
+ rebuild_model processors: [:thumbnail, :test], styles: @style_params
660
655
  @dummy = Dummy.new
661
656
  @file = StringIO.new("...")
662
657
  @file.stubs(:close)
@@ -665,56 +660,67 @@ class AttachmentTest < Test::Unit::TestCase
665
660
  end
666
661
 
667
662
  context "when assigned" do
668
- setup { @dummy.avatar = @file }
663
+ it "calls #make on all specified processors" do
664
+ Paperclip::Thumbnail.stubs(:make).with(any_parameters).returns(@file)
665
+ Paperclip::Test.stubs(:make).with(any_parameters).returns(@file)
669
666
 
670
- before_should "call #make on all specified processors" do
671
- Paperclip::Thumbnail.expects(:make).with(any_parameters).returns(@file)
672
- Paperclip::Test.expects(:make).with(any_parameters).returns(@file)
667
+ @dummy.avatar = @file
668
+
669
+ expect(Paperclip::Thumbnail).to have_received(:make)
670
+ expect(Paperclip::Test).to have_received(:make)
673
671
  end
674
672
 
675
- before_should "call #make with the right parameters passed as second argument" do
673
+ it "calls #make with the right parameters passed as second argument" do
676
674
  expected_params = @style_params[:once].merge({
677
- :processors => [:thumbnail, :test],
678
- :whiny => true,
679
- :convert_options => "",
680
- :source_file_options => ""
675
+ style: :once,
676
+ processors: [:thumbnail, :test],
677
+ whiny: true,
678
+ convert_options: "",
679
+ source_file_options: ""
681
680
  })
682
- Paperclip::Thumbnail.expects(:make).with(anything, expected_params, anything).returns(@file)
681
+ Paperclip::Thumbnail.stubs(:make).returns(@file)
682
+
683
+ @dummy.avatar = @file
684
+
685
+ expect(Paperclip::Thumbnail).to have_received(:make).with(anything, expected_params, anything)
683
686
  end
684
687
 
685
- before_should "call #make with attachment passed as third argument" do
686
- Paperclip::Test.expects(:make).with(anything, anything, @dummy.avatar).returns(@file)
688
+ it "calls #make with attachment passed as third argument" do
689
+ Paperclip::Test.expects(:make).returns(@file)
690
+
691
+ @dummy.avatar = @file
692
+
693
+ expect(Paperclip::Test).to have_received(:make).with(anything, anything, @dummy.avatar)
687
694
  end
688
695
  end
689
696
  end
690
697
 
691
- should "include the filesystem module when loading the filesystem storage" do
692
- rebuild_model :storage => :filesystem
698
+ it "includes the filesystem module when loading the filesystem storage" do
699
+ rebuild_model storage: :filesystem
693
700
  @dummy = Dummy.new
694
701
  assert @dummy.avatar.is_a?(Paperclip::Storage::Filesystem)
695
702
  end
696
703
 
697
- should "include the filesystem module even if capitalization is wrong" do
698
- rebuild_model :storage => :FileSystem
704
+ it "includes the filesystem module even if capitalization is wrong" do
705
+ rebuild_model storage: :FileSystem
699
706
  @dummy = Dummy.new
700
707
  assert @dummy.avatar.is_a?(Paperclip::Storage::Filesystem)
701
708
 
702
- rebuild_model :storage => :Filesystem
709
+ rebuild_model storage: :Filesystem
703
710
  @dummy = Dummy.new
704
711
  assert @dummy.avatar.is_a?(Paperclip::Storage::Filesystem)
705
712
  end
706
713
 
707
- should "convert underscored storage name to camelcase" do
708
- rebuild_model :storage => :not_here
714
+ it "converts underscored storage name to camelcase" do
715
+ rebuild_model storage: :not_here
709
716
  @dummy = Dummy.new
710
- exception = assert_raises(Paperclip::Errors::StorageMethodNotFound) do
717
+ exception = assert_raises(Paperclip::Errors::StorageMethodNotFound, /NotHere/) do
711
718
  @dummy.avatar
712
719
  end
713
- assert exception.message.include?("NotHere")
714
720
  end
715
721
 
716
- should "raise an error if you try to include a storage module that doesn't exist" do
717
- rebuild_model :storage => :not_here
722
+ it "raises an error if you try to include a storage module that doesn't exist" do
723
+ rebuild_model storage: :not_here
718
724
  @dummy = Dummy.new
719
725
  assert_raises(Paperclip::Errors::StorageMethodNotFound) do
720
726
  @dummy.avatar
@@ -722,30 +728,30 @@ class AttachmentTest < Test::Unit::TestCase
722
728
  end
723
729
 
724
730
  context "An attachment with styles but no processors defined" do
725
- setup do
726
- rebuild_model :processors => [], :styles => {:something => '1'}
731
+ before do
732
+ rebuild_model processors: [], styles: {something: '1'}
727
733
  @dummy = Dummy.new
728
734
  @file = StringIO.new("...")
729
735
  end
730
- should "raise when assigned to" do
736
+ it "raises when assigned to" do
731
737
  assert_raises(RuntimeError){ @dummy.avatar = @file }
732
738
  end
733
739
  end
734
740
 
735
741
  context "An attachment without styles and with no processors defined" do
736
- setup do
737
- rebuild_model :processors => [], :styles => {}
742
+ before do
743
+ rebuild_model processors: [], styles: {}
738
744
  @dummy = Dummy.new
739
745
  @file = StringIO.new("...")
740
746
  end
741
- should "not raise when assigned to" do
747
+ it "does not raise when assigned to" do
742
748
  @dummy.avatar = @file
743
749
  end
744
750
  end
745
751
 
746
752
  context "Assigning an attachment with post_process hooks" do
747
- setup do
748
- rebuild_class :styles => { :something => "100x100#" }
753
+ before do
754
+ rebuild_class styles: { something: "100x100#" }
749
755
  Dummy.class_eval do
750
756
  before_avatar_post_process :do_before_avatar
751
757
  after_avatar_post_process :do_after_avatar
@@ -763,7 +769,7 @@ class AttachmentTest < Test::Unit::TestCase
763
769
  @attachment = @dummy.avatar
764
770
  end
765
771
 
766
- should "call the defined callbacks when assigned" do
772
+ it "calls the defined callbacks when assigned" do
767
773
  @dummy.expects(:do_before_avatar).with()
768
774
  @dummy.expects(:do_after_avatar).with()
769
775
  @dummy.expects(:do_before_all).with()
@@ -772,7 +778,7 @@ class AttachmentTest < Test::Unit::TestCase
772
778
  @dummy.avatar = @file
773
779
  end
774
780
 
775
- should "not cancel the processing if a before_post_process returns nil" do
781
+ it "does not cancel the processing if a before_post_process returns nil" do
776
782
  @dummy.expects(:do_before_avatar).with().returns(nil)
777
783
  @dummy.expects(:do_after_avatar).with()
778
784
  @dummy.expects(:do_before_all).with().returns(nil)
@@ -781,7 +787,7 @@ class AttachmentTest < Test::Unit::TestCase
781
787
  @dummy.avatar = @file
782
788
  end
783
789
 
784
- should "cancel the processing if a before_post_process returns false" do
790
+ it "cancels the processing if a before_post_process returns false" do
785
791
  @dummy.expects(:do_before_avatar).never
786
792
  @dummy.expects(:do_after_avatar).never
787
793
  @dummy.expects(:do_before_all).with().returns(false)
@@ -790,7 +796,7 @@ class AttachmentTest < Test::Unit::TestCase
790
796
  @dummy.avatar = @file
791
797
  end
792
798
 
793
- should "cancel the processing if a before_avatar_post_process returns false" do
799
+ it "cancels the processing if a before_avatar_post_process returns false" do
794
800
  @dummy.expects(:do_before_avatar).with().returns(false)
795
801
  @dummy.expects(:do_after_avatar)
796
802
  @dummy.expects(:do_before_all).with().returns(true)
@@ -801,37 +807,37 @@ class AttachmentTest < Test::Unit::TestCase
801
807
  end
802
808
 
803
809
  context "Assigning an attachment" do
804
- setup do
805
- rebuild_model :styles => { :something => "100x100#" }
810
+ before do
811
+ rebuild_model styles: { something: "100x100#" }
806
812
  @file = File.new(fixture_file("5k.png"), "rb")
807
813
  @dummy = Dummy.new
808
814
  @dummy.avatar = @file
809
815
  end
810
816
 
811
- should "strip whitespace from original_filename field" do
817
+ it "strips whitespace from original_filename field" do
812
818
  assert_equal "5k.png", @dummy.avatar.original_filename
813
819
  end
814
820
 
815
- should "strip whitespace from content_type field" do
821
+ it "strips whitespace from content_type field" do
816
822
  assert_equal "image/png", @dummy.avatar.instance.avatar_content_type
817
823
  end
818
824
  end
819
825
 
820
826
  context "Assigning an attachment" do
821
- setup do
822
- rebuild_model :styles => { :something => "100x100#" }
827
+ before do
828
+ rebuild_model styles: { something: "100x100#" }
823
829
  @file = File.new(fixture_file("5k.png"), "rb")
824
830
  @dummy = Dummy.new
825
831
  @dummy.avatar = @file
826
832
  end
827
833
 
828
- should "make sure the content_type is a string" do
834
+ it "makes sure the content_type is a string" do
829
835
  assert_equal "image/png", @dummy.avatar.instance.avatar_content_type
830
836
  end
831
837
  end
832
838
 
833
839
  context "Attachment with strange letters" do
834
- setup do
840
+ before do
835
841
  rebuild_model
836
842
  @file = File.new(fixture_file("5k.png"), "rb")
837
843
  @file.stubs(:original_filename).returns("sheep_say_bæ.png")
@@ -839,18 +845,18 @@ class AttachmentTest < Test::Unit::TestCase
839
845
  @dummy.avatar = @file
840
846
  end
841
847
 
842
- should "not remove strange letters" do
848
+ it "does not remove strange letters" do
843
849
  assert_equal "sheep_say_bæ.png", @dummy.avatar.original_filename
844
850
  end
845
851
  end
846
852
 
847
853
  context "Attachment with reserved filename" do
848
- setup do
854
+ before do
849
855
  rebuild_model
850
856
  @file = Tempfile.new(["filename","png"])
851
857
  end
852
858
 
853
- teardown do
859
+ after do
854
860
  @file.unlink
855
861
  end
856
862
 
@@ -859,37 +865,37 @@ class AttachmentTest < Test::Unit::TestCase
859
865
  context "with character #{character}" do
860
866
 
861
867
  context "at beginning of filename" do
862
- setup do
868
+ before do
863
869
  @file.stubs(:original_filename).returns("#{character}filename.png")
864
870
  @dummy = Dummy.new
865
871
  @dummy.avatar = @file
866
872
  end
867
873
 
868
- should "convert special character into underscore" do
874
+ it "converts special character into underscore" do
869
875
  assert_equal "_filename.png", @dummy.avatar.original_filename
870
876
  end
871
877
  end
872
878
 
873
879
  context "at end of filename" do
874
- setup do
880
+ before do
875
881
  @file.stubs(:original_filename).returns("filename.png#{character}")
876
882
  @dummy = Dummy.new
877
883
  @dummy.avatar = @file
878
884
  end
879
885
 
880
- should "convert special character into underscore" do
886
+ it "converts special character into underscore" do
881
887
  assert_equal "filename.png_", @dummy.avatar.original_filename
882
888
  end
883
889
  end
884
890
 
885
891
  context "in the middle of filename" do
886
- setup do
892
+ before do
887
893
  @file.stubs(:original_filename).returns("file#{character}name.png")
888
894
  @dummy = Dummy.new
889
895
  @dummy.avatar = @file
890
896
  end
891
897
 
892
- should "convert special character into underscore" do
898
+ it "converts special character into underscore" do
893
899
  assert_equal "file_name.png", @dummy.avatar.original_filename
894
900
  end
895
901
  end
@@ -899,53 +905,53 @@ class AttachmentTest < Test::Unit::TestCase
899
905
  end
900
906
 
901
907
  context "with specified regexp replacement" do
902
- setup do
908
+ before do
903
909
  @old_defaults = Paperclip::Attachment.default_options.dup
904
910
  end
905
911
 
906
- teardown do
912
+ after do
907
913
  Paperclip::Attachment.default_options.merge! @old_defaults
908
914
  end
909
915
 
910
916
  context 'as another regexp' do
911
- setup do
912
- Paperclip::Attachment.default_options.merge! :restricted_characters => /o/
917
+ before do
918
+ Paperclip::Attachment.default_options.merge! restricted_characters: /o/
913
919
 
914
920
  @file.stubs(:original_filename).returns("goood.png")
915
921
  @dummy = Dummy.new
916
922
  @dummy.avatar = @file
917
923
  end
918
924
 
919
- should "match and convert that character" do
925
+ it "matches and converts that character" do
920
926
  assert_equal "g___d.png", @dummy.avatar.original_filename
921
927
  end
922
928
  end
923
929
 
924
930
  context 'as nil' do
925
- setup do
926
- Paperclip::Attachment.default_options.merge! :restricted_characters => nil
931
+ before do
932
+ Paperclip::Attachment.default_options.merge! restricted_characters: nil
927
933
 
928
934
  @file.stubs(:original_filename).returns("goood.png")
929
935
  @dummy = Dummy.new
930
936
  @dummy.avatar = @file
931
937
  end
932
938
 
933
- should "ignore and return the original file name" do
939
+ it "ignores and returns the original file name" do
934
940
  assert_equal "goood.png", @dummy.avatar.original_filename
935
941
  end
936
942
  end
937
943
  end
938
944
 
939
945
  context 'with specified cleaner' do
940
- setup do
946
+ before do
941
947
  @old_defaults = Paperclip::Attachment.default_options.dup
942
948
  end
943
949
 
944
- teardown do
950
+ after do
945
951
  Paperclip::Attachment.default_options.merge! @old_defaults
946
952
  end
947
953
 
948
- should 'call the given proc and take the result as cleaned filename' do
954
+ it 'calls the given proc and take the result as cleaned filename' do
949
955
  Paperclip::Attachment.default_options[:filename_cleaner] = lambda do |str|
950
956
  "from_proc_#{str}"
951
957
  end
@@ -956,7 +962,7 @@ class AttachmentTest < Test::Unit::TestCase
956
962
  assert_equal "from_proc_goood.png", @dummy.avatar.original_filename
957
963
  end
958
964
 
959
- should 'call the given object and take the result as the cleaned filename' do
965
+ it 'calls the given object and take the result as the cleaned filename' do
960
966
  class MyCleaner
961
967
  def call(filename)
962
968
  "foo"
@@ -973,16 +979,16 @@ class AttachmentTest < Test::Unit::TestCase
973
979
  end
974
980
 
975
981
  context "Attachment with uppercase extension and a default style" do
976
- setup do
982
+ before do
977
983
  @old_defaults = Paperclip::Attachment.default_options.dup
978
984
  Paperclip::Attachment.default_options.merge!({
979
- :path => ":rails_root/:attachment/:class/:style/:id/:basename.:extension"
985
+ path: ":rails_root/:attachment/:class/:style/:id/:basename.:extension"
980
986
  })
981
987
  FileUtils.rm_rf("tmp")
982
- rebuild_model :styles => { :large => ["400x400", :jpg],
983
- :medium => ["100x100", :jpg],
984
- :small => ["32x32#", :jpg]},
985
- :default_style => :small
988
+ rebuild_model styles: { large: ["400x400", :jpg],
989
+ medium: ["100x100", :jpg],
990
+ small: ["32x32#", :jpg]},
991
+ default_style: :small
986
992
  @instance = Dummy.new
987
993
  @instance.stubs(:id).returns 123
988
994
  @file = File.new(fixture_file("uppercase.PNG"), 'rb')
@@ -995,26 +1001,26 @@ class AttachmentTest < Test::Unit::TestCase
995
1001
  @attachment.save
996
1002
  end
997
1003
 
998
- teardown do
1004
+ after do
999
1005
  @file.close
1000
1006
  Paperclip::Attachment.default_options.merge!(@old_defaults)
1001
1007
  end
1002
1008
 
1003
- should "should have matching to_s and url methods" do
1004
- assert_match @attachment.to_s, @attachment.url
1005
- assert_match @attachment.to_s(:small), @attachment.url(:small)
1009
+ it "has matching to_s and url methods" do
1010
+ assert_equal @attachment.to_s, @attachment.url
1011
+ assert_equal @attachment.to_s(:small), @attachment.url(:small)
1006
1012
  end
1007
1013
 
1008
- should "have matching expiring_url and url methods when using the filesystem storage" do
1009
- assert_match @attachment.expiring_url, @attachment.url
1014
+ it "has matching expiring_url and url methods when using the filesystem storage" do
1015
+ assert_equal @attachment.expiring_url, @attachment.url
1010
1016
  end
1011
1017
  end
1012
1018
 
1013
1019
  context "An attachment" do
1014
- setup do
1020
+ before do
1015
1021
  @old_defaults = Paperclip::Attachment.default_options.dup
1016
1022
  Paperclip::Attachment.default_options.merge!({
1017
- :path => ":rails_root/:attachment/:class/:style/:id/:basename.:extension"
1023
+ path: ":rails_root/:attachment/:class/:style/:id/:basename.:extension"
1018
1024
  })
1019
1025
  FileUtils.rm_rf("tmp")
1020
1026
  rebuild_model
@@ -1025,39 +1031,39 @@ class AttachmentTest < Test::Unit::TestCase
1025
1031
  @file = File.new(fixture_file("5k.png"), 'rb')
1026
1032
  end
1027
1033
 
1028
- teardown do
1034
+ after do
1029
1035
  @file.close
1030
1036
  Paperclip::Attachment.default_options.merge!(@old_defaults)
1031
1037
  end
1032
1038
 
1033
- should "raise if there are not the correct columns when you try to assign" do
1039
+ it "raises if there are not the correct columns when you try to assign" do
1034
1040
  @other_attachment = Paperclip::Attachment.new(:not_here, @instance)
1035
1041
  assert_raises(Paperclip::Error) do
1036
1042
  @other_attachment.assign(@file)
1037
1043
  end
1038
1044
  end
1039
1045
 
1040
- should 'clear out the previous assignment when assigned nil' do
1046
+ it 'clears out the previous assignment when assigned nil' do
1041
1047
  @attachment.assign(@file)
1042
1048
  @attachment.queued_for_write[:original]
1043
1049
  @attachment.assign(nil)
1044
1050
  assert_nil @attachment.queued_for_write[:original]
1045
1051
  end
1046
1052
 
1047
- should 'not do anything when it is assigned an empty string' do
1053
+ it 'does not do anything when it is assigned an empty string' do
1048
1054
  @attachment.assign(@file)
1049
1055
  original_file = @attachment.queued_for_write[:original]
1050
1056
  @attachment.assign("")
1051
1057
  assert_equal original_file, @attachment.queued_for_write[:original]
1052
1058
  end
1053
1059
 
1054
- should "return nil as path when no file assigned" do
1060
+ it "returns nil as path when no file assigned" do
1055
1061
  assert_equal nil, @attachment.path
1056
1062
  assert_equal nil, @attachment.path(:blah)
1057
1063
  end
1058
1064
 
1059
1065
  context "with a file assigned but not saved yet" do
1060
- should "clear out any attached files" do
1066
+ it "clears out any attached files" do
1061
1067
  @attachment.assign(@file)
1062
1068
  assert !@attachment.queued_for_write.blank?
1063
1069
  @attachment.clear
@@ -1066,7 +1072,7 @@ class AttachmentTest < Test::Unit::TestCase
1066
1072
  end
1067
1073
 
1068
1074
  context "with a file assigned in the database" do
1069
- setup do
1075
+ before do
1070
1076
  @attachment.stubs(:instance_read).with(:file_name).returns("5k.png")
1071
1077
  @attachment.stubs(:instance_read).with(:content_type).returns("image/png")
1072
1078
  @attachment.stubs(:instance_read).with(:file_size).returns(12345)
@@ -1076,21 +1082,21 @@ class AttachmentTest < Test::Unit::TestCase
1076
1082
  @attachment.stubs(:instance_read).with(:updated_at).returns(dtnow)
1077
1083
  end
1078
1084
 
1079
- should "return the proper path when filename has a single .'s" do
1085
+ it "returns the proper path when filename has a single .'s" do
1080
1086
  assert_equal File.expand_path("tmp/avatars/dummies/original/#{@instance.id}/5k.png"), File.expand_path(@attachment.path)
1081
1087
  end
1082
1088
 
1083
- should "return the proper path when filename has multiple .'s" do
1089
+ it "returns the proper path when filename has multiple .'s" do
1084
1090
  @attachment.stubs(:instance_read).with(:file_name).returns("5k.old.png")
1085
1091
  assert_equal File.expand_path("tmp/avatars/dummies/original/#{@instance.id}/5k.old.png"), File.expand_path(@attachment.path)
1086
1092
  end
1087
1093
 
1088
1094
  context "when expecting three styles" do
1089
- setup do
1090
- rebuild_class :styles => {
1091
- :large => ["400x400", :png],
1092
- :medium => ["100x100", :gif],
1093
- :small => ["32x32#", :jpg]
1095
+ before do
1096
+ rebuild_class styles: {
1097
+ large: ["400x400", :png],
1098
+ medium: ["100x100", :gif],
1099
+ small: ["32x32#", :jpg]
1094
1100
  }
1095
1101
  @instance = Dummy.new
1096
1102
  @instance.stubs(:id).returns 123
@@ -1099,28 +1105,28 @@ class AttachmentTest < Test::Unit::TestCase
1099
1105
  end
1100
1106
 
1101
1107
  context "and assigned a file" do
1102
- setup do
1108
+ before do
1103
1109
  now = Time.now
1104
1110
  Time.stubs(:now).returns(now)
1105
1111
  @attachment.assign(@file)
1106
1112
  end
1107
1113
 
1108
- should "be dirty" do
1114
+ it "is dirty" do
1109
1115
  assert @attachment.dirty?
1110
1116
  end
1111
1117
 
1112
1118
  context "and saved" do
1113
- setup do
1119
+ before do
1114
1120
  @attachment.save
1115
1121
  end
1116
1122
 
1117
- should "commit the files to disk" do
1123
+ it "commits the files to disk" do
1118
1124
  [:large, :medium, :small].each do |style|
1119
- assert_file_exists(@attachment.path(style))
1125
+ expect(@attachment.path(style)).to exist
1120
1126
  end
1121
1127
  end
1122
1128
 
1123
- should "save the files as the right formats and sizes" do
1129
+ it "saves the files as the right formats and sizes" do
1124
1130
  [[:large, 400, 61, "PNG"],
1125
1131
  [:medium, 100, 15, "GIF"],
1126
1132
  [:small, 32, 32, "JPEG"]].each do |style|
@@ -1134,13 +1140,13 @@ class AttachmentTest < Test::Unit::TestCase
1134
1140
  end
1135
1141
 
1136
1142
  context "and trying to delete" do
1137
- setup do
1143
+ before do
1138
1144
  @existing_names = @attachment.styles.keys.collect do |style|
1139
1145
  @attachment.path(style)
1140
1146
  end
1141
1147
  end
1142
1148
 
1143
- should "delete the files after assigning nil" do
1149
+ it "deletes the files after assigning nil" do
1144
1150
  @attachment.expects(:instance_write).with(:file_name, nil)
1145
1151
  @attachment.expects(:instance_write).with(:content_type, nil)
1146
1152
  @attachment.expects(:instance_write).with(:file_size, nil)
@@ -1151,7 +1157,7 @@ class AttachmentTest < Test::Unit::TestCase
1151
1157
  @existing_names.each{|f| assert_file_not_exists(f) }
1152
1158
  end
1153
1159
 
1154
- should "delete the files when you call #clear and #save" do
1160
+ it "deletes the files when you call #clear and #save" do
1155
1161
  @attachment.expects(:instance_write).with(:file_name, nil)
1156
1162
  @attachment.expects(:instance_write).with(:content_type, nil)
1157
1163
  @attachment.expects(:instance_write).with(:file_size, nil)
@@ -1162,7 +1168,7 @@ class AttachmentTest < Test::Unit::TestCase
1162
1168
  @existing_names.each{|f| assert_file_not_exists(f) }
1163
1169
  end
1164
1170
 
1165
- should "delete the files when you call #delete" do
1171
+ it "deletes the files when you call #delete" do
1166
1172
  @attachment.expects(:instance_write).with(:file_name, nil)
1167
1173
  @attachment.expects(:instance_write).with(:content_type, nil)
1168
1174
  @attachment.expects(:instance_write).with(:file_size, nil)
@@ -1173,11 +1179,11 @@ class AttachmentTest < Test::Unit::TestCase
1173
1179
  end
1174
1180
 
1175
1181
  context "when keeping old files" do
1176
- setup do
1182
+ before do
1177
1183
  @attachment.options[:keep_old_files] = true
1178
1184
  end
1179
1185
 
1180
- should "keep the files after assigning nil" do
1186
+ it "keeps the files after assigning nil" do
1181
1187
  @attachment.expects(:instance_write).with(:file_name, nil)
1182
1188
  @attachment.expects(:instance_write).with(:content_type, nil)
1183
1189
  @attachment.expects(:instance_write).with(:file_size, nil)
@@ -1188,7 +1194,7 @@ class AttachmentTest < Test::Unit::TestCase
1188
1194
  @existing_names.each{|f| assert_file_exists(f) }
1189
1195
  end
1190
1196
 
1191
- should "keep the files when you call #clear and #save" do
1197
+ it "keeps the files when you call #clear and #save" do
1192
1198
  @attachment.expects(:instance_write).with(:file_name, nil)
1193
1199
  @attachment.expects(:instance_write).with(:content_type, nil)
1194
1200
  @attachment.expects(:instance_write).with(:file_size, nil)
@@ -1199,7 +1205,7 @@ class AttachmentTest < Test::Unit::TestCase
1199
1205
  @existing_names.each{|f| assert_file_exists(f) }
1200
1206
  end
1201
1207
 
1202
- should "keep the files when you call #delete" do
1208
+ it "keeps the files when you call #delete" do
1203
1209
  @attachment.expects(:instance_write).with(:file_name, nil)
1204
1210
  @attachment.expects(:instance_write).with(:content_type, nil)
1205
1211
  @attachment.expects(:instance_write).with(:file_size, nil)
@@ -1216,19 +1222,19 @@ class AttachmentTest < Test::Unit::TestCase
1216
1222
  end
1217
1223
 
1218
1224
  context "when trying a nonexistant storage type" do
1219
- setup do
1220
- rebuild_model :storage => :not_here
1225
+ before do
1226
+ rebuild_model storage: :not_here
1221
1227
  end
1222
1228
 
1223
- should "not be able to find the module" do
1224
- assert_raise(Paperclip::Errors::StorageMethodNotFound){ Dummy.new.avatar }
1229
+ it "is not able to find the module" do
1230
+ assert_raises(Paperclip::Errors::StorageMethodNotFound){ Dummy.new.avatar }
1225
1231
  end
1226
1232
  end
1227
1233
  end
1228
1234
 
1229
1235
  context "An attachment with only a avatar_file_name column" do
1230
- setup do
1231
- ActiveRecord::Base.connection.create_table :dummies, :force => true do |table|
1236
+ before do
1237
+ ActiveRecord::Base.connection.create_table :dummies, force: true do |table|
1232
1238
  table.column :avatar_file_name, :string
1233
1239
  end
1234
1240
  rebuild_class
@@ -1236,41 +1242,41 @@ class AttachmentTest < Test::Unit::TestCase
1236
1242
  @file = File.new(fixture_file("5k.png"), 'rb')
1237
1243
  end
1238
1244
 
1239
- teardown { @file.close }
1245
+ after { @file.close }
1240
1246
 
1241
- should "not error when assigned an attachment" do
1247
+ it "does not error when assigned an attachment" do
1242
1248
  assert_nothing_raised { @dummy.avatar = @file }
1243
1249
  end
1244
1250
 
1245
- should "not return the time when sent #avatar_updated_at" do
1251
+ it "does not return the time when sent #avatar_updated_at" do
1246
1252
  @dummy.avatar = @file
1247
1253
  assert_nil @dummy.avatar.updated_at
1248
1254
  end
1249
1255
 
1250
- should "return the right value when sent #avatar_file_size" do
1256
+ it "returns the right value when sent #avatar_file_size" do
1251
1257
  @dummy.avatar = @file
1252
1258
  assert_equal File.size(@file), @dummy.avatar.size
1253
1259
  end
1254
1260
 
1255
1261
  context "and avatar_created_at column" do
1256
- setup do
1262
+ before do
1257
1263
  ActiveRecord::Base.connection.add_column :dummies, :avatar_created_at, :timestamp
1258
1264
  rebuild_class
1259
1265
  @dummy = Dummy.new
1260
1266
  end
1261
1267
 
1262
- should "not error when assigned an attachment" do
1268
+ it "does not error when assigned an attachment" do
1263
1269
  assert_nothing_raised { @dummy.avatar = @file }
1264
1270
  end
1265
1271
 
1266
- should "return the creation time when sent #avatar_created_at" do
1272
+ it "returns the creation time when sent #avatar_created_at" do
1267
1273
  now = Time.now
1268
1274
  Time.stubs(:now).returns(now)
1269
1275
  @dummy.avatar = @file
1270
1276
  assert_equal now.to_i, @dummy.avatar.created_at
1271
1277
  end
1272
1278
 
1273
- should "return the creation time when sent #avatar_created_at and the entry has been updated" do
1279
+ it "returns the creation time when sent #avatar_created_at and the entry has been updated" do
1274
1280
  creation = 2.hours.ago
1275
1281
  now = Time.now
1276
1282
  Time.stubs(:now).returns(creation)
@@ -1281,7 +1287,7 @@ class AttachmentTest < Test::Unit::TestCase
1281
1287
  assert_not_equal now.to_i, @dummy.avatar.created_at
1282
1288
  end
1283
1289
 
1284
- should "set changed? to true on attachment assignment" do
1290
+ it "sets changed? to true on attachment assignment" do
1285
1291
  @dummy.avatar = @file
1286
1292
  @dummy.save!
1287
1293
  @dummy.avatar = @file
@@ -1290,17 +1296,17 @@ class AttachmentTest < Test::Unit::TestCase
1290
1296
  end
1291
1297
 
1292
1298
  context "and avatar_updated_at column" do
1293
- setup do
1299
+ before do
1294
1300
  ActiveRecord::Base.connection.add_column :dummies, :avatar_updated_at, :timestamp
1295
1301
  rebuild_class
1296
1302
  @dummy = Dummy.new
1297
1303
  end
1298
1304
 
1299
- should "not error when assigned an attachment" do
1305
+ it "does not error when assigned an attachment" do
1300
1306
  assert_nothing_raised { @dummy.avatar = @file }
1301
1307
  end
1302
1308
 
1303
- should "return the right value when sent #avatar_updated_at" do
1309
+ it "returns the right value when sent #avatar_updated_at" do
1304
1310
  now = Time.now
1305
1311
  Time.stubs(:now).returns(now)
1306
1312
  @dummy.avatar = @file
@@ -1308,45 +1314,45 @@ class AttachmentTest < Test::Unit::TestCase
1308
1314
  end
1309
1315
  end
1310
1316
 
1311
- should "not calculate fingerprint" do
1317
+ it "does not calculate fingerprint" do
1312
1318
  @dummy.avatar = @file
1313
1319
  assert_nil @dummy.avatar.fingerprint
1314
1320
  end
1315
1321
 
1316
1322
  context "and avatar_content_type column" do
1317
- setup do
1323
+ before do
1318
1324
  ActiveRecord::Base.connection.add_column :dummies, :avatar_content_type, :string
1319
1325
  rebuild_class
1320
1326
  @dummy = Dummy.new
1321
1327
  end
1322
1328
 
1323
- should "not error when assigned an attachment" do
1329
+ it "does not error when assigned an attachment" do
1324
1330
  assert_nothing_raised { @dummy.avatar = @file }
1325
1331
  end
1326
1332
 
1327
- should "return the right value when sent #avatar_content_type" do
1333
+ it "returns the right value when sent #avatar_content_type" do
1328
1334
  @dummy.avatar = @file
1329
1335
  assert_equal "image/png", @dummy.avatar.content_type
1330
1336
  end
1331
1337
  end
1332
1338
 
1333
1339
  context "and avatar_file_size column" do
1334
- setup do
1340
+ before do
1335
1341
  ActiveRecord::Base.connection.add_column :dummies, :avatar_file_size, :integer
1336
1342
  rebuild_class
1337
1343
  @dummy = Dummy.new
1338
1344
  end
1339
1345
 
1340
- should "not error when assigned an attachment" do
1346
+ it "does not error when assigned an attachment" do
1341
1347
  assert_nothing_raised { @dummy.avatar = @file }
1342
1348
  end
1343
1349
 
1344
- should "return the right value when sent #avatar_file_size" do
1350
+ it "returns the right value when sent #avatar_file_size" do
1345
1351
  @dummy.avatar = @file
1346
1352
  assert_equal File.size(@file), @dummy.avatar.size
1347
1353
  end
1348
1354
 
1349
- should "return the right value when saved, reloaded, and sent #avatar_file_size" do
1355
+ it "returns the right value when saved, reloaded, and sent #avatar_file_size" do
1350
1356
  @dummy.avatar = @file
1351
1357
  @dummy.save
1352
1358
  @dummy = Dummy.find(@dummy.id)
@@ -1355,22 +1361,22 @@ class AttachmentTest < Test::Unit::TestCase
1355
1361
  end
1356
1362
 
1357
1363
  context "and avatar_fingerprint column" do
1358
- setup do
1364
+ before do
1359
1365
  ActiveRecord::Base.connection.add_column :dummies, :avatar_fingerprint, :string
1360
1366
  rebuild_class
1361
1367
  @dummy = Dummy.new
1362
1368
  end
1363
1369
 
1364
- should "not error when assigned an attachment" do
1370
+ it "does not error when assigned an attachment" do
1365
1371
  assert_nothing_raised { @dummy.avatar = @file }
1366
1372
  end
1367
1373
 
1368
- should "return the right value when sent #avatar_fingerprint" do
1374
+ it "returns the right value when sent #avatar_fingerprint" do
1369
1375
  @dummy.avatar = @file
1370
1376
  assert_equal 'aec488126c3b33c08a10c3fa303acf27', @dummy.avatar_fingerprint
1371
1377
  end
1372
1378
 
1373
- should "return the right value when saved, reloaded, and sent #avatar_fingerprint" do
1379
+ it "returns the right value when saved, reloaded, and sent #avatar_fingerprint" do
1374
1380
  @dummy.avatar = @file
1375
1381
  @dummy.save
1376
1382
  @dummy = Dummy.find(@dummy.id)
@@ -1380,8 +1386,8 @@ class AttachmentTest < Test::Unit::TestCase
1380
1386
  end
1381
1387
 
1382
1388
  context "an attachment with delete_file option set to false" do
1383
- setup do
1384
- rebuild_model :preserve_files => true
1389
+ before do
1390
+ rebuild_model preserve_files: true
1385
1391
  @dummy = Dummy.new
1386
1392
  @file = File.new(fixture_file("5k.png"), 'rb')
1387
1393
  @dummy.avatar = @file
@@ -1390,27 +1396,27 @@ class AttachmentTest < Test::Unit::TestCase
1390
1396
  @path = @attachment.path
1391
1397
  end
1392
1398
 
1393
- teardown { @file.close }
1399
+ after { @file.close }
1394
1400
 
1395
- should "not delete the files from storage when attachment is destroyed" do
1401
+ it "does not delete the files from storage when attachment is destroyed" do
1396
1402
  @attachment.destroy
1397
1403
  assert_file_exists(@path)
1398
1404
  end
1399
1405
 
1400
- should "clear out attachment data when attachment is destroyed" do
1406
+ it "clears out attachment data when attachment is destroyed" do
1401
1407
  @attachment.destroy
1402
1408
  assert !@attachment.exists?
1403
1409
  assert_nil @dummy.avatar_file_name
1404
1410
  end
1405
1411
 
1406
- should "not delete the file when model is destroyed" do
1412
+ it "does not delete the file when model is destroyed" do
1407
1413
  @dummy.destroy
1408
1414
  assert_file_exists(@path)
1409
1415
  end
1410
1416
  end
1411
1417
 
1412
1418
  context "An attached file" do
1413
- setup do
1419
+ before do
1414
1420
  rebuild_model
1415
1421
  @dummy = Dummy.new
1416
1422
  @file = File.new(fixture_file("5k.png"), 'rb')
@@ -1420,24 +1426,24 @@ class AttachmentTest < Test::Unit::TestCase
1420
1426
  @path = @attachment.path
1421
1427
  end
1422
1428
 
1423
- teardown { @file.close }
1429
+ after { @file.close }
1424
1430
 
1425
- should "not be deleted when the model fails to destroy" do
1431
+ it "is not deleted when the model fails to destroy" do
1426
1432
  @dummy.stubs(:destroy).raises(Exception)
1427
1433
 
1428
- assert_raise Exception do
1434
+ assert_raises Exception do
1429
1435
  @dummy.destroy
1430
1436
  end
1431
1437
 
1432
1438
  assert_file_exists(@path)
1433
1439
  end
1434
1440
 
1435
- should "be deleted when the model is destroyed" do
1441
+ it "is deleted when the model is destroyed" do
1436
1442
  @dummy.destroy
1437
1443
  assert_file_not_exists(@path)
1438
1444
  end
1439
1445
 
1440
- should "not be deleted when transaction rollbacks after model is destroyed" do
1446
+ it "is not deleted when transaction rollbacks after model is destroyed" do
1441
1447
  ActiveRecord::Base.transaction do
1442
1448
  @dummy.destroy
1443
1449
  raise ActiveRecord::Rollback
@@ -1448,3 +1454,4 @@ class AttachmentTest < Test::Unit::TestCase
1448
1454
  end
1449
1455
 
1450
1456
  end
1457
+