Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Revert commit 73723cd

* Causing issues with virtual attributes and error messages (#277)
* Will need to come up with another solution than adding a check for setting an
attribute correctly.
  • Loading branch information...
commit 9ffcf37b3adc47399fd7e06fba2bfafd317c720c 1 parent f96c8c7
Melissa Xie mxie authored
3  NEWS.md
View
@@ -1,5 +1,8 @@
# HEAD
+* Revert previous change in `AllowValueMatcher` that added a check for a
+properly-set attribute.
+
# v 1.5.5
* `AllowValueMatcher` checks that the right value is used for attempts at
setting the attribute with it
24 lib/shoulda/matchers/active_model/allow_value_matcher.rb
View
@@ -56,9 +56,10 @@ def strict
def matches?(instance)
self.instance = instance
- values_to_match.all? do |current_value|
- set_attribute_on_instance(current_value)
- matches_attribute_value?(current_value) && errors_do_not_match?
+ values_to_match.none? do |value|
+ self.value = value
+ instance.send("#{attribute}=", value)
+ errors_match?
end
end
@@ -79,21 +80,12 @@ def description
attr_accessor :values_to_match, :message_finder_factory,
:instance, :attribute, :value, :matched_error
- def set_attribute_on_instance(current_value)
- self.value = current_value
- instance.send("#{attribute}=", current_value)
+ def errors_match?
+ has_messages? && errors_for_attribute_match?
end
- def matches_attribute_value?(current_value)
- instance.send(attribute.to_sym) == current_value
- end
-
- def errors_do_not_match?
- has_no_messages? || !errors_for_attribute_match?
- end
-
- def has_no_messages?
- !message_finder.has_messages?
+ def has_messages?
+ message_finder.has_messages?
end
def errors_for_attribute_match?
11 spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb
View
@@ -79,13 +79,6 @@
end
context 'an attribute which must be included in an array' do
- context 'given an attribute that does not accept strings' do
- it 'allows an attribute to be set as an integer' do
- validating_inclusion(:in => [0,1,2], :column_type => :integer).
- should ensure_inclusion_of(:attr).in_array([0,1,2])
- end
- end
-
it 'accepts with correct array' do
validating_inclusion(:in => %w(one two)).
should ensure_inclusion_of(:attr).in_array(%w(one two))
@@ -172,9 +165,7 @@
end
def validating_inclusion(options)
- options[:column_type] ||= :string
-
- define_model(:example, :attr => options[:column_type]) do
+ define_model(:example, :attr => :string) do
validates_inclusion_of :attr, options
end.new
end
Please sign in to comment.
Something went wrong with that request. Please try again.