Commit be890c98 by austin.bain

Validating size and content_type no longer throws errors when no file is uploaded

parent 3d745db9
...@@ -156,7 +156,7 @@ module Paperclip ...@@ -156,7 +156,7 @@ module Paperclip
unless options[:less_than].nil? unless options[:less_than].nil?
options[:in] = (0..options[:less_than]) options[:in] = (0..options[:less_than])
end end
unless options[:in].include? instance[:"#{name}_file_size"].to_i unless attachment.original_filename.blank? || options[:in].include?(instance[:"#{name}_file_size"].to_i)
min = options[:in].first min = options[:in].first
max = options[:in].last max = options[:in].last
...@@ -187,7 +187,7 @@ module Paperclip ...@@ -187,7 +187,7 @@ module Paperclip
options[:content_type] = [options[:content_type]].flatten.collect! { |t| t == :image ? Paperclip.content_types : t }.flatten unless options[:content_type].nil? options[:content_type] = [options[:content_type]].flatten.collect! { |t| t == :image ? Paperclip.content_types : t }.flatten unless options[:content_type].nil?
unless options[:content_type].empty? unless options[:content_type].empty?
unless options[:content_type].include?(instance[:"#{name}_content_type"]) unless attachment.original_filename.blank? || options[:content_type].include?(instance[:"#{name}_content_type"])
options[:message] || ActiveRecord::Errors.default_error_messages[:inclusion] options[:message] || ActiveRecord::Errors.default_error_messages[:inclusion]
end end
end end
......
...@@ -71,7 +71,9 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -71,7 +71,9 @@ class PaperclipTest < Test::Unit::TestCase
[:content_type3, {:content_type => "text/plain"}, "text.txt", "5k.png"], [:content_type3, {:content_type => "text/plain"}, "text.txt", "5k.png"],
[:presence2, {:message => "error"}, "5k.png", nil, "error"], [:presence2, {:message => "error"}, "5k.png", nil, "error"],
[:size2, {:in => 1..10240, :message => 'size is not between #{min} and #{max} bytes.'}, "5k.png", "12k.png", "size is not between 1 and 10240 bytes."], [:size2, {:in => 1..10240, :message => 'size is not between #{min} and #{max} bytes.'}, "5k.png", "12k.png", "size is not between 1 and 10240 bytes."],
[:content_type4,{:content_type => "image/png", :message => "error"}, "5k.png", "text.txt", "error"]].each do |args| [:size3, {:in => 1..10240}, nil, "12k.png"],
[:content_type4,{:content_type => "image/png", :message => "error"}, "5k.png", "text.txt", "error"],
[:content_type5,{:content_type => "image/png"}, nil, "text.txt"]].each do |args|
context "with #{args[0]} validations" do context "with #{args[0]} validations" do
setup do setup do
Dummy.class_eval do Dummy.class_eval do
......
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