Commit b8c85cdf by Barry Hess Committed by Jon Yurek

Fix broken validates_attachment_size error message. The min and max values were…

Fix broken validates_attachment_size error message. The min and max values 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.
(cherry picked from commit 3fdb1160b272e71653d18d0b5945073e615c0a2d)
parent 98eff60d
......@@ -257,7 +257,9 @@ module Paperclip
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]}]
......
......@@ -307,6 +307,21 @@ class PaperclipTest < Test::Unit::TestCase
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
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