From e5d9ad3e2903597e708fcb3ad76f08b4a600d82d Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 13 Dec 2005 00:39:51 +0000 Subject: Added option inheritance for find calls on has_and_belongs_to_many and has_many assosociations [DHH] Added option to specify :group, :limit, :offset, and :select options from find on has_and_belongs_to_many and has_many assosociations [DHH] Added form_remote_for (form_for meets form_remote_tag) [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3287 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations_test.rb | 12 +++++++++++- activerecord/test/fixtures/company.rb | 1 + activerecord/test/fixtures/project.rb | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'activerecord/test') diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 735f012afe..e088432da8 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -281,6 +281,12 @@ class HasManyAssociationsTest < Test::Unit::TestCase assert_equal 2, Firm.find(:first).clients.length end + def test_find_many_with_merged_options + assert_equal 1, companies(:first_firm).limited_clients.size + assert_equal 1, companies(:first_firm).limited_clients.find(:all).size + assert_equal 2, companies(:first_firm).limited_clients.find(:all, :limit => nil).size + end + def test_triple_equality assert !(Array === Firm.find(:first).clients) assert Firm.find(:first).clients === Array @@ -670,7 +676,6 @@ class HasManyAssociationsTest < Test::Unit::TestCase assert_equal num_accounts - 1, Account.count end - def test_depends_and_nullify num_accounts = Account.count num_companies = Company.count @@ -1342,6 +1347,11 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase assert_equal developers(:david), projects(:active_record).developers_with_finder_sql.find(developers(:david).id.to_s), "SQL find" end + def test_find_with_merged_options + assert_equal 1, projects(:active_record).limited_developers.size + assert_equal 1, projects(:active_record).limited_developers.find(:all).size + assert_equal 2, projects(:active_record).limited_developers.find(:all, :limit => nil).size + end def test_new_with_values_in_collection jamis = DeveloperForProjectWithAfterCreateHook.find_by_name('Jamis') diff --git a/activerecord/test/fixtures/company.rb b/activerecord/test/fixtures/company.rb index 6d33d4e1a8..d4a68900fe 100755 --- a/activerecord/test/fixtures/company.rb +++ b/activerecord/test/fixtures/company.rb @@ -14,6 +14,7 @@ class Firm < Company has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id" has_many :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => true has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :exclusively_dependent => true + has_many :limited_clients, :class_name => "Client", :order => "id", :limit => 1 has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id" has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}' has_many :clients_using_counter_sql, :class_name => "Client", diff --git a/activerecord/test/fixtures/project.rb b/activerecord/test/fixtures/project.rb index f8519f1b8c..c1aa4145f9 100644 --- a/activerecord/test/fixtures/project.rb +++ b/activerecord/test/fixtures/project.rb @@ -1,5 +1,6 @@ class Project < ActiveRecord::Base has_and_belongs_to_many :developers, :uniq => true + has_and_belongs_to_many :limited_developers, :class_name => "Developer", :limit => 1 has_and_belongs_to_many :developers_named_david, :class_name => "Developer", :conditions => "name = 'David'", :uniq => true has_and_belongs_to_many :salaried_developers, :class_name => "Developer", :conditions => "salary > 0" has_and_belongs_to_many :developers_with_finder_sql, :class_name => "Developer", :finder_sql => 'SELECT t.*, j.* FROM developers_projects j, developers t WHERE t.id = j.developer_id AND j.project_id = #{id}' -- cgit v1.2.3