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
@@ -0,0 +1,160 @@
1
+ require 'spec_helper'
2
+
3
+ describe Paperclip::Validators::AttachmentFileNameValidator do
4
+ before do
5
+ rebuild_model
6
+ @dummy = Dummy.new
7
+ end
8
+
9
+ def build_validator(options)
10
+ @validator = Paperclip::Validators::AttachmentFileNameValidator.new(options.merge(
11
+ attributes: :avatar
12
+ ))
13
+ end
14
+
15
+ context "with a failing validation" do
16
+ before do
17
+ build_validator matches: /.*\.png$/, allow_nil: false
18
+ @dummy.stubs(avatar_file_name: "data.txt")
19
+ @validator.validate(@dummy)
20
+ end
21
+
22
+ it "adds error to the base object" do
23
+ assert @dummy.errors[:avatar].present?,
24
+ "Error not added to base attribute"
25
+ end
26
+
27
+ it "adds error to base object as a string" do
28
+ expect(@dummy.errors[:avatar].first).to be_a String
29
+ end
30
+ end
31
+
32
+ it "does not add error to the base object with a successful validation" do
33
+ build_validator matches: /.*\.png$/, allow_nil: false
34
+ @dummy.stubs(avatar_file_name: "image.png")
35
+ @validator.validate(@dummy)
36
+
37
+ assert @dummy.errors[:avatar].blank?, "Error was added to base attribute"
38
+ end
39
+
40
+ context "whitelist format" do
41
+ context "with an allowed type" do
42
+ context "as a single regexp" do
43
+ before do
44
+ build_validator matches: /.*\.jpg$/
45
+ @dummy.stubs(avatar_file_name: "image.jpg")
46
+ @validator.validate(@dummy)
47
+ end
48
+
49
+ it "does not set an error message" do
50
+ assert @dummy.errors[:avatar_file_name].blank?
51
+ end
52
+ end
53
+
54
+ context "as a list" do
55
+ before do
56
+ build_validator matches: [/.*\.png$/, /.*\.jpe?g$/]
57
+ @dummy.stubs(avatar_file_name: "image.jpg")
58
+ @validator.validate(@dummy)
59
+ end
60
+
61
+ it "does not set an error message" do
62
+ assert @dummy.errors[:avatar_file_name].blank?
63
+ end
64
+ end
65
+ end
66
+
67
+ context "with a disallowed type" do
68
+ it "sets a correct default error message" do
69
+ build_validator matches: /^text\/.*/
70
+ @dummy.stubs(avatar_file_name: "image.jpg")
71
+ @validator.validate(@dummy)
72
+
73
+ assert @dummy.errors[:avatar_file_name].present?
74
+ expect(@dummy.errors[:avatar_file_name]).to include "is invalid"
75
+ end
76
+
77
+ it "sets a correct custom error message" do
78
+ build_validator matches: /.*\.png$/, message: "should be a PNG image"
79
+ @dummy.stubs(avatar_file_name: "image.jpg")
80
+ @validator.validate(@dummy)
81
+
82
+ expect(@dummy.errors[:avatar_file_name]).to include "should be a PNG image"
83
+ end
84
+ end
85
+ end
86
+
87
+ context "blacklist format" do
88
+ context "with an allowed type" do
89
+ context "as a single regexp" do
90
+ before do
91
+ build_validator not: /^text\/.*/
92
+ @dummy.stubs(avatar_file_name: "image.jpg")
93
+ @validator.validate(@dummy)
94
+ end
95
+
96
+ it "does not set an error message" do
97
+ assert @dummy.errors[:avatar_file_name].blank?
98
+ end
99
+ end
100
+
101
+ context "as a list" do
102
+ before do
103
+ build_validator not: [/.*\.png$/, /.*\.jpe?g$/]
104
+ @dummy.stubs(avatar_file_name: "image.gif")
105
+ @validator.validate(@dummy)
106
+ end
107
+
108
+ it "does not set an error message" do
109
+ assert @dummy.errors[:avatar_file_name].blank?
110
+ end
111
+ end
112
+ end
113
+
114
+ context "with a disallowed type" do
115
+ it "sets a correct default error message" do
116
+ build_validator not: /data.*/
117
+ @dummy.stubs(avatar_file_name: "data.txt")
118
+ @validator.validate(@dummy)
119
+
120
+ assert @dummy.errors[:avatar_file_name].present?
121
+ expect(@dummy.errors[:avatar_file_name]).to include "is invalid"
122
+ end
123
+
124
+ it "sets a correct custom error message" do
125
+ build_validator not: /.*\.png$/, message: "should not be a PNG image"
126
+ @dummy.stubs(avatar_file_name: "image.png")
127
+ @validator.validate(@dummy)
128
+
129
+ expect(@dummy.errors[:avatar_file_name]).to include "should not be a PNG image"
130
+ end
131
+ end
132
+ end
133
+
134
+ context "using the helper" do
135
+ before do
136
+ Dummy.validates_attachment_file_name :avatar, matches: /.*\.jpg$/
137
+ end
138
+
139
+ it "adds the validator to the class" do
140
+ assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_file_name }
141
+ end
142
+ end
143
+
144
+ context "given options" do
145
+ it "raises argument error if no required argument was given" do
146
+ assert_raises(ArgumentError) do
147
+ build_validator message: "Some message"
148
+ end
149
+ end
150
+
151
+ it "does not raise argument error if :matches was given" do
152
+ build_validator matches: /.*\.jpg$/
153
+ end
154
+
155
+ it "does not raise argument error if :not was given" do
156
+ build_validator not: /.*\.jpg$/
157
+ end
158
+ end
159
+ end
160
+
@@ -1,56 +1,56 @@
1
- require './test/helper'
1
+ require 'spec_helper'
2
2
 
