Skip to content
This repository
Browse code

Fix some errors on shoulda's matchers

  • Loading branch information...
commit d3a742755e3b0ffefcd73abe68fb193fd7cdd143 1 parent da5d716
Prem Sichanugrist authored March 16, 2012
4  lib/paperclip/matchers/validate_attachment_presence_matcher.rb
@@ -39,14 +39,14 @@ def description
39 39
         def error_when_not_valid?
40 40
           @subject.send(@attachment_name).assign(nil)
41 41
           @subject.valid?
42  
-          not @subject.errors[:"#{@attachment_name}_file_name"].blank?
  42
+          @subject.errors[:"#{@attachment_name}"].present?
43 43
         end
44 44
 
45 45
         def no_error_when_valid?
46 46
           @file = StringIO.new(".")
47 47
           @subject.send(@attachment_name).assign(@file)
48 48
           @subject.valid?
49  
-          @subject.errors[:"#{@attachment_name}_file_name"].blank?
  49
+          @subject.errors[:"#{@attachment_name}"].blank?
50 50
         end
51 51
       end
52 52
     end
11  lib/paperclip/matchers/validate_attachment_size_matcher.rb
@@ -18,7 +18,6 @@ def validate_attachment_size name
18 18
       class ValidateAttachmentSizeMatcher
19 19
         def initialize attachment_name
20 20
           @attachment_name = attachment_name
21  
-          @low, @high = 0, (1.0/0)
22 21
         end
23 22
 
24 23
         def less_than size
@@ -76,21 +75,19 @@ def passes_validation_with_size(new_size)
76 75
         end
77 76
 
78 77
         def lower_than_low?
79  
-          not passes_validation_with_size(@low - 1)
  78
+          @low.nil? || !passes_validation_with_size(@low - 1)
80 79
         end
81 80
 
82 81
         def higher_than_low?
83  
-          passes_validation_with_size(@low + 1)
  82
+          @low.nil? || passes_validation_with_size(@low + 1)
84 83
         end
85 84
 
86 85
         def lower_than_high?
87  
-          return true if @high == (1.0/0)
88  
-          passes_validation_with_size(@high - 1)
  86
+          @high.nil? || @high == Float::INFINITY || passes_validation_with_size(@high - 1)
89 87
         end
90 88
 
91 89
         def higher_than_high?
92  
-          return true if @high == (1.0/0)
93  
-          not passes_validation_with_size(@high + 1)
  90
+          @high.nil? || @high == Float::INFINITY || !passes_validation_with_size(@high + 1)
94 91
         end
95 92
       end
96 93
     end

0 notes on commit d3a7427

Please sign in to comment.
Something went wrong with that request. Please try again.