Commit 0f4be8ac by Jon Yurek

Fixed issue with size validations and the removal of size column requirements.

parent c72812fb
......@@ -181,7 +181,7 @@ module Paperclip
message = options[:message] || "file size must be between :min and :max bytes."
attachment_definitions[name][:validations][:size] = lambda do |attachment, instance|
if attachment.file? && !range.include?(attachment.instance_read(:file_size).to_i)
if attachment.file? && !range.include?(attachment.size.to_i)
message.gsub(/:min/, min.to_s).gsub(/:max/, max.to_s)
end
end
......
......@@ -152,6 +152,10 @@ module Paperclip
instance_read(:file_name)
end
def size
instance_read(:file_size) || (@queued_for_write[:original] && @queued_for_write[:original].size)
end
def content_type
instance_read(:content_type)
end
......
......@@ -387,6 +387,11 @@ class AttachmentTest < Test::Unit::TestCase
assert_nil @dummy.avatar.updated_at
end
should "return the right value when sent #avatar_file_size" do
@dummy.avatar = @file
assert_equal @file.size, @dummy.avatar.size
end
context "and avatar_updated_at column" do
setup do
ActiveRecord::Base.connection.add_column :dummies, :avatar_updated_at, :timestamp
......@@ -423,5 +428,28 @@ class AttachmentTest < Test::Unit::TestCase
end
end
context "and avatar_file_size column" do
setup do
ActiveRecord::Base.connection.add_column :dummies, :avatar_file_size, :integer
rebuild_class
@dummy = Dummy.new
end
should "not error when assigned an attachment" do
assert_nothing_raised { @dummy.avatar = @file }
end
should "return the right value when sent #avatar_file_size" do
@dummy.avatar = @file
assert_equal @file.size, @dummy.avatar.size
end
should "return the right value when saved, reloaded, and sent #avatar_file_size" do
@dummy.avatar = @file
@dummy.save
@dummy = Dummy.find(@dummy.id)
assert_equal @file.size, @dummy.avatar.size
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