3
- class AttachmentPresenceValidatorTest < Test::Unit::TestCase
4
- def setup
3
+ describe Paperclip::Validators::AttachmentPresenceValidator do
4
+ before do
5
5
  rebuild_model
6
6
  @dummy = Dummy.new
7
7
  end
8
8
 
9
9
  def build_validator(options={})
10
10
  @validator = Paperclip::Validators::AttachmentPresenceValidator.new(options.merge(
11
- :attributes => :avatar
11
+ attributes: :avatar
12
12
  ))
13
13
  end
14
14
 
15
15
  context "nil attachment" do
16
- setup do
16
+ before do
17
17
  @dummy.avatar = nil
18
18
  end
19
19
 
20
20
  context "with default options" do
21
- setup do
21
+ before do
22
22
  build_validator
23
23
  @validator.validate(@dummy)
24
24
  end
25
25
 
26
- should "add error on the attachment" do
26
+ it "adds error on the attachment" do
27
27
  assert @dummy.errors[:avatar].present?
28
28
  end
29
29
 
30
- should "not add an error on the file_name attribute" do
30
+ it "does not add an error on the file_name attribute" do
31
31
  assert @dummy.errors[:avatar_file_name].blank?
32
32
  end
33
33
  end
34
34
 
35
35
  context "with :if option" do
36
36
  context "returning true" do
37
- setup do
38
- build_validator :if => true
37
+ before do
38
+ build_validator if: true
39
39
  @validator.validate(@dummy)
40
40
  end
41
41
 
42
- should "perform a validation" do
42
+ it "performs a validation" do
43
43
  assert @dummy.errors[:avatar].present?
44
44
  end
45
45
  end
46
46
 
47
47
  context "returning false" do
48
- setup do
49
- build_validator :if => false
48
+ before do
49
+ build_validator if: false
50
50
  @validator.validate(@dummy)
51
51
  end
52
52
 
53
- should "perform a validation" do
53
+ it "performs a validation" do
54
54
  assert @dummy.errors[:avatar].present?
55
55
  end
56
56
  end
@@ -58,27 +58,27 @@ class AttachmentPresenceValidatorTest < Test::Unit::TestCase
58
58
  end
59
59
 
60
60
  context "with attachment" do
61
- setup do
61
+ before do
62
62
  build_validator
63
63
  @dummy.avatar = StringIO.new('.\n')
64
64
  @validator.validate(@dummy)
65
65
  end
66
66
 
