class AssociationAccessors::Test::Matcher
Attributes
association[R]
association_name[R]
attribute[R]
failure_message[R]
subject[R]
Public Class Methods
new(association_name)
click to toggle source
# File lib/association_accessors/test/matcher.rb, line 10 def initialize association_name @association_name = association_name end
Public Instance Methods
description()
click to toggle source
# File lib/association_accessors/test/matcher.rb, line 14 def description "have association accessor for #{association_name.inspect} with attribute #{attribute.inspect}." end
matches?(subject)
click to toggle source
# File lib/association_accessors/test/matcher.rb, line 18 def matches? subject @subject = subject @association = get_association check_attribute! has_accessors? end
with_attribute(attribute)
click to toggle source
# File lib/association_accessors/test/matcher.rb, line 27 def with_attribute attribute @attribute = attribute self end
Private Instance Methods
check_attribute!()
click to toggle source
# File lib/association_accessors/test/matcher.rb, line 39 def check_attribute! raise ArgumentError, "'with_attribute' is required" if attribute.nil? end
get_association()
click to toggle source
# File lib/association_accessors/test/matcher.rb, line 35 def get_association subject.association(association_name) end
has_accessors?()
click to toggle source
# File lib/association_accessors/test/matcher.rb, line 43 def has_accessors? accessor_name = if association.reflection.collection? :"#{association_name.to_s.singularize}_#{attribute.to_s.pluralize}" else :"#{association_name}_#{attribute}" end if subject.respond_to?(accessor_name) && subject.respond_to?(:"#{accessor_name}=") true else @failure_message = "reader and/or writer `#{accessor_name}` not defined on #{subject.class.name}." false end end