Commit d3a74275 by Prem Sichanugrist

Fix some errors on shoulda's matchers

parent da5d716b
...@@ -39,14 +39,14 @@ module Paperclip ...@@ -39,14 +39,14 @@ module Paperclip
def error_when_not_valid? def error_when_not_valid?
@subject.send(@attachment_name).assign(nil) @subject.send(@attachment_name).assign(nil)
@subject.valid? @subject.valid?
not @subject.errors[:"#{@attachment_name}_file_name"].blank? @subject.errors[:"#{@attachment_name}"].present?
end end
def no_error_when_valid? def no_error_when_valid?
@file = StringIO.new(".") @file = StringIO.new(".")
@subject.send(@attachment_name).assign(@file) @subject.send(@attachment_name).assign(@file)
@subject.valid? @subject.valid?
@subject.errors[:"#{@attachment_name}_file_name"].blank? @subject.errors[:"#{@attachment_name}"].blank?
end end
end end
end end
......
...@@ -18,7 +18,6 @@ module Paperclip ...@@ -18,7 +18,6 @@ module Paperclip
class ValidateAttachmentSizeMatcher class ValidateAttachmentSizeMatcher
def initialize attachment_name def initialize attachment_name
@attachment_name = attachment_name @attachment_name = attachment_name
@low, @high = 0, (1.0/0)
end end
def less_than size def less_than size
...@@ -76,21 +75,19 @@ module Paperclip ...@@ -76,21 +75,19 @@ module Paperclip
end end
def lower_than_low? def lower_than_low?
not passes_validation_with_size(@low - 1) @low.nil? || !passes_validation_with_size(@low - 1)
end end
def higher_than_low? def higher_than_low?
passes_validation_with_size(@low + 1) @low.nil? || passes_validation_with_size(@low + 1)
end end
def lower_than_high? def lower_than_high?
return true if @high == (1.0/0) @high.nil? || @high == Float::INFINITY || passes_validation_with_size(@high - 1)
passes_validation_with_size(@high - 1)
end end
def higher_than_high? def higher_than_high?
return true if @high == (1.0/0) @high.nil? || @high == Float::INFINITY || !passes_validation_with_size(@high + 1)
not passes_validation_with_size(@high + 1)
end 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