67
- should "not add error on the attachment" do
67
+ it "does not add error on the attachment" do
68
68
  assert @dummy.errors[:avatar].blank?
69
69
  end
70
70
 
71
- should "not add an error on the file_name attribute" do
71
+ it "does not add an error on the file_name attribute" do
72
72
  assert @dummy.errors[:avatar_file_name].blank?
73
73
  end
74
74
  end
75
75
 
76
76
  context "using the helper" do
77
- setup do
77
+ before do
78
78
  Dummy.validates_attachment_presence :avatar
79
79
  end
80
80
 
81
- should "add the validator to the class" do
81
+ it "adds the validator to the class" do
82
82
  assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_presence }
83
83
  end
84
84
  end
@@ -1,27 +1,35 @@
1
- require './test/helper'
1
+ require 'spec_helper'
2
2
 
3
- class AttachmentSizeValidatorTest < Test::Unit::TestCase
4
- def setup
3
+ describe Paperclip::Validators::AttachmentSizeValidator do
4
+ before do
5
5
  rebuild_model
6
6
  @dummy = Dummy.new
7
7
  end
8
8
 
9
9
  def build_validator(options)
10
10
  @validator = Paperclip::Validators::AttachmentSizeValidator.new(options.merge(
11
- :attributes => :avatar
11
+ attributes: :avatar
12
12
  ))
13
13
  end
14
14
 
15
+ def self.storage_units
16
+ if defined?(ActiveSupport::NumberHelper) # Rails 4.0+
17
+ { 5120 => '5 KB', 10240 => '10 KB' }
18
+ else
19
+ { 5120 => '5120 Bytes', 10240 => '10240 Bytes' }
20
+ end
21
+ end
22
+
15
23
  def self.should_allow_attachment_file_size(size)
16
24
  context "when the attachment size is #{size}" do
17
- should "add error to dummy object" do
25
+ it "adds error to dummy object" do
18
26
  @dummy.stubs(:avatar_file_size).returns(size)
19
27
  @validator.validate(@dummy)
20
28
  assert @dummy.errors[:avatar_file_size].blank?,
21
29
  "Expect an error message on :avatar_file_size, got none."
22
30
  end
23
31
 
24
- should "not add error to the base dummy object" do
32
+ it "does not add error to the base dummy object" do
25
33
  assert @dummy.errors[:avatar].blank?,
26
34
  "Error added to base attribute"
27
35
  end
@@ -30,29 +38,28 @@ class AttachmentSizeValidatorTest < Test::Unit::TestCase
30
38
 
31
39
  def self.should_not_allow_attachment_file_size(size, options = {})
32
40
  context "when the attachment size is #{size}" do
33
- setup do
41
+ before do
34
42
  @dummy.stubs(:avatar_file_size).returns(size)
35
43
  @validator.validate(@dummy)
36
44
  end
37
45
 
38
- should "add error to dummy object" do
46
+ it "adds error to dummy object" do
39
47
  assert @dummy.errors[:avatar_file_size].present?,
40
48
  "Unexpected error message on :avatar_file_size"
41
49
  end
42
50
 
43
- should "add error to the base dummy object" do
51
+ it "adds error to the base dummy object" do
44
52
  assert @dummy.errors[:avatar].present?,
45
53
  "Error not added to base attribute"
46
54
  end
47
55
 
48
- should "add error to base object as a string" do
49
- assert_kind_of String, @dummy.errors[:avatar].first,
50
- "Error added to base attribute as something other than a String"
56
+ it "adds error to base object as a string" do
57
+ expect(@dummy.errors[:avatar].first).to be_a String
51
58
  end
52
59
 
53
60
  if options[:message]
54
- should "return a correct error message" do
55
- assert_includes @dummy.errors[:avatar_file_size], options[:message]
61
+ it "returns a correct error message" do
62
+ expect(@dummy.errors[:avatar_file_size]).to include options[:message]
56
63
  end
57
64
  end
58
65
  end
@@ -60,8 +67,8 @@ class AttachmentSizeValidatorTest < Test::Unit::TestCase
60
67
 
61
68
  context "with :in option" do
62
69
  context "as a range" do
