Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix some errors on shoulda's matchers
  • Loading branch information
sikachu committed Mar 23, 2012
1 parent da5d716 commit d3a7427
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Expand Up @@ -39,14 +39,14 @@ def description
def error_when_not_valid?
@subject.send(@attachment_name).assign(nil)
@subject.valid?
not @subject.errors[:"#{@attachment_name}_file_name"].blank?
@subject.errors[:"#{@attachment_name}"].present?
end

def no_error_when_valid?
@file = StringIO.new(".")
@subject.send(@attachment_name).assign(@file)
@subject.valid?
@subject.errors[:"#{@attachment_name}_file_name"].blank?
@subject.errors[:"#{@attachment_name}"].blank?
end
end
end
Expand Down
11 changes: 4 additions & 7 deletions lib/paperclip/matchers/validate_attachment_size_matcher.rb
Expand Up @@ -18,7 +18,6 @@ def validate_attachment_size name
class ValidateAttachmentSizeMatcher
def initialize attachment_name
@attachment_name = attachment_name
@low, @high = 0, (1.0/0)
end

def less_than size
Expand Down Expand Up @@ -76,21 +75,19 @@ def passes_validation_with_size(new_size)
end

def lower_than_low?
not passes_validation_with_size(@low - 1)
@low.nil? || !passes_validation_with_size(@low - 1)
end

def higher_than_low?
passes_validation_with_size(@low + 1)
@low.nil? || passes_validation_with_size(@low + 1)
end

def lower_than_high?
return true if @high == (1.0/0)
passes_validation_with_size(@high - 1)
@high.nil? || @high == Float::INFINITY || passes_validation_with_size(@high - 1)
end

def higher_than_high?
return true if @high == (1.0/0)
not passes_validation_with_size(@high + 1)
@high.nil? || @high == Float::INFINITY || !passes_validation_with_size(@high + 1)
end
end
end
Expand Down

0 comments on commit d3a7427

Please sign in to comment.