class Shoulda::Matchers::ActiveModel::AllowValueMatcher
@private
Attributes
after_set_callback[R]
after_setting_value_callback[R]
args[R]
attribute_changed_value_message[W]
attribute_to_check_message_against[R]
attribute_to_set[R]
context[R]
failure_message_preface[W]
instance[R]
matcher_name[R]
object[R]
values_to_preset[W]
Public Instance Methods
attribute_changed_value?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 139 def attribute_changed_value? value_written != value_read end
check()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 55 def check if attribute_exists? @result_of_checking = successful_check true else @result_of_checking = attribute_does_not_exist_error false end end
checked?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 115 def checked? !result_of_checking.nil? end
description()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 34 def description description = ":#{attribute_name} to " description << Shoulda::Matchers::Util.inspect_value(value_written) if attribute_changed_value? description << " -- which was read back as " description << Shoulda::Matchers::Util.inspect_value(value_read) description << " --" end description end
failure_message()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 97 def failure_message if successful? raise "We're not supposed to be here!" elsif result_of_setting result_of_setting.message else result_of_checking.message end end
run()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 47 def run check && set end
run!()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 51 def run! check && set! end
set()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 82 def set object.public_send("#{attribute_name}=", value_written) after_set_callback.call @result_of_checking = successful_check if raise_attribute_changed_value_error? @result_of_setting = attribute_changed_value_error false else @result_of_setting = successful_setting true end end
set!()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 65 def set! if attribute_exists? set unless result_of_setting.successful? raise result_of_setting end @result_of_checking = successful_check @result_of_setting = successful_setting true else attribute_does_not_exist! end end
set?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 127 def set? !result_of_setting.nil? end
successful?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 107 def successful? successfully_checked? && successfully_set? end
successfully_checked?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 119 def successfully_checked? checked? && result_of_checking.successful? end
successfully_set?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 131 def successfully_set? set? && result_of_setting.successful? end
unsuccessful?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 111 def unsuccessful? !successful? end
unsuccessfully_checked?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 123 def unsuccessfully_checked? !successfully_checked? end
value_read()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 135 def value_read @_value_read ||= object.public_send(attribute_name) end
Private Instance Methods
active_resource_object?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 225 def active_resource_object? object.respond_to?(:known_attributes) end
attribute_changed_value!()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 200 def attribute_changed_value! raise attribute_changed_value_error end
attribute_changed_value_error()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 204 def attribute_changed_value_error AttributeChangedValueError.create( model: object.class, attribute_name: attribute_name, value_written: value_written, value_read: value_read ) end
attribute_does_not_exist!()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 213 def attribute_does_not_exist! raise attribute_does_not_exist_error end
attribute_does_not_exist_error()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 217 def attribute_does_not_exist_error AttributeDoesNotExistError.create( model: object.class, attribute_name: attribute_name, value: value_written ) end
attribute_exists?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 153 def attribute_exists? if active_resource_object? object.known_attributes.include?(attribute_name.to_s) else object.respond_to?("#{attribute_name}=") end end
attribute_is_an_enum?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 171 def attribute_is_an_enum? enum_values.any? end
defined_enums()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 184 def defined_enums if model.respond_to?(:defined_enums) model.defined_enums else {} end end
enum_values()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 180 def enum_values defined_enums.fetch(attribute_name.to_s, {}) end
ignore_interference_by_writer()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 161 def ignore_interference_by_writer @ignore_interference_by_writer end
model()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 149 def model object.class end
raise_attribute_changed_value_error?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 165 def raise_attribute_changed_value_error? attribute_changed_value? && !(attribute_is_an_enum? && value_read_is_expected_for_an_enum?) && !ignore_interference_by_writer.considering?(value_read) end
successful_check()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 192 def successful_check SuccessfulCheck.new end
successful_setting()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 196 def successful_setting SuccessfulSetting.new end
value_read_is_expected_for_an_enum?()
click to toggle source
# File lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb, line 175 def value_read_is_expected_for_an_enum? enum_values.key?(value_read) && enum_values[value_read] == value_written end