Skip to content

Instantly share code, notes, and snippets.

@jonleighton
Created May 13, 2011 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonleighton/971105 to your computer and use it in GitHub Desktop.
Save jonleighton/971105 to your computer and use it in GitHub Desktop.
From 42a20533837e925030b07132eaf0a2a6534ad235 Mon Sep 17 00:00:00 2001
From: Jon Leighton <j@jonathanleighton.com>
Date: Fri, 13 May 2011 20:03:57 +0100
Subject: [PATCH] Unfailing test case
---
.../has_many_through_associations_test.rb | 21 ++++++++++++++++++++
activerecord/test/schema/schema.rb | 11 ++++++++++
2 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 8911759..59ae365 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -25,6 +25,22 @@ require 'models/member'
require 'models/membership'
require 'models/club'
+class Question < ActiveRecord::Base
+ has_many :questions_has_sections
+ has_many :sections, :through => :questions_has_sections
+end
+
+# coding: utf-8
+class QuestionsHasSection < ActiveRecord::Base
+ belongs_to :question
+ belongs_to :section
+end
+
+class Section < ActiveRecord::Base
+ has_many :questions_has_sections
+ has_many :questions, :through => :questions_has_sections
+end
+
class HasManyThroughAssociationsTest < ActiveRecord::TestCase
fixtures :posts, :readers, :people, :comments, :authors, :categories, :taggings, :tags,
:owners, :pets, :toys, :jobs, :references, :companies, :members, :author_addresses,
@@ -766,4 +782,9 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_equal [category.name], post.named_category_ids # checks when target loaded
assert_equal [category.name], post.reload.named_category_ids # checks when target no loaded
end
+
+ def test_duplicate_hmt_joins
+ s = Section.create!
+ p s.questions
+ end
end
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index c8a98f1..6ce6353 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -25,6 +25,17 @@ ActiveRecord::Schema.define do
# #
# ------------------------------------------------------------------- #
+ create_table :questions, :force => true do |t|
+ end
+
+ create_table :questions_has_sections, :force => true do |t|
+ t.integer :question_id
+ t.integer :section_id
+ end
+
+ create_table :sections, :force => true do |t|
+ end
+
create_table :accounts, :force => true do |t|
t.integer :firm_id
t.string :firm_name
--
1.7.4.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment