Commit e8518e0e by Jon Yurek

New shoulda macros that are actually useful

parent e8f45902
...@@ -8,20 +8,60 @@ module Paperclip ...@@ -8,20 +8,60 @@ module Paperclip
assert klass.instance_methods.include?(meth), "#{klass.name} does not respond to #{name}." assert klass.instance_methods.include?(meth), "#{klass.name} does not respond to #{name}."
end end
end end
end
end
should "have the correct definition" do def should_validate_attachment_size name, options = {}
expected = options klass = self.name.gsub(/Test$/, '').constantize
actual = klass.attachment_definitions[name] min = options[:greater_than] || (options[:in] && options[:in].first) || 0
expected.delete(:validations) if not options.key?(:validations) max = options[:less_than] || (options[:in] && options[:in].last) || (1.0/0)
expected.delete(:whiny_thumbnails) if not options.key?(:whiny_thumbnails) range = (min..max)
context "Class #{klass.name} with attachment #{name}" do
context "with an attachment that is #{max+1} bytes" do
setup do
@file = StringIO.new("." * (max+1))
@attachment = klass.new.send(name)
@attachment.assign(@file)
end
assert_equal expected, actual should "have a :size validation error" do
assert @attachment.errors[:size]
end
end
context "with an attachment that us #{max-1} bytes" do
setup do
@file = StringIO.new("." * (max-1))
@attachment = klass.new.send(name)
@attachment.assign(@file)
end end
should "ensure that ImageMagick is available" do should "not have a :size validation error" do
%w( convert identify ).each do |command| assert ! @attachment.errors[:size]
`#{Paperclip.path_for_command(command)}` end
assert_equal 0, $?, "ImageMagick's #{command} returned with an error. Make sure that #{command} is available at #{Paperclip.path_for_command(command)}" end
if min > 0
context "with an attachment that is #{min-1} bytes" do
setup do
@file = StringIO.new("." * (min-1))
@attachment = klass.new.send(name)
@attachment.assign(@file)
end
should "have a :size validation error" do
assert @attachment.errors[:size]
end
end
context "with an attachment that us #{min+1} bytes" do
setup do
@file = StringIO.new("." * (min+1))
@attachment = klass.new.send(name)
@attachment.assign(@file)
end
should "not have a :size validation error" do
assert ! @attachment.errors[:size]
end
end end
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment