paperclip 2.3.1.1 → 2.3.2
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.
- data/README.rdoc +6 -1
- data/Rakefile +11 -38
- data/generators/paperclip/USAGE +2 -2
- data/generators/paperclip/paperclip_generator.rb +8 -8
- data/lib/generators/paperclip/USAGE +8 -0
- data/lib/generators/paperclip/paperclip_generator.rb +31 -0
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
- data/lib/paperclip.rb +113 -69
- data/lib/paperclip/attachment.rb +58 -146
- data/lib/paperclip/callback_compatability.rb +50 -22
- data/lib/paperclip/geometry.rb +7 -7
- data/lib/paperclip/interpolations.rb +21 -21
- data/lib/paperclip/iostream.rb +3 -2
- data/lib/paperclip/matchers.rb +29 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +8 -0
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +13 -5
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +13 -7
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +16 -4
- data/lib/paperclip/processor.rb +2 -2
- data/lib/paperclip/railtie.rb +22 -0
- data/lib/paperclip/storage.rb +29 -25
- data/lib/paperclip/style.rb +90 -0
- data/lib/paperclip/thumbnail.rb +20 -15
- data/lib/paperclip/upfile.rb +5 -2
- data/lib/paperclip/version.rb +3 -0
- data/{tasks/paperclip_tasks.rake → lib/tasks/paperclip.rake} +0 -0
- data/rails/init.rb +2 -0
- data/shoulda_macros/paperclip.rb +5 -3
- data/test/attachment_test.rb +52 -74
- data/test/geometry_test.rb +1 -1
- data/test/helper.rb +62 -22
- data/test/integration_test.rb +8 -8
- data/test/interpolations_test.rb +4 -4
- data/test/iostream_test.rb +9 -2
- data/test/matchers/have_attached_file_matcher_test.rb +9 -6
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +15 -8
- data/test/matchers/validate_attachment_presence_matcher_test.rb +11 -6
- data/test/matchers/validate_attachment_size_matcher_test.rb +18 -17
- data/test/paperclip_test.rb +58 -68
- data/test/storage_test.rb +53 -13
- data/test/style_test.rb +141 -0
- data/test/thumbnail_test.rb +17 -17
- data/test/upfile_test.rb +8 -0
- metadata +69 -42
data/test/integration_test.rb
CHANGED
@@ -9,7 +9,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
9
9
|
Dummy.create! :avatar => @file
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
should "not exceed the open file limit" do
|
14
14
|
assert_nothing_raised do
|
15
15
|
dummies = Dummy.find(:all)
|
@@ -157,7 +157,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
157
157
|
end
|
158
158
|
end
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
context "A model with no convert_options setting" do
|
162
162
|
setup do
|
163
163
|
rebuild_model :styles => { :large => "300x300>",
|
@@ -168,7 +168,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
168
168
|
:path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
|
169
169
|
@dummy = Dummy.new
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
should "have its definition return nil when asked about convert_options" do
|
173
173
|
assert ! Dummy.attachment_definitions[:avatar][:convert_options]
|
174
174
|
end
|
@@ -189,7 +189,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
189
189
|
end
|
190
190
|
end
|
191
191
|
end
|
192
|
-
|
192
|
+
|
193
193
|
context "A model with a filesystem attachment" do
|
194
194
|
setup do
|
195
195
|
rebuild_model :styles => { :large => "300x300>",
|
@@ -281,7 +281,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
281
281
|
Dummy.validates_attachment_presence :avatar
|
282
282
|
@d2 = Dummy.find(@dummy.id)
|
283
283
|
@d2.avatar = @file
|
284
|
-
assert @d2.valid?, @d2.errors.full_messages.inspect
|
284
|
+
assert @d2.valid?, @d2.errors.full_messages.inspect
|
285
285
|
@d2.avatar = @bad_file
|
286
286
|
assert ! @d2.valid?
|
287
287
|
end
|
@@ -294,7 +294,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
294
294
|
@dummy.reload
|
295
295
|
assert_equal "5k.png", @dummy.avatar_file_name
|
296
296
|
end
|
297
|
-
|
297
|
+
|
298
298
|
context "that is assigned its file from another Paperclip attachment" do
|
299
299
|
setup do
|
300
300
|
@dummy2 = Dummy.new
|
@@ -302,7 +302,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
302
302
|
assert @dummy2.avatar = @file2
|
303
303
|
@dummy2.save
|
304
304
|
end
|
305
|
-
|
305
|
+
|
306
306
|
should "work when assigned a file" do
|
307
307
|
assert_not_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`,
|
308
308
|
`identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"`
|
@@ -312,7 +312,7 @@ class IntegrationTest < Test::Unit::TestCase
|
|
312
312
|
assert_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`,
|
313
313
|
`identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"`
|
314
314
|
end
|
315
|
-
end
|
315
|
+
end
|
316
316
|
|
317
317
|
end
|
318
318
|
|
data/test/interpolations_test.rb
CHANGED
@@ -11,12 +11,12 @@ class InterpolationsTest < Test::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
should "return the
|
15
|
-
assert_equal
|
14
|
+
should "return the Rails.root" do
|
15
|
+
assert_equal Rails.root, Paperclip::Interpolations.rails_root(:attachment, :style)
|
16
16
|
end
|
17
17
|
|
18
|
-
should "return the
|
19
|
-
assert_equal
|
18
|
+
should "return the Rails.env" do
|
19
|
+
assert_equal Rails.env, Paperclip::Interpolations.rails_env(:attachment, :style)
|
20
20
|
end
|
21
21
|
|
22
22
|
should "return the class of the Interpolations module when called with no params" do
|
data/test/iostream_test.rb
CHANGED
@@ -58,8 +58,15 @@ class IOStreamTest < Test::Unit::TestCase
|
|
58
58
|
assert @tempfile = @file.to_tempfile
|
59
59
|
end
|
60
60
|
|
61
|
-
should "convert it to a Tempfile" do
|
62
|
-
assert @tempfile.is_a?(Tempfile)
|
61
|
+
should "convert it to a Paperclip Tempfile" do
|
62
|
+
assert @tempfile.is_a?(Paperclip::Tempfile)
|
63
|
+
end
|
64
|
+
|
65
|
+
should "have the name be based on the original_filename" do
|
66
|
+
name = File.basename(@file.path)
|
67
|
+
extension = File.extname(name)
|
68
|
+
basename = File.basename(name, extension)
|
69
|
+
assert_match %r[^stream.*?#{Regexp.quote(extension)}], File.basename(@tempfile.path)
|
63
70
|
end
|
64
71
|
|
65
72
|
should "have the Tempfile contain the same data as the file" do
|
@@ -8,14 +8,17 @@ class HaveAttachedFileMatcherTest < Test::Unit::TestCase
|
|
8
8
|
@matcher = self.class.have_attached_file(:avatar)
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
context "given a class with no attachment" do
|
12
|
+
should_reject_dummy_class
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
context "given a class with an attachment" do
|
16
|
+
setup do
|
17
|
+
modify_table("dummies"){|d| d.string :avatar_file_name }
|
18
|
+
@dummy_class.has_attached_file :avatar
|
19
|
+
end
|
20
|
+
|
21
|
+
should_accept_dummy_class
|
19
22
|
end
|
20
23
|
end
|
21
24
|
end
|
@@ -5,6 +5,7 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
|
|
5
5
|
setup do
|
6
6
|
reset_table("dummies") do |d|
|
7
7
|
d.string :avatar_file_name
|
8
|
+
d.string :avatar_content_type
|
8
9
|
end
|
9
10
|
@dummy_class = reset_class "Dummy"
|
10
11
|
@dummy_class.has_attached_file :avatar
|
@@ -13,18 +14,24 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
|
|
13
14
|
rejecting(%w(audio/mp3 application/octet-stream))
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
context "given a class with no validation" do
|
18
|
+
should_reject_dummy_class
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
context "given a class with a validation that doesn't match" do
|
22
|
+
setup do
|
23
|
+
@dummy_class.validates_attachment_content_type :avatar, :content_type => %r{audio/.*}
|
24
|
+
end
|
25
|
+
|
26
|
+
should_reject_dummy_class
|
23
27
|
end
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
29
|
+
context "given a class with a matching validation" do
|
30
|
+
setup do
|
31
|
+
@dummy_class.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
|
32
|
+
end
|
33
|
+
|
34
|
+
should_accept_dummy_class
|
28
35
|
end
|
29
36
|
end
|
30
37
|
end
|
@@ -3,19 +3,24 @@ require 'test/helper'
|
|
3
3
|
class ValidateAttachmentPresenceMatcherTest < Test::Unit::TestCase
|
4
4
|
context "validate_attachment_presence" do
|
5
5
|
setup do
|
6
|
-
reset_table("dummies")
|
6
|
+
reset_table("dummies") do |d|
|
7
|
+
d.string :avatar_file_name
|
8
|
+
end
|
7
9
|
@dummy_class = reset_class "Dummy"
|
8
10
|
@dummy_class.has_attached_file :avatar
|
9
11
|
@matcher = self.class.validate_attachment_presence(:avatar)
|
10
12
|
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
context "given a class with no validation" do
|
15
|
+
should_reject_dummy_class
|
14
16
|
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
context "given a class with a matching validation" do
|
19
|
+
setup do
|
20
|
+
@dummy_class.validates_attachment_presence :avatar
|
21
|
+
end
|
22
|
+
|
23
|
+
should_accept_dummy_class
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|
@@ -5,6 +5,7 @@ class ValidateAttachmentSizeMatcherTest < Test::Unit::TestCase
|
|
5
5
|
setup do
|
6
6
|
reset_table("dummies") do |d|
|
7
7
|
d.string :avatar_file_name
|
8
|
+
d.integer :avatar_file_size
|
8
9
|
end
|
9
10
|
@dummy_class = reset_class "Dummy"
|
10
11
|
@dummy_class.has_attached_file :avatar
|
@@ -13,37 +14,37 @@ class ValidateAttachmentSizeMatcherTest < Test::Unit::TestCase
|
|
13
14
|
context "of limited size" do
|
14
15
|
setup{ @matcher = self.class.validate_attachment_size(:avatar).in(256..1024) }
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
context "given a class with no validation" do
|
18
|
+
should_reject_dummy_class
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
-
@dummy_class.validates_attachment_size :avatar, :in => 256..2048
|
22
|
-
|
21
|
+
context "given a class with a validation that's too high" do
|
22
|
+
setup { @dummy_class.validates_attachment_size :avatar, :in => 256..2048 }
|
23
|
+
should_reject_dummy_class
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
@dummy_class.validates_attachment_size :avatar, :in => 0..1024
|
27
|
-
|
26
|
+
context "given a class with a validation that's too low" do
|
27
|
+
setup { @dummy_class.validates_attachment_size :avatar, :in => 0..1024 }
|
28
|
+
should_reject_dummy_class
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
|
-
@dummy_class.validates_attachment_size :avatar, :in => 256..1024
|
32
|
-
|
31
|
+
context "given a class with a validation that matches" do
|
32
|
+
setup { @dummy_class.validates_attachment_size :avatar, :in => 256..1024 }
|
33
|
+
should_accept_dummy_class
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
36
37
|
context "validates_attachment_size with infinite range" do
|
37
38
|
setup{ @matcher = self.class.validate_attachment_size(:avatar) }
|
38
39
|
|
39
|
-
|
40
|
-
@dummy_class.validates_attachment_size :avatar, :less_than => 1
|
41
|
-
|
40
|
+
context "given a class with an upper limit" do
|
41
|
+
setup { @dummy_class.validates_attachment_size :avatar, :less_than => 1 }
|
42
|
+
should_accept_dummy_class
|
42
43
|
end
|
43
44
|
|
44
|
-
|
45
|
-
@dummy_class.validates_attachment_size :avatar, :greater_than => 1
|
46
|
-
|
45
|
+
context "given a class with no upper limit" do
|
46
|
+
setup { @dummy_class.validates_attachment_size :avatar, :greater_than => 1 }
|
47
|
+
should_accept_dummy_class
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
data/test/paperclip_test.rb
CHANGED
@@ -16,8 +16,8 @@ class PaperclipTest < Test::Unit::TestCase
|
|
16
16
|
should "execute the right command" do
|
17
17
|
Paperclip.expects(:path_for_command).with("convert").returns("/usr/bin/convert")
|
18
18
|
Paperclip.expects(:bit_bucket).returns("/dev/null")
|
19
|
-
Paperclip.expects(:"`").with("/usr/bin/convert one.jpg two.jpg 2>/dev/null")
|
20
|
-
Paperclip.run("convert", "one.jpg two.jpg")
|
19
|
+
Paperclip.expects(:"`").with("/usr/bin/convert 'one.jpg' 'two.jpg' 2>/dev/null")
|
20
|
+
Paperclip.run("convert", "one.jpg", "two.jpg")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -35,49 +35,68 @@ class PaperclipTest < Test::Unit::TestCase
|
|
35
35
|
should "execute the right command" do
|
36
36
|
Paperclip.expects(:path_for_command).with("convert").returns("convert")
|
37
37
|
Paperclip.expects(:bit_bucket).returns("/dev/null")
|
38
|
-
Paperclip.expects(:"`").with("convert one.jpg two.jpg 2>/dev/null")
|
39
|
-
Paperclip.run("convert", "one.jpg two.jpg")
|
38
|
+
Paperclip.expects(:"`").with("convert 'one.jpg' 'two.jpg' 2>/dev/null")
|
39
|
+
Paperclip.run("convert", "one.jpg", "two.jpg")
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
context "Calling Paperclip.run and logging" do
|
44
|
-
|
44
|
+
should "log the command when :log_command is true" do
|
45
45
|
Paperclip.options[:image_magick_path] = nil
|
46
46
|
Paperclip.options[:command_path] = nil
|
47
47
|
Paperclip.stubs(:bit_bucket).returns("/dev/null")
|
48
|
-
Paperclip.
|
49
|
-
Paperclip.
|
50
|
-
end
|
51
|
-
|
52
|
-
should "log the command when :log_command is true" do
|
48
|
+
Paperclip.expects(:log).with("this 'is the command' 2>/dev/null")
|
49
|
+
Paperclip.expects(:"`").with("this 'is the command' 2>/dev/null")
|
53
50
|
Paperclip.options[:log_command] = true
|
54
51
|
Paperclip.run("this","is the command")
|
55
|
-
assert_received(Paperclip, :log) do |p|
|
56
|
-
p.with("this is the command 2>/dev/null")
|
57
|
-
end
|
58
|
-
assert_received(Paperclip, :`) do |p|
|
59
|
-
p.with("this is the command 2>/dev/null")
|
60
|
-
end
|
61
52
|
end
|
62
53
|
|
63
54
|
should "not log the command when :log_command is false" do
|
55
|
+
Paperclip.options[:image_magick_path] = nil
|
56
|
+
Paperclip.options[:command_path] = nil
|
57
|
+
Paperclip.stubs(:bit_bucket).returns("/dev/null")
|
58
|
+
Paperclip.expects(:log).with("this 'is the command' 2>/dev/null").never
|
59
|
+
Paperclip.expects(:"`").with("this 'is the command' 2>/dev/null")
|
64
60
|
Paperclip.options[:log_command] = false
|
65
61
|
Paperclip.run("this","is the command")
|
66
|
-
|
67
|
-
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "Calling Paperclip.run when the command is not found" do
|
66
|
+
should "tell you the command isn't there if the shell returns 127" do
|
67
|
+
begin
|
68
|
+
assert_raises(Paperclip::CommandNotFoundError) do
|
69
|
+
`ruby -e 'exit 127'` # Stub $?.exitstatus to be 127, i.e. Command Not Found.
|
70
|
+
Paperclip.stubs(:"`").returns("")
|
71
|
+
Paperclip.run("command")
|
72
|
+
end
|
73
|
+
ensure
|
74
|
+
`ruby -e 'exit 0'` # Unstub $?.exitstatus
|
68
75
|
end
|
69
|
-
|
70
|
-
|
76
|
+
end
|
77
|
+
should "tell you the command isn't there if an ENOENT is raised" do
|
78
|
+
assert_raises(Paperclip::CommandNotFoundError) do
|
79
|
+
Paperclip.stubs(:"`").raises(Errno::ENOENT)
|
80
|
+
Paperclip.run("command")
|
71
81
|
end
|
72
82
|
end
|
73
83
|
end
|
74
84
|
|
85
|
+
should "prevent dangerous characters in the command via quoting" do
|
86
|
+
Paperclip.options[:image_magick_path] = nil
|
87
|
+
Paperclip.options[:command_path] = nil
|
88
|
+
Paperclip.options[:log_command] = false
|
89
|
+
Paperclip.options[:swallow_stderr] = false
|
90
|
+
Paperclip.expects(:"`").with(%q[this 'is' 'jack'\''s' '`command`' 'line!'])
|
91
|
+
Paperclip.run("this", "is", "jack's", "`command`", "line!")
|
92
|
+
end
|
93
|
+
|
75
94
|
context "Paperclip.bit_bucket" do
|
76
95
|
context "on systems without /dev/null" do
|
77
96
|
setup do
|
78
97
|
File.expects(:exists?).with("/dev/null").returns(false)
|
79
98
|
end
|
80
|
-
|
99
|
+
|
81
100
|
should "return 'NUL'" do
|
82
101
|
assert_equal "NUL", Paperclip.bit_bucket
|
83
102
|
end
|
@@ -87,7 +106,7 @@ class PaperclipTest < Test::Unit::TestCase
|
|
87
106
|
setup do
|
88
107
|
File.expects(:exists?).with("/dev/null").returns(true)
|
89
108
|
end
|
90
|
-
|
109
|
+
|
91
110
|
should "return '/dev/null'" do
|
92
111
|
assert_equal "/dev/null", Paperclip.bit_bucket
|
93
112
|
end
|
@@ -133,7 +152,7 @@ class PaperclipTest < Test::Unit::TestCase
|
|
133
152
|
should "not assign the avatar on mass-set" do
|
134
153
|
@dummy.attributes = { :other => "I'm set!",
|
135
154
|
:avatar => @file }
|
136
|
-
|
155
|
+
|
137
156
|
assert_equal "I'm set!", @dummy.other
|
138
157
|
assert ! @dummy.avatar?
|
139
158
|
end
|
@@ -141,7 +160,7 @@ class PaperclipTest < Test::Unit::TestCase
|
|
141
160
|
should "still allow assigment on normal set" do
|
142
161
|
@dummy.other = "I'm set!"
|
143
162
|
@dummy.avatar = @file
|
144
|
-
|
163
|
+
|
145
164
|
assert_equal "I'm set!", @dummy.other
|
146
165
|
assert @dummy.avatar?
|
147
166
|
end
|
@@ -185,45 +204,23 @@ class PaperclipTest < Test::Unit::TestCase
|
|
185
204
|
should "be valid" do
|
186
205
|
assert @dummy.valid?
|
187
206
|
end
|
188
|
-
|
189
|
-
context "then has a validation added that makes it invalid" do
|
190
|
-
setup do
|
191
|
-
assert @dummy.save
|
192
|
-
Dummy.class_eval do
|
193
|
-
validates_attachment_content_type :avatar, :content_type => ["text/plain"]
|
194
|
-
end
|
195
|
-
@dummy2 = Dummy.find(@dummy.id)
|
196
|
-
end
|
197
|
-
|
198
|
-
should "be invalid when reloaded" do
|
199
|
-
assert ! @dummy2.valid?, @dummy2.errors.inspect
|
200
|
-
end
|
201
|
-
|
202
|
-
should "be able to call #valid? twice without having duplicate errors" do
|
203
|
-
@dummy2.avatar.valid?
|
204
|
-
first_errors = @dummy2.avatar.errors
|
205
|
-
@dummy2.avatar.valid?
|
206
|
-
assert_equal first_errors, @dummy2.avatar.errors
|
207
|
-
end
|
208
|
-
end
|
209
207
|
end
|
210
208
|
|
211
209
|
context "a validation with an if guard clause" do
|
212
210
|
setup do
|
213
211
|
Dummy.send(:"validates_attachment_presence", :avatar, :if => lambda{|i| i.foo })
|
214
212
|
@dummy = Dummy.new
|
213
|
+
@dummy.stubs(:avatar_file_name).returns(nil)
|
215
214
|
end
|
216
215
|
|
217
216
|
should "attempt validation if the guard returns true" do
|
218
217
|
@dummy.expects(:foo).returns(true)
|
219
|
-
@dummy.
|
220
|
-
@dummy.valid?
|
218
|
+
assert ! @dummy.valid?
|
221
219
|
end
|
222
220
|
|
223
221
|
should "not attempt validation if the guard returns false" do
|
224
222
|
@dummy.expects(:foo).returns(false)
|
225
|
-
@dummy.
|
226
|
-
@dummy.valid?
|
223
|
+
assert @dummy.valid?
|
227
224
|
end
|
228
225
|
end
|
229
226
|
|
@@ -231,18 +228,17 @@ class PaperclipTest < Test::Unit::TestCase
|
|
231
228
|
setup do
|
232
229
|
Dummy.send(:"validates_attachment_presence", :avatar, :unless => lambda{|i| i.foo })
|
233
230
|
@dummy = Dummy.new
|
231
|
+
@dummy.stubs(:avatar_file_name).returns(nil)
|
234
232
|
end
|
235
233
|
|
236
234
|
should "attempt validation if the guard returns true" do
|
237
235
|
@dummy.expects(:foo).returns(false)
|
238
|
-
@dummy.
|
239
|
-
@dummy.valid?
|
236
|
+
assert ! @dummy.valid?
|
240
237
|
end
|
241
238
|
|
242
239
|
should "not attempt validation if the guard returns false" do
|
243
240
|
@dummy.expects(:foo).returns(true)
|
244
|
-
@dummy.
|
245
|
-
@dummy.valid?
|
241
|
+
assert @dummy.valid?
|
246
242
|
end
|
247
243
|
end
|
248
244
|
|
@@ -259,11 +255,11 @@ class PaperclipTest < Test::Unit::TestCase
|
|
259
255
|
end
|
260
256
|
if validation == :presence
|
261
257
|
should "have an error on the attachment" do
|
262
|
-
assert @dummy.errors
|
258
|
+
assert @dummy.errors[:avatar_file_name]
|
263
259
|
end
|
264
260
|
else
|
265
261
|
should "not have an error on the attachment" do
|
266
|
-
|
262
|
+
assert @dummy.errors[:avatar_file_name].blank?, @dummy.errors.full_messages.join(", ")
|
267
263
|
end
|
268
264
|
end
|
269
265
|
end
|
@@ -273,10 +269,7 @@ class PaperclipTest < Test::Unit::TestCase
|
|
273
269
|
@dummy.valid?
|
274
270
|
end
|
275
271
|
should "not have an error when assigned a valid file" do
|
276
|
-
|
277
|
-
end
|
278
|
-
should "not have an error on the attachment" do
|
279
|
-
assert_nil @dummy.errors.on(:avatar)
|
272
|
+
assert_equal 0, @dummy.errors.length, @dummy.errors.full_messages.join(", ")
|
280
273
|
end
|
281
274
|
end
|
282
275
|
context "and assigned an invalid file" do
|
@@ -285,17 +278,14 @@ class PaperclipTest < Test::Unit::TestCase
|
|
285
278
|
@dummy.valid?
|
286
279
|
end
|
287
280
|
should "have an error when assigned a valid file" do
|
288
|
-
|
289
|
-
end
|
290
|
-
should "have an error on the attachment" do
|
291
|
-
assert @dummy.errors.on(:avatar)
|
281
|
+
assert @dummy.errors.length > 0
|
292
282
|
end
|
293
283
|
end
|
294
284
|
end
|
295
285
|
end
|
296
286
|
|
297
287
|
[[:presence, {}, "5k.png", nil],
|
298
|
-
[:size, {:in => 1..10240},
|
288
|
+
[:size, {:in => 1..10240}, "5k.png", "12k.png"],
|
299
289
|
[:size, {:less_than => 10240}, "5k.png", "12k.png"],
|
300
290
|
[:size, {:greater_than => 8096}, "12k.png", "5k.png"],
|
301
291
|
[:content_type, {:content_type => "image/png"}, "5k.png", "text.txt"],
|
@@ -304,10 +294,10 @@ class PaperclipTest < Test::Unit::TestCase
|
|
304
294
|
validation, options, valid_file, invalid_file = args
|
305
295
|
valid_file &&= File.open(File.join(FIXTURES_DIR, valid_file), "rb")
|
306
296
|
invalid_file &&= File.open(File.join(FIXTURES_DIR, invalid_file), "rb")
|
307
|
-
|
297
|
+
|
308
298
|
should_validate validation, options, valid_file, invalid_file
|
309
299
|
end
|
310
|
-
|
300
|
+
|
311
301
|
context "with size validation and less_than 10240 option" do
|
312
302
|
context "and assigned an invalid file" do
|
313
303
|
setup do
|
@@ -316,9 +306,9 @@ class PaperclipTest < Test::Unit::TestCase
|
|
316
306
|
@dummy.avatar &&= File.open(File.join(FIXTURES_DIR, "12k.png"), "rb")
|
317
307
|
@dummy.valid?
|
318
308
|
end
|
319
|
-
|
309
|
+
|
320
310
|
should "have a file size min/max error message" do
|
321
|
-
|
311
|
+
assert @dummy.errors[:avatar_file_size] =~ %r/between 0 and 10240 bytes/
|
322
312
|
end
|
323
313
|
end
|
324
314
|
end
|