Permalink
Browse files

Fix broken validates_attachment_size error message. The min and max v…

…alues were not being passed to attachment_definitions and thus were not available for :min and :max string replacement when the error message was built, leading to spaces rather than byte values for :min and :max.
  • Loading branch information...
1 parent e430afe commit 3fdb1160b272e71653d18d0b5945073e615c0a2d @bjhess bjhess committed Jul 28, 2009
Showing with 18 additions and 1 deletion.
  1. +3 −1 lib/paperclip.rb
  2. +15 −0 test/paperclip_test.rb
View
@@ -257,7 +257,9 @@ def validates_attachment_size name, options = {}
range = (min..max)
message = options[:message] || "file size must be between :min and :max bytes."
- attachment_definitions[name][:validations] << [:size, {:range => range,
+ attachment_definitions[name][:validations] << [:size, {:min => min,
+ :max => max,
+ :range => range,
:message => message,
:if => options[:if],
:unless => options[:unless]}]
View
@@ -286,6 +286,21 @@ def self.should_validate validation, options, valid_file, invalid_file
should_validate validation, options, valid_file, invalid_file
end
+
+ context "with size validation and less_than 10240 option" do
+ context "and assigned an invalid file" do
+ setup do
+ Dummy.send(:"validates_attachment_size", :avatar, :less_than => 10240)
+ @dummy = Dummy.new
+ @dummy.avatar &&= File.open(File.join(FIXTURES_DIR, "12k.png"), "rb")
+ @dummy.valid?
+ end
+
+ should "have a file size min/max error message" do
+ assert_match /between 0 and 10240 bytes/, @dummy.errors.on(:avatar)
+ end
+ end
+ end
end
end

0 comments on commit 3fdb116

Please sign in to comment.