class Object
Public Instance Methods
actual_child_keys()
click to toggle source
# File lib/nested_validator/validate_nested_matcher.rb, line 106 def actual_child_keys child_attributes.map{|key| key.to_s.sub(/^.*\s+/, '').to_sym } end
child()
click to toggle source
# File lib/nested_validator/validate_nested_matcher.rb, line 62 def child parent.public_send(child_name) end
child_attributes_when_validity_is(valid)
click to toggle source
# File lib/nested_validator/validate_nested_matcher.rb, line 66 def child_attributes_when_validity_is(valid) errors_when_child_validity_is(valid).map{|k, msg| msg.split.first.to_sym} end
child_error_keys_when_validity_is(valid)
click to toggle source
# File lib/nested_validator/validate_nested_matcher.rb, line 70 def child_error_keys_when_validity_is(valid) errors_when_child_validity_is(valid).keys end
combine(*keys)
click to toggle source
# File lib/nested_validator/validate_nested_matcher.rb, line 166 def combine(*keys) keys.flatten.compact end
common_failure_message()
click to toggle source
# File lib/nested_validator/validate_nested_matcher.rb, line 157 def common_failure_message return "#{parent} doesn't respond to #{show child_name}" unless parent.respond_to?(child_name) "#{child_name} doesn't respond to #{show invalid_child_keys}" if invalid_child_keys.present? end
errors_when_child_validity_is(valid)
click to toggle source
# File lib/nested_validator/validate_nested_matcher.rb, line 74 def errors_when_child_validity_is(valid) child_error_keys = combine TEST_KEY, only_keys, except_keys, any_keys child_errors = child_error_keys.inject({}) { |result, key| result[key] = ['error message']; result } allow(child).to receive(:valid?) { valid } allow(child).to receive(:errors) { valid ? [] : child_errors } parent.valid? parent.errors end
expected_child_attributes()
click to toggle source
# File lib/nested_validator/validate_nested_matcher.rb, line 85 def expected_child_attributes expected_child_keys.map{|k| k.to_sym} end
expected_child_error_key()
click to toggle source
# File lib/nested_validator/validate_nested_matcher.rb, line 89 def expected_child_error_key prefix.present? ? prefix : child_name end
expected_child_keys()
click to toggle source
# File lib/nested_validator/validate_nested_matcher.rb, line 93 def expected_child_keys expected_keys = case when only_keys.present? only_keys when any_keys.present? any_keys else [TEST_KEY] end unique_except_keys = except_keys - only_keys - any_keys combine expected_keys - unique_except_keys end
invalid_child_keys()
click to toggle source
# File lib/nested_validator/validate_nested_matcher.rb, line 110 def invalid_child_keys (only_keys + except_keys).reject{|key| child.respond_to? key} end
prepare_keys(keys)
click to toggle source
# File lib/nested_validator/validate_nested_matcher.rb, line 49 def prepare_keys(keys) if keys.length == 1 && keys[0].is_a?(String) keys[0].split(/\s+|,/).reject(&:blank?) else keys end end
show(value)
click to toggle source
# File lib/nested_validator/validate_nested_matcher.rb, line 162 def show(value) Array.wrap(value).map{|key| key.is_a?(Symbol) ? ":#{key}" : key.to_s}.join(', ') end