Permalink
Browse files

WIP: conditional -> polymorphism

  • Loading branch information...
1 parent cc03053 commit cb46e2cd38fb21f4860c769d729e1a80f161345d @gabebw gabebw committed Sep 28, 2012
@@ -44,17 +44,26 @@ def matches?(subject)
super(subject)
if @range
- allows_lower_value &&
- disallows_minimum_value &&
- allows_higher_value &&
- disallows_maximum_value
+ exclusion_matcher.matches?
+ # allows_range?
elsif @array
disallows_all_values_in_array?
end
end
private
+ def allows_range?
+ allows_lower_value &&
+ disallows_minimum_value &&
+ allows_higher_value &&
+ disallows_maximum_value
+ end
+
+ def exclusion_matcher
+ @exclusion_matcher ||= RangeExclusionMatcher.new(@range)
+ end
+
def disallows_all_values_in_array?
@array.all? do |value|
disallows_value_of(value, expected_message)
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe Shoulda::Matchers::ActiveModel::RangeExclusionMatcher do
+ context '#matches?' do
+ it 'returns true when the range is correctly excluded'
+ it 'returns false when the validation disallows a higher value'
+ it 'returns false when the validation disallows a lower value'
+ end
+end
@@ -26,7 +26,6 @@
before do
@model = define_model(:example, :attr => :string) do
validates_exclusion_of :attr, :in => 2..4, :message => 'not good'
-
end.new
end

0 comments on commit cb46e2c

Please sign in to comment.