Skip to content

Commit

Permalink
Fix broken validates_attachment_size error message. The min and max v…
Browse files Browse the repository at this point in the history
…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
bjhess committed Jul 28, 2009
1 parent e430afe commit 3fdb116
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/paperclip.rb
Expand Up @@ -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]}]
Expand Down
15 changes: 15 additions & 0 deletions test/paperclip_test.rb
Expand Up @@ -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.