From 83c1934003740ed01c618a8943457a0df53e2adb Mon Sep 17 00:00:00 2001 From: mattbauer Date: Sun, 21 Jun 2009 17:35:04 +0100 Subject: Ensure hm:t#create respects source associations hash conditions [#2090 state:resolved] Signed-off-by: Pratik Naik --- .../test/cases/associations/has_many_through_associations_test.rb | 6 ++++++ activerecord/test/models/post.rb | 2 ++ activerecord/test/schema/schema.rb | 1 + 3 files changed, 9 insertions(+) (limited to 'activerecord/test') 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 4254badef2..7a4712d7c8 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -157,6 +157,12 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert_equal peeps + 1, posts(:thinking).people.count end + def test_associate_with_create_with_through_having_conditions + impatient_people = posts(:thinking).impatient_people.count + posts(:thinking).impatient_people.create!(:first_name => 'foo') + assert_equal impatient_people + 1, posts(:thinking).impatient_people.count + end + def test_associate_with_create_exclamation_and_no_options peeps = posts(:thinking).people.count posts(:thinking).people.create!(:first_name => 'foo') diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 374e536a5b..7392515ec7 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -69,6 +69,8 @@ class Post < ActiveRecord::Base :after_add => lambda {|owner, reader| log(:added, :after, reader.first_name) }, :before_remove => lambda {|owner, reader| log(:removed, :before, reader.first_name) }, :after_remove => lambda {|owner, reader| log(:removed, :after, reader.first_name) } + has_many :skimmers, :class_name => 'Reader', :conditions => { :skimmer => true } + has_many :impatient_people, :through => :skimmers, :source => :person def self.top(limit) ranked_by_comments.limit(limit) diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index b2aaccb352..d2d6d1f4b3 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -364,6 +364,7 @@ ActiveRecord::Schema.define do create_table :readers, :force => true do |t| t.integer :post_id, :null => false t.integer :person_id, :null => false + t.boolean :skimmer, :default => false end create_table :shape_expressions, :force => true do |t| -- cgit v1.2.3