0
assert_equal %w(1 2), projects.scan(/\d/).sort
0
+class OverridingAssociationsTest < Test::Unit::TestCase
0
+ class Person < ActiveRecord::Base; end
0
+ class DifferentPerson < ActiveRecord::Base; end
0
+ class PeopleList < ActiveRecord::Base
0
+ has_and_belongs_to_many :has_and_belongs_to_many, :before_add => :enlist
0
+ has_many :has_many, :before_add => :enlist
0
+ belongs_to :belongs_to
0
+ class DifferentPeopleList < PeopleList
0
+ # Different association with the same name, callbacks should be omitted here.
0
+ has_and_belongs_to_many :has_and_belongs_to_many, :class_name => 'DifferentPerson'
0
+ has_many :has_many, :class_name => 'DifferentPerson'
0
+ belongs_to :belongs_to, :class_name => 'DifferentPerson', :foreign_key => 'belongs_to_id'
0
+ has_one :has_one, :class_name => 'DifferentPerson'
0
+ def test_habtm_association_redefinition_callbacks_should_differ_and_not_inherited
0
+ # redeclared association on AR descendant should not inherit callbacks from superclass
0
+ callbacks = PeopleList.read_inheritable_attribute(:before_add_for_has_and_belongs_to_many)
0
+ assert_equal([:enlist], callbacks)
0
+ callbacks = DifferentPeopleList.read_inheritable_attribute(:before_add_for_has_and_belongs_to_many)
0
+ assert_equal([], callbacks)
0
+ def test_has_many_association_redefinition_callbacks_should_differ_and_not_inherited
0
+ # redeclared association on AR descendant should not inherit callbacks from superclass
0
+ callbacks = PeopleList.read_inheritable_attribute(:before_add_for_has_many)
0
+ assert_equal([:enlist], callbacks)
0
+ callbacks = DifferentPeopleList.read_inheritable_attribute(:before_add_for_has_many)
0
+ assert_equal([], callbacks)
0
+ def test_habtm_association_redefinition_reflections_should_differ_and_not_inherited
0
+ PeopleList.reflect_on_association(:has_and_belongs_to_many),
0
+ DifferentPeopleList.reflect_on_association(:has_and_belongs_to_many)
0
+ def test_has_many_association_redefinition_reflections_should_differ_and_not_inherited
0
+ PeopleList.reflect_on_association(:has_many),
0
+ DifferentPeopleList.reflect_on_association(:has_many)
0
+ def test_belongs_to_association_redefinition_reflections_should_differ_and_not_inherited
0
+ PeopleList.reflect_on_association(:belongs_to),
0
+ DifferentPeopleList.reflect_on_association(:belongs_to)
0
+ def test_has_one_association_redefinition_reflections_should_differ_and_not_inherited
0
+ PeopleList.reflect_on_association(:has_one),
0
+ DifferentPeopleList.reflect_on_association(:has_one)
Comments
No one has commented yet.