63
- setup do
64
- build_validator :in => (5.kilobytes..10.kilobytes)
70
+ before do
71
+ build_validator in: (5.kilobytes..10.kilobytes)
65
72
  end
66
73
 
67
74
  should_allow_attachment_file_size(7.kilobytes)
@@ -70,8 +77,8 @@ class AttachmentSizeValidatorTest < Test::Unit::TestCase
70
77
  end
71
78
 
72
79
  context "as a proc" do
73
- setup do
74
- build_validator :in => lambda { |avatar| (5.kilobytes..10.kilobytes) }
80
+ before do
81
+ build_validator in: lambda { |avatar| (5.kilobytes..10.kilobytes) }
75
82
  end
76
83
 
77
84
  should_allow_attachment_file_size(7.kilobytes)
@@ -82,8 +89,8 @@ class AttachmentSizeValidatorTest < Test::Unit::TestCase
82
89
 
83
90
  context "with :greater_than option" do
84
91
  context "as number" do
85
- setup do
86
- build_validator :greater_than => 10.kilobytes
92
+ before do
93
+ build_validator greater_than: 10.kilobytes
87
94
  end
88
95
 
89
96
  should_allow_attachment_file_size 11.kilobytes
@@ -91,8 +98,8 @@ class AttachmentSizeValidatorTest < Test::Unit::TestCase
91
98
  end
92
99
 
93
100
  context "as a proc" do
94
- setup do
95
- build_validator :greater_than => lambda { |avatar| 10.kilobytes }
101
+ before do
102
+ build_validator greater_than: lambda { |avatar| 10.kilobytes }
96
103
  end
97
104
 
98
105
  should_allow_attachment_file_size 11.kilobytes
@@ -102,8 +109,8 @@ class AttachmentSizeValidatorTest < Test::Unit::TestCase
102
109
 
103
110
  context "with :less_than option" do
104
111
  context "as number" do
105
- setup do
106
- build_validator :less_than => 10.kilobytes
112
+ before do
113
+ build_validator less_than: 10.kilobytes
107
114
  end
108
115
 
109
116
  should_allow_attachment_file_size 9.kilobytes
@@ -111,8 +118,8 @@ class AttachmentSizeValidatorTest < Test::Unit::TestCase
111
118
  end
112
119
 
113
120
  context "as a proc" do
114
- setup do
115
- build_validator :less_than => lambda { |avatar| 10.kilobytes }
121
+ before do
122
+ build_validator less_than: lambda { |avatar| 10.kilobytes }
116
123
  end
117
124
 
118
125
  should_allow_attachment_file_size 9.kilobytes
@@ -122,9 +129,9 @@ class AttachmentSizeValidatorTest < Test::Unit::TestCase
122
129
 
123
130
  context "with :greater_than and :less_than option" do
124
131
  context "as numbers" do
125
- setup do
126
- build_validator :greater_than => 5.kilobytes,
127
- :less_than => 10.kilobytes
132
+ before do
133
+ build_validator greater_than: 5.kilobytes,
134
+ less_than: 10.kilobytes
128
135
  end
129
136
 
130
137
  should_allow_attachment_file_size 7.kilobytes
@@ -133,9 +140,9 @@ class AttachmentSizeValidatorTest < Test::Unit::TestCase
133
140
  end
134
141
 
135
142
  context "as a proc" do
136
- setup do
137
- build_validator :greater_than => lambda { |avatar| 5.kilobytes },
138
- :less_than => lambda { |avatar| 10.kilobytes }
143
+ before do
144
+ build_validator greater_than: lambda { |avatar| 5.kilobytes },
145
+ less_than: lambda { |avatar| 10.kilobytes }
139
146
  end
140
147
 
141
148
  should_allow_attachment_file_size 7.kilobytes
@@ -146,77 +153,77 @@ class AttachmentSizeValidatorTest < Test::Unit::TestCase
146
153
 
147
154
  context "with :message option" do
148
155
  context "given a range" do
149
- setup do
150
- build_validator :in => (5.kilobytes..10.kilobytes),
151
- :message => "is invalid. (Between %{min} and %{max} please.)"
156
+ before do
157
+ build_validator in: (5.kilobytes..10.kilobytes),
158
+ message: "is invalid. (Between %{min} and %{max} please.)"
152
159
  end
