From b4f48164808845ece7d8c8843d5a191d2db1a7e5 Mon Sep 17 00:00:00 2001 From: railsbob Date: Sat, 8 Aug 2009 18:05:11 +0100 Subject: [PATCH] association_collection#create failing test case for has_many :through associations --- .../has_many_through_associations_test.rb | 13 ++++++++++++- activerecord/test/fixtures/markets.yml | 3 +++ activerecord/test/models/market.rb | 4 ++++ activerecord/test/models/product.rb | 4 ++++ activerecord/test/models/segment.rb | 4 ++++ activerecord/test/schema/schema.rb | 13 +++++++++++++ 6 files changed, 40 insertions(+), 1 deletions(-) create mode 100644 activerecord/test/fixtures/markets.yml create mode 100644 activerecord/test/models/market.rb create mode 100644 activerecord/test/models/product.rb create mode 100644 activerecord/test/models/segment.rb 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 8529ff0..775d8b2 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -11,9 +11,12 @@ require 'models/author' require 'models/owner' require 'models/pet' require 'models/toy' +require 'models/market' +require 'models/segment' +require 'models/product' class HasManyThroughAssociationsTest < ActiveRecord::TestCase - fixtures :posts, :readers, :people, :comments, :authors, :owners, :pets, :toys, :jobs, :references + fixtures :posts, :readers, :people, :comments, :authors, :owners, :pets, :toys, :jobs, :references, :markets def test_associate_existing assert_queries(2) { posts(:thinking);people(:david) } @@ -169,6 +172,14 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert_equal peeps + 1, posts(:thinking).people.count end + def test_associate_with_create_and_invalid_options + peeps = markets(:eshop).products.count + assert_nothing_raised do + product = markets(:eshop).products.create(:name => nil) + end + assert_equal peeps, markets(:eshop).products.count + end + def test_clear_associations assert_queries(2) { posts(:welcome);posts(:welcome).people(true) } diff --git a/activerecord/test/fixtures/markets.yml b/activerecord/test/fixtures/markets.yml new file mode 100644 index 0000000..2c86fd9 --- /dev/null +++ b/activerecord/test/fixtures/markets.yml @@ -0,0 +1,3 @@ +eshop: + id: 1 + name: "eBooks" diff --git a/activerecord/test/models/market.rb b/activerecord/test/models/market.rb new file mode 100644 index 0000000..e42bfbc --- /dev/null +++ b/activerecord/test/models/market.rb @@ -0,0 +1,4 @@ +class Market < ActiveRecord::Base + has_many :segments + has_many :products, :through => :segments +end \ No newline at end of file diff --git a/activerecord/test/models/product.rb b/activerecord/test/models/product.rb new file mode 100644 index 0000000..dea52db --- /dev/null +++ b/activerecord/test/models/product.rb @@ -0,0 +1,4 @@ +class Product < ActiveRecord::Base + has_many :segments + validates_presence_of :name +end \ No newline at end of file diff --git a/activerecord/test/models/segment.rb b/activerecord/test/models/segment.rb new file mode 100644 index 0000000..6985d55 --- /dev/null +++ b/activerecord/test/models/segment.rb @@ -0,0 +1,4 @@ +class Segment < ActiveRecord::Base + belongs_to :market + belongs_to :product +end \ No newline at end of file diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 5f60d5e..bd35ded 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -219,6 +219,10 @@ ActiveRecord::Schema.define do t.column :custom_lock_version, :integer end + create_table :markets, :force => true do |t| + t.string :name + end + create_table :mateys, :id => false, :force => true do |t| t.column :pirate_id, :integer t.column :target_id, :integer @@ -379,6 +383,10 @@ ActiveRecord::Schema.define do t.integer :price end + create_table :products, :force => true do |t| + t.string :name + end + create_table :projects, :force => true do |t| t.string :name t.string :type @@ -390,6 +398,11 @@ ActiveRecord::Schema.define do t.boolean :skimmer, :default => false end + create_table :segments, :force => true do |t| + t.integer :market_id + t.integer :product_id + end + create_table :shape_expressions, :force => true do |t| t.string :paint_type t.integer :paint_id -- 1.6.0.2