aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/cases/associations_test.rb24
-rw-r--r--activerecord/test/models/category.rb3
2 files changed, 27 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb
index 768d2b2600..8ae9e5630c 100755
--- a/activerecord/test/cases/associations_test.rb
+++ b/activerecord/test/cases/associations_test.rb
@@ -1075,6 +1075,18 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal 1, Client.find_all_by_client_of(firm.id).size
end
+ def test_creation_respects_hash_condition
+ ms_client = companies(:first_firm).clients_like_ms_with_hash_conditions.build
+
+ assert ms_client.save
+ assert_equal 'Microsoft', ms_client.name
+
+ another_ms_client = companies(:first_firm).clients_like_ms_with_hash_conditions.create
+
+ assert !another_ms_client.new_record?
+ assert_equal 'Microsoft', another_ms_client.name
+ end
+
def test_dependent_delete_and_destroy_with_belongs_to
author_address = author_addresses(:david_address)
assert_equal [], AuthorAddress.destroyed_author_address_ids[authors(:david).id]
@@ -1887,6 +1899,18 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
assert_equal Developer.find_by_name("Marcel").projects.last, proj2 # prove join table is updated
end
+ def test_creation_respects_hash_condition
+ post = categories(:general).post_with_conditions.build(:body => '')
+
+ assert post.save
+ assert_equal 'Yet Another Testing Title', post.title
+
+ another_post = categories(:general).post_with_conditions.create(:body => '')
+
+ assert !another_post.new_record?
+ assert_equal 'Yet Another Testing Title', another_post.title
+ end
+
def test_uniq_after_the_fact
developers(:jamis).projects << projects(:active_record)
developers(:jamis).projects << projects(:active_record)
diff --git a/activerecord/test/models/category.rb b/activerecord/test/models/category.rb
index 89d61b7e4e..f1d2e4805a 100644
--- a/activerecord/test/models/category.rb
+++ b/activerecord/test/models/category.rb
@@ -9,6 +9,9 @@ class Category < ActiveRecord::Base
:association_foreign_key => 'post_id',
:select => 'posts.*, 1 as correctness_marker')
+ has_and_belongs_to_many :post_with_conditions,
+ :class_name => 'Post',
+ :conditions => { :title => 'Yet Another Testing Title' }
def self.what_are_you
'a category...'
end