153
160
 
154
161
  should_not_allow_attachment_file_size 11.kilobytes,
155
- :message => "is invalid. (Between 5120 Bytes and 10240 Bytes please.)"
162
+ message: "is invalid. (Between #{storage_units[5120]} and #{storage_units[10240]} please.)"
156
163
  end
157
164
 
158
165
  context "given :less_than and :greater_than" do
159
- setup do
160
- build_validator :less_than => 10.kilobytes,
161
- :greater_than => 5.kilobytes,
162
- :message => "is invalid. (Between %{min} and %{max} please.)"
166
+ before do
167
+ build_validator less_than: 10.kilobytes,
168
+ greater_than: 5.kilobytes,
169
+ message: "is invalid. (Between %{min} and %{max} please.)"
163
170
  end
164
171
 
165
172
  should_not_allow_attachment_file_size 11.kilobytes,
166
- :message => "is invalid. (Between 5120 Bytes and 10240 Bytes please.)"
173
+ message: "is invalid. (Between #{storage_units[5120]} and #{storage_units[10240]} please.)"
167
174
  end
168
175
  end
169
176
 
170
177
  context "default error messages" do
171
178
  context "given :less_than and :greater_than" do
172
- setup do
173
- build_validator :greater_than => 5.kilobytes,
174
- :less_than => 10.kilobytes
179
+ before do
180
+ build_validator greater_than: 5.kilobytes,
181
+ less_than: 10.kilobytes
175
182
  end
176
183
 
177
184
  should_not_allow_attachment_file_size 11.kilobytes,
178
- :message => "must be less than 10240 Bytes"
185
+ message: "must be less than #{storage_units[10240]}"
179
186
  should_not_allow_attachment_file_size 4.kilobytes,
180
- :message => "must be greater than 5120 Bytes"
187
+ message: "must be greater than #{storage_units[5120]}"
181
188
  end
182
189
 
183
190
  context "given a size range" do
184
- setup do
185
- build_validator :in => (5.kilobytes..10.kilobytes)
191
+ before do
192
+ build_validator in: (5.kilobytes..10.kilobytes)
186
193
  end
187
194
 
188
195
  should_not_allow_attachment_file_size 11.kilobytes,
189
- :message => "must be in between 5120 Bytes and 10240 Bytes"
196
+ message: "must be in between #{storage_units[5120]} and #{storage_units[10240]}"
190
197
  should_not_allow_attachment_file_size 4.kilobytes,
191
- :message => "must be in between 5120 Bytes and 10240 Bytes"
198
+ message: "must be in between #{storage_units[5120]} and #{storage_units[10240]}"
192
199
  end
193
200
  end
194
201
 
195
202
  context "using the helper" do
196
- setup do
197
- Dummy.validates_attachment_size :avatar, :in => (5.kilobytes..10.kilobytes)
203
+ before do
204
+ Dummy.validates_attachment_size :avatar, in: (5.kilobytes..10.kilobytes)
198
205
  end
199
206
 
200
- should "add the validator to the class" do
207
+ it "adds the validator to the class" do
201
208
  assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_size }
202
209
  end
203
210
  end
204
211
 
205
212
  context "given options" do
206
- should "raise argument error if no required argument was given" do
213
+ it "raises argument error if no required argument was given" do
207
214
  assert_raises(ArgumentError) do
208
- build_validator :message => "Some message"
215
+ build_validator message: "Some message"
209
216
  end
210
217
  end
211
218
 
212
219
  (Paperclip::Validators::AttachmentSizeValidator::AVAILABLE_CHECKS).each do |argument|
213
- should "not raise arguemnt error if #{argument} was given" do
220
+ it "does not raise arguemnt error if #{argument} was given" do
214
221
  build_validator argument => 5.kilobytes
215
222
  end
216
223
  end
217
224
 
218
- should "not raise argument error if :in was given" do
219
- build_validator :in => (5.kilobytes..10.kilobytes)
225
+ it "does not raise argument error if :in was given" do
226
+ build_validator in: (5.kilobytes..10.kilobytes)
220
227
  end
221
228
  end
222
229
  end