Object
@private
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 802 def autosave(autosave) @options[:autosave] = autosave self end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 807 def class_name(class_name) @options[:class_name] = class_name self end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 797 def conditions(conditions) @options[:conditions] = conditions self end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 778 def counter_cache(counter_cache = true) counter_cache_matcher = AssociationMatchers::CounterCacheMatcher.new(counter_cache, name) add_submatcher(counter_cache_matcher) self end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 766 def dependent(dependent) dependent_matcher = AssociationMatchers::DependentMatcher.new(dependent, name) add_submatcher(dependent_matcher) self end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 827 def description description = "#{macro_description} #{name}" description += " class_name => #{options[:class_name]}" if options.key?(:class_name) [description, submatchers.map(&:description)].flatten.join(' ') end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 833 def failure_message "Expected #{expectation} (#{missing_options})" end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 838 def failure_message_when_negated "Did not expect #{expectation}" end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 784 def inverse_of(inverse_of) inverse_of_matcher = AssociationMatchers::InverseOfMatcher.new(inverse_of, name) add_submatcher(inverse_of_matcher) self end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 843 def matches?(subject) @subject = subject association_exists? && macro_correct? && (polymorphic? || class_exists?) && foreign_key_exists? && class_name_correct? && autosave_correct? && conditions_correct? && join_table_exists? && validate_correct? && touch_correct? && submatchers_match? end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 772 def order(order) order_matcher = AssociationMatchers::OrderMatcher.new(order, name) add_submatcher(order_matcher) self end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 791 def source(source) source_matcher = AssociationMatchers::SourceMatcher.new(source, name) add_submatcher(source_matcher) self end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 760 def through(through) through_matcher = AssociationMatchers::ThroughMatcher.new(through, name) add_submatcher(through_matcher) self end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 822 def touch(touch = true) @options[:touch] = touch self end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 870 def add_submatcher(matcher) @submatchers << matcher end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 901 def association_exists? if reflection.nil? @missing = "no association called #{name}" false else true end end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 957 def autosave_correct? if options.key?(:autosave) if option_verifier.correct_for_boolean?(:autosave, options[:autosave]) true else @missing = "#{name} should have autosave set to #{options[:autosave]}" false end else true end end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 926 def belongs_foreign_key_missing? macro == :belongs_to && !class_has_foreign_key?(model_class) end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 949 def class_exists? associated_class true rescue NameError @missing = "#{reflection.class_name} does not exist" false end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 1011 def class_has_foreign_key?(klass) if options.key?(:foreign_key) option_verifier.correct_for_string?(:foreign_key, options[:foreign_key]) else if klass.column_names.include?(foreign_key) true else @missing = "#{klass} does not have a #{foreign_key} foreign key." false end end end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 936 def class_name_correct? if options.key?(:class_name) if option_verifier.correct_for_string?(:class_name, options[:class_name]) true else @missing = "#{name} should resolve to #{options[:class_name]} for class_name" false end else true end end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 970 def conditions_correct? if options.key?(:conditions) if option_verifier.correct_for_relation_clause?(:conditions, options[:conditions]) true else @missing = "#{name} should have the following conditions: #{options[:conditions]}" false end else true end end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 887 def expectation "#{model_class.name} to have a #{macro} association called #{name}" end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 895 def failing_submatchers @failing_submatchers ||= submatchers.reject do |matcher| matcher.matches?(subject) end end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 1024 def foreign_key if foreign_key_reflection if foreign_key_reflection.respond_to?(:foreign_key) foreign_key_reflection.foreign_key.to_s else foreign_key_reflection.primary_key_name.to_s end end end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 922 def foreign_key_exists? !(belongs_foreign_key_missing? || has_foreign_key_missing?) end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 1034 def foreign_key_reflection if [:has_one, :has_many].include?(macro) && reflection.options.include?(:inverse_of) associated_class.reflect_on_association(reflection.options[:inverse_of]) else reflection end end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 930 def has_foreign_key_missing? [:has_many, :has_one].include?(macro) && !through? && !class_has_foreign_key?(associated_class) end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 983 def join_table_exists? if macro != :has_and_belongs_to_many || model_class.connection.tables.include?(join_table) true else @missing = "join table #{join_table} doesn't exist" false end end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 910 def macro_correct? if reflection.macro == macro true elsif reflection.macro == :has_many macro == :has_and_belongs_to_many && reflection.name == @name else @missing = "actual association type was #{reflection.macro}" false end end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 874 def macro_description case macro.to_s when 'belongs_to' 'belong to' when 'has_many' 'have many' when 'has_one' 'have one' when 'has_and_belongs_to_many' 'have and belong to many' end end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 891 def missing_options [missing, failing_submatchers.map(&:missing_option)].flatten.join end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 866 def option_verifier @option_verifier ||= AssociationMatchers::OptionVerifier.new(reflector) end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 862 def reflector @reflector ||= AssociationMatchers::ModelReflector.new(subject, name) end
# File lib/shoulda/matchers/active_record/association_matcher.rb, line 1042 def submatchers_match? failing_submatchers.empty? end
Generated with the Darkfish Rdoc Generator 2.