class Shoulda::Matchers::ActiveRecord::AssociationMatchers::ModelReflection
@private
Attributes
reflection[R]
subject[R]
Public Class Methods
new(reflection)
click to toggle source
Calls superclass method
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 9 def initialize(reflection) super(reflection) @reflection = reflection @subject = reflection.active_record end
Public Instance Methods
associated_class()
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 15 def associated_class reflection.klass end
association_relation()
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 34 def association_relation if reflection.respond_to?(:scope) convert_scope_to_relation(reflection.scope) else convert_options_to_relation(reflection.options) end end
join_table()
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 23 def join_table join_table = if reflection.respond_to?(:join_table) reflection.join_table else reflection.options[:join_table] end join_table.to_s end
through?()
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 19 def through? reflection.options[:through] end
Private Instance Methods
convert_options_to_relation(options)
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 57 def convert_options_to_relation(options) relation = associated_class.scoped relation = extend_relation_with(relation, :where, options[:conditions]) relation = extend_relation_with(relation, :includes, options[:include]) relation = extend_relation_with(relation, :order, options[:order]) relation = extend_relation_with(relation, :group, options[:group]) relation = extend_relation_with(relation, :having, options[:having]) relation = extend_relation_with(relation, :limit, options[:limit]) relation = extend_relation_with(relation, :offset, options[:offset]) relation = extend_relation_with(relation, :select, options[:select]) relation end
convert_scope_to_relation(scope)
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 46 def convert_scope_to_relation(scope) relation = associated_class.all if scope # Source: AR::Associations::AssociationScope#eval_scope relation.instance_exec(subject, &scope) else relation end end
extend_relation_with(relation, method_name, value)
click to toggle source
# File lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb, line 70 def extend_relation_with(relation, method_name, value) if value relation.__send__(method_name, value) else relation end end