mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
Revert commit 73723cdbc8
* 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.
This commit is contained in:
parent
f96c8c7606
commit
9ffcf37b3a
3 changed files with 12 additions and 26 deletions
3
NEWS.md
3
NEWS.md
|
@ -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
|
||||
|
|
|
@ -56,9 +56,10 @@ module Shoulda # :nodoc:
|
|||
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 @@ module Shoulda # :nodoc:
|
|||
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?
|
||||
|
|
|
@ -79,13 +79,6 @@ describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
|
|||
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 @@ describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
|
|||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue