From 0e8c3b8dd974a19855f41cb319579567449461ed Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 5 Mar 2007 11:34:39 +0000 Subject: Fix has_many :through << with custom foreign keys. Closes #6466, #7153. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6336 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations/join_model_test.rb | 7 ++++++- activerecord/test/fixtures/vertex.rb | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/associations/join_model_test.rb b/activerecord/test/associations/join_model_test.rb index 1124a0ace0..1d2a4f6c5c 100644 --- a/activerecord/test/associations/join_model_test.rb +++ b/activerecord/test/associations/join_model_test.rb @@ -6,10 +6,12 @@ require 'fixtures/comment' require 'fixtures/author' require 'fixtures/category' require 'fixtures/categorization' +require 'fixtures/vertex' +require 'fixtures/edge' class AssociationsJoinModelTest < Test::Unit::TestCase self.use_transactional_fixtures = false - fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings, :author_favorites + fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings, :author_favorites, :vertices def test_has_many assert authors(:david).categories.include?(categories(:general)) @@ -414,6 +416,9 @@ class AssociationsJoinModelTest < Test::Unit::TestCase message = "Expected a Tagging in taggings collection, got #{wrong.class}.") assert_equal(count + 4, post_thinking.tags.size) assert_equal(count + 4, post_thinking.tags(true).size) + + # Raises if the wrong reflection name is used to set the Edge belongs_to + assert_nothing_raised { vertices(:vertex_1).sinks << vertices(:vertex_5) } end def test_adding_junk_to_has_many_through_should_raise_type_mismatch diff --git a/activerecord/test/fixtures/vertex.rb b/activerecord/test/fixtures/vertex.rb index f4c11144de..48bb851e62 100644 --- a/activerecord/test/fixtures/vertex.rb +++ b/activerecord/test/fixtures/vertex.rb @@ -1,7 +1,7 @@ # This class models a vertex in a directed graph. class Vertex < ActiveRecord::Base has_many :sink_edges, :class_name => 'Edge', :foreign_key => 'source_id' - has_many :sinks, :through => :sink_edges, :source => :sink + has_many :sinks, :through => :sink_edges has_and_belongs_to_many :sources, :class_name => 'Vertex', :join_table => 'edges', -- cgit v1.2.3