From d6f7b7d35337b87cc1c419e47fae52bbfc3f371e Mon Sep 17 00:00:00 2001 From: Tim Connor Date: Mon, 27 Sep 2010 11:56:18 +1300 Subject: Fix remove_index issue when provided :name is a symbol Signed-off-by: Santiago Pastorino --- activerecord/test/cases/migration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index bcae46c7e8..8c75500998 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -91,7 +91,7 @@ if ActiveRecord::Base.connection.supports_migrations? # Oracle adapter is shortening index name when just column list is given unless current_adapter?(:OracleAdapter) assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) } - assert_nothing_raised { Person.connection.remove_index("people", :name => "index_people_on_last_name_and_first_name") } + assert_nothing_raised { Person.connection.remove_index("people", :name => :index_people_on_last_name_and_first_name) } assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"]) } assert_nothing_raised { Person.connection.remove_index("people", "last_name_and_first_name") } end -- cgit v1.2.3 From e1b51955f15e91f3f1705612fd0aca82a257e2f4 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 27 Sep 2010 11:32:22 -0700 Subject: adding a test for slug behavior --- activerecord/test/cases/base_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index d87f259f4b..b434b0faa8 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -366,6 +366,10 @@ class BasicsTest < ActiveRecord::TestCase assert_equal Topic.find(1), Topic.find(2).topic end + def test_find_by_slug + assert_equal Topic.find('1-meowmeow'), Topic.find(1) + end + def test_equality_of_new_records assert_not_equal Topic.new, Topic.new end -- cgit v1.2.3 From 7f743233c4e276d1799451478e6718589d270cbd Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sun, 26 Sep 2010 00:35:39 -0400 Subject: Fix for nested_attributes with has_many association fails when a single record is being updated. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#5705 state:resolved] Signed-off-by: José Valim --- activerecord/test/cases/nested_attributes_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 62e073ba8c..75ffd31de3 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -123,6 +123,14 @@ class TestNestedAttributesInGeneral < ActiveRecord::TestCase assert_equal 's1', ship.reload.name end + def test_has_many_association_updating_a_single_record + Man.accepts_nested_attributes_for(:interests) + man = Man.create(:name => 'John') + interest = man.interests.create(:topic => 'photography') + man.update_attributes({:interests_attributes => {:topic => 'gardening', :id => interest.id}}) + assert_equal 'gardening', interest.reload.topic + end + end class TestNestedAttributesOnAHasOneAssociation < ActiveRecord::TestCase -- cgit v1.2.3 From 4966b915fe96db73933d33176c1ea5cc53e58a22 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sun, 26 Sep 2010 00:54:44 -0400 Subject: Fix for #5579 involved the code change for both has_one and has_many relationships. The path included test only for has_one. This patch adds test for has_many relationship. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#5706 state:resolved] Signed-off-by: José Valim --- activerecord/test/cases/nested_attributes_test.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 75ffd31de3..54429bf80b 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -115,7 +115,7 @@ class TestNestedAttributesInGeneral < ActiveRecord::TestCase assert_difference('Ship.count') { pirate.save! } end - def test_reject_if_with_a_proc_which_returns_true_always + def test_reject_if_with_a_proc_which_returns_true_always_for_has_one Pirate.accepts_nested_attributes_for :ship, :reject_if => proc {|attributes| true } pirate = Pirate.new(:catchphrase => "Stop wastin' me time") ship = pirate.create_ship(:name => 's1') @@ -123,6 +123,14 @@ class TestNestedAttributesInGeneral < ActiveRecord::TestCase assert_equal 's1', ship.reload.name end + def test_reject_if_with_a_proc_which_returns_true_always_for_has_many + Man.accepts_nested_attributes_for :interests, :reject_if => proc {|attributes| true } + man = Man.create(:name => "John") + interest = man.interests.create(:topic => 'photography') + man.update_attributes({:interests_attributes => { :topic => 'gardening', :id => interest.id } }) + assert_equal 'photography', interest.reload.topic + end + def test_has_many_association_updating_a_single_record Man.accepts_nested_attributes_for(:interests) man = Man.create(:name => 'John') -- cgit v1.2.3 From f22b40a8f223e0b2f5194b6f3ce24cafd5cd3a05 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 27 Sep 2010 14:29:00 -0700 Subject: make sure we use the engine assigned to the table when quoting --- activerecord/test/cases/base_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index b434b0faa8..16fd9a7465 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -69,6 +69,24 @@ class BasicsTest < ActiveRecord::TestCase end end + def test_use_table_engine_for_quoting_where + relation = Topic.where(Topic.arel_table[:id].eq(1)) + engine = relation.table.engine + + fakepool = Class.new(Struct.new(:spec)) { + def with_connection; yield self; end + def connection_pool; self; end + def quote_table_name(*args); raise "lol quote_table_name"; end + } + + relation.table.engine = fakepool.new(engine.connection_pool.spec) + + error = assert_raises(RuntimeError) { relation.to_a } + assert_match('lol', error.message) + ensure + relation.table.engine = engine + end + def test_preserving_time_objects assert_kind_of( Time, Topic.find(1).bonus_time, -- cgit v1.2.3 From 133742d185c2abf0fb443b694a305a4b68259bcb Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 27 Sep 2010 16:51:12 -0700 Subject: @klass also uses DynamicFinderMatch, so no need for it on the relation --- activerecord/test/cases/relations_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 3bc3671b77..d642aeed8b 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -32,6 +32,11 @@ class RelationTest < ActiveRecord::TestCase assert_equal 5, Post.where(:id => post_authors).size end + def test_dynamic_finder + x = Post.where('author_id = ?', 1) + assert x.klass.respond_to?(:find_by_id), '@klass should handle dynamic finders' + end + def test_multivalue_where posts = Post.where('author_id = ? AND id = ?', 1, 1) assert_equal 1, posts.to_a.size -- cgit v1.2.3 From 526ade1ff63ba1fcb32250841b29c95ae4cb9de9 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 27 Sep 2010 17:59:28 -0700 Subject: adding test cases for the dynamic finder matcher match method --- .../test/cases/dynamic_finder_match_test.rb | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 activerecord/test/cases/dynamic_finder_match_test.rb (limited to 'activerecord/test') diff --git a/activerecord/test/cases/dynamic_finder_match_test.rb b/activerecord/test/cases/dynamic_finder_match_test.rb new file mode 100644 index 0000000000..64bf6cb508 --- /dev/null +++ b/activerecord/test/cases/dynamic_finder_match_test.rb @@ -0,0 +1,49 @@ +require "cases/helper" + +module ActiveRecord + class DynamicFinderMatchTest < ActiveRecord::TestCase + def test_find_by + m = DynamicFinderMatch.match(:find_by_foo) + assert_equal :first, m.finder + assert_equal %w{ foo }, m.attribute_names + end + + def test_find_all_by + m = DynamicFinderMatch.match(:find_all_by_foo) + assert_equal :all, m.finder + assert_equal %w{ foo }, m.attribute_names + end + + def test_find_last_by + m = DynamicFinderMatch.match(:find_last_by_foo) + assert_equal :last, m.finder + assert_equal %w{ foo }, m.attribute_names + end + + def test_find_by! + m = DynamicFinderMatch.match(:find_by_foo!) + assert_equal :first, m.finder + assert m.bang?, 'should be banging' + assert_equal %w{ foo }, m.attribute_names + end + + def test_find_or_create + m = DynamicFinderMatch.match(:find_or_create_by_foo) + assert_equal :first, m.finder + assert_equal %w{ foo }, m.attribute_names + assert_equal :create, m.instantiator + end + + def test_find_or_initialize + m = DynamicFinderMatch.match(:find_or_initialize_by_foo) + assert_equal :first, m.finder + assert_equal %w{ foo }, m.attribute_names + assert_equal :new, m.instantiator + end + + def test_garbage + assert !DynamicFinderMatch.match(:fooo), 'should be false' + assert !DynamicFinderMatch.match(:find_by), 'should be false' + end + end +end -- cgit v1.2.3 From bee447a5b9fe1d683c6cc69aefb7fc22c2a9d9af Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 28 Sep 2010 10:02:03 -0700 Subject: porting 515917f5d8678af6c57842ca5dfd7c18e67ff1fe to master --- activerecord/test/cases/associations/eager_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 40859d425f..4a2c8bab5b 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -357,6 +357,12 @@ class EagerAssociationTest < ActiveRecord::TestCase end end + def test_eager_with_has_many_through_association_with_order + author_comments = Author.find(authors(:david).id).comments_desc + eager_author_comments = Author.find(authors(:david).id, :include => :comments_desc).comments_desc + assert_equal eager_author_comments, author_comments + end + def test_eager_with_has_many_through_with_conditions_join_model_with_include post_tags = Post.find(posts(:welcome).id).misc_tags eager_post_tags = Post.find(1, :include => :misc_tags).misc_tags -- cgit v1.2.3 From 8b8730e1390963a8bb3a231ed1a324862d3dc4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Mon, 27 Sep 2010 20:59:45 +0200 Subject: Test add_index and remove_index with a symbol name #4891 --- activerecord/test/cases/migration_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 8c75500998..5242d78033 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -124,6 +124,13 @@ if ActiveRecord::Base.connection.supports_migrations? end end + def test_index_symbol_names + assert_nothing_raised { Person.connection.add_index :people, :primary_contact_id, :name => :symbol_index_name } + assert Person.connection.index_exists?(:people, :primary_contact_id, :name => :symbol_index_name) + assert_nothing_raised { Person.connection.remove_index :people, :name => :symbol_index_name } + assert !Person.connection.index_exists?(:people, :primary_contact_id, :name => :symbol_index_name) + end + def test_add_index_length_limit good_index_name = 'x' * Person.connection.index_name_length too_long_index_name = good_index_name + 'x' -- cgit v1.2.3 From 75e52df0e8b6a229a696a28423f1a40c9837ba76 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 28 Sep 2010 10:26:32 -0700 Subject: fixing indentation warning --- activerecord/test/cases/nested_attributes_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 54429bf80b..8382ca048b 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -131,7 +131,7 @@ class TestNestedAttributesInGeneral < ActiveRecord::TestCase assert_equal 'photography', interest.reload.topic end - def test_has_many_association_updating_a_single_record + def test_has_many_association_updating_a_single_record Man.accepts_nested_attributes_for(:interests) man = Man.create(:name => 'John') interest = man.interests.create(:topic => 'photography') -- cgit v1.2.3 From cdfd013dd7953fc87038c73ecddbaa8cfe29a301 Mon Sep 17 00:00:00 2001 From: Marcelo Giorgi Date: Wed, 15 Sep 2010 12:26:54 -0300 Subject: Set attributes properly for model built from association with conditions [#5562 state:resolved] Signed-off-by: Santiago Pastorino --- .../cases/associations/belongs_to_associations_test.rb | 5 +++++ .../has_and_belongs_to_many_associations_test.rb | 10 ++++++++++ .../test/cases/associations/has_many_associations_test.rb | 12 ++++++++++++ .../associations/has_many_through_associations_test.rb | 14 ++++++++++++++ .../test/cases/associations/has_one_associations_test.rb | 5 +++++ activerecord/test/cases/method_scoping_test.rb | 2 +- 6 files changed, 47 insertions(+), 1 deletion(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 742513230e..cbaa4990f7 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -474,4 +474,9 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase Author.belongs_to :special_author_address, :dependent => :restrict end end + + def test_attributes_are_being_set_when_initialized_from_belongs_to_association_with_where_clause + new_firm = accounts(:signals37).build_firm(:name => 'Apple') + assert_equal new_firm.name, "Apple" + end end diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb index 2bdf9d8971..c0be7dfdcc 100644 --- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb @@ -848,4 +848,14 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase assert_queries(0) { david.projects.columns; david.projects.columns } end + def test_attributes_are_being_set_when_initialized_from_habm_association_with_where_clause + new_developer = projects(:action_controller).developers.where(:name => "Marcelo").build + assert_equal new_developer.name, "Marcelo" + end + + def test_attributes_are_being_set_when_initialized_from_habm_association_with_multiple_where_clauses + new_developer = projects(:action_controller).developers.where(:name => "Marcelo").where(:salary => 90_000).build + assert_equal new_developer.name, "Marcelo" + assert_equal new_developer.salary, 90_000 + end end diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index efabf74e13..720b7fc386 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1255,4 +1255,16 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end EOF end + + def test_attributes_are_being_set_when_initialized_from_has_many_association_with_where_clause + new_comment = posts(:welcome).comments.where(:body => "Some content").build + assert_equal new_comment.body, "Some content" + end + + def test_attributes_are_being_set_when_initialized_from_has_many_association_with_multiple_where_clauses + new_comment = posts(:welcome).comments.where(:body => "Some content").where(:type => 'SpecialComment').build + assert_equal new_comment.body, "Some content" + assert_equal new_comment.type, "SpecialComment" + assert_equal new_comment.post_id, posts(:welcome).id + end end 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 45f8bd64eb..0dac633852 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -421,4 +421,18 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert_raises(ActiveRecord::RecordNotFound) {company.developer_ids= ids} end + def test_build_a_model_from_hm_through_association_with_where_clause + assert_nothing_raised { books(:awdr).subscribers.where(:nick => "marklazz").build } + end + + def test_attributes_are_being_set_when_initialized_from_hm_through_association_with_where_clause + new_subscriber = books(:awdr).subscribers.where(:nick => "marklazz").build + assert_equal new_subscriber.nick, "marklazz" + end + + def test_attributes_are_being_set_when_initialized_from_hm_through_association_with_multiple_where_clauses + new_subscriber = books(:awdr).subscribers.where(:nick => "marklazz").where(:name => 'Marcelo Giorgi').build + assert_equal new_subscriber.nick, "marklazz" + assert_equal new_subscriber.name, "Marcelo Giorgi" + end end diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index e959ed46cc..b522be3fe0 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -326,4 +326,9 @@ class HasOneAssociationsTest < ActiveRecord::TestCase assert !account.new_record? assert_equal 500, account.credit_limit end + + def test_attributes_are_being_set_when_initialized_from_has_one_association_with_where_clause + new_account = companies(:first_firm).build_account(:firm_name => 'Account') + assert_equal new_account.firm_name, "Account" + end end diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb index ffe16ffdfa..f3d3d62830 100644 --- a/activerecord/test/cases/method_scoping_test.rb +++ b/activerecord/test/cases/method_scoping_test.rb @@ -219,7 +219,7 @@ class MethodScopingTest < ActiveRecord::TestCase new_comment = nil VerySpecialComment.send(:with_scope, :create => { :post_id => 1 }) do - assert_equal({:post_id => 1}, VerySpecialComment.scoped.send(:scope_for_create)) + assert_equal({:post_id => 1, :type => 'VerySpecialComment' }, VerySpecialComment.scoped.send(:scope_for_create)) new_comment = VerySpecialComment.create :body => "Wonderful world" end -- cgit v1.2.3 From 9b89a436e59bfe50ef6dfd85bd12311f326d7140 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 28 Sep 2010 15:51:07 -0700 Subject: Revert "porting 515917f5d8678af6c57842ca5dfd7c18e67ff1fe to master" This reverts commit bee447a5b9fe1d683c6cc69aefb7fc22c2a9d9af. --- activerecord/test/cases/associations/eager_test.rb | 6 ------ 1 file changed, 6 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 4a2c8bab5b..40859d425f 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -357,12 +357,6 @@ class EagerAssociationTest < ActiveRecord::TestCase end end - def test_eager_with_has_many_through_association_with_order - author_comments = Author.find(authors(:david).id).comments_desc - eager_author_comments = Author.find(authors(:david).id, :include => :comments_desc).comments_desc - assert_equal eager_author_comments, author_comments - end - def test_eager_with_has_many_through_with_conditions_join_model_with_include post_tags = Post.find(posts(:welcome).id).misc_tags eager_post_tags = Post.find(1, :include => :misc_tags).misc_tags -- cgit v1.2.3 From 2cc4b7f2978b3e2dac490894b5d548c7f58c587e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 09:54:22 -0700 Subject: fisting test organization --- .../test/cases/dynamic_finder_match_test.rb | 51 +++++++++++++++++++++- activerecord/test/cases/finder_test.rb | 51 ---------------------- 2 files changed, 50 insertions(+), 52 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/dynamic_finder_match_test.rb b/activerecord/test/cases/dynamic_finder_match_test.rb index 64bf6cb508..e576870317 100644 --- a/activerecord/test/cases/dynamic_finder_match_test.rb +++ b/activerecord/test/cases/dynamic_finder_match_test.rb @@ -2,18 +2,67 @@ require "cases/helper" module ActiveRecord class DynamicFinderMatchTest < ActiveRecord::TestCase + def test_find_or_create_by + match = DynamicFinderMatch.match("find_or_create_by_age_and_sex_and_location") + assert_not_nil match + assert !match.finder? + assert match.instantiator? + assert_equal :first, match.finder + assert_equal :create, match.instantiator + assert_equal %w(age sex location), match.attribute_names + end + + def test_find_or_initialize_by + match = DynamicFinderMatch.match("find_or_initialize_by_age_and_sex_and_location") + assert_not_nil match + assert !match.finder? + assert match.instantiator? + assert_equal :first, match.finder + assert_equal :new, match.instantiator + assert_equal %w(age sex location), match.attribute_names + end + + def test_find_no_match + assert_nil DynamicFinderMatch.match("not_a_finder") + end + + def find_by_bang + match = DynamicFinderMatch.match("find_by_age_and_sex_and_location!") + assert_not_nil match + assert match.finder? + assert match.bang? + assert_equal :first, match.finder + assert_equal %w(age sex location), match.attribute_names + end + def test_find_by + match = DynamicFinderMatch.match("find_by_age_and_sex_and_location") + assert_not_nil match + assert match.finder? + assert_equal :first, match.finder + assert_equal %w(age sex location), match.attribute_names + end + + def test_find_by_with_symbol m = DynamicFinderMatch.match(:find_by_foo) assert_equal :first, m.finder assert_equal %w{ foo }, m.attribute_names end - def test_find_all_by + def test_find_all_by_with_symbol m = DynamicFinderMatch.match(:find_all_by_foo) assert_equal :all, m.finder assert_equal %w{ foo }, m.attribute_names end + def test_find_all_by + match = DynamicFinderMatch.match("find_all_by_age_and_sex_and_location") + assert_not_nil match + assert match.finder? + assert_equal :all, match.finder + assert_equal %w(age sex location), match.attribute_names + end + def test_find_last_by m = DynamicFinderMatch.match(:find_last_by_foo) assert_equal :last, m.finder diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 4f3e43d77d..26b5096255 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -11,57 +11,6 @@ require 'models/project' require 'models/developer' require 'models/customer' -class DynamicFinderMatchTest < ActiveRecord::TestCase - def test_find_no_match - assert_nil ActiveRecord::DynamicFinderMatch.match("not_a_finder") - end - - def test_find_by - match = ActiveRecord::DynamicFinderMatch.match("find_by_age_and_sex_and_location") - assert_not_nil match - assert match.finder? - assert_equal :first, match.finder - assert_equal %w(age sex location), match.attribute_names - end - - def find_by_bang - match = ActiveRecord::DynamicFinderMatch.match("find_by_age_and_sex_and_location!") - assert_not_nil match - assert match.finder? - assert match.bang? - assert_equal :first, match.finder - assert_equal %w(age sex location), match.attribute_names - end - - def test_find_all_by - match = ActiveRecord::DynamicFinderMatch.match("find_all_by_age_and_sex_and_location") - assert_not_nil match - assert match.finder? - assert_equal :all, match.finder - assert_equal %w(age sex location), match.attribute_names - end - - def test_find_or_initialize_by - match = ActiveRecord::DynamicFinderMatch.match("find_or_initialize_by_age_and_sex_and_location") - assert_not_nil match - assert !match.finder? - assert match.instantiator? - assert_equal :first, match.finder - assert_equal :new, match.instantiator - assert_equal %w(age sex location), match.attribute_names - end - - def test_find_or_create_by - match = ActiveRecord::DynamicFinderMatch.match("find_or_create_by_age_and_sex_and_location") - assert_not_nil match - assert !match.finder? - assert match.instantiator? - assert_equal :first, match.finder - assert_equal :create, match.instantiator - assert_equal %w(age sex location), match.attribute_names - end -end - class FinderTest < ActiveRecord::TestCase fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts, :comments, :accounts, :authors, :customers, :categories, :categorizations -- cgit v1.2.3 From 5793d5e0023257962ed9a8ef980062cddd30ce19 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 29 Sep 2010 11:18:43 -0700 Subject: eliminating method_missing on TableDefinition --- activerecord/test/cases/migration_test.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 5242d78033..6e8ee95613 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -1588,13 +1588,23 @@ if ActiveRecord::Base.connection.supports_migrations? end end - if current_adapter?(:PostgreSQLAdapter) + if current_adapter?(:PostgreSQLAdapter) || current_adapter?(:SQLiteAdapter) || current_adapter?(:MysqlAdapter) || current_adapter?(:Mysql2Adapter) def test_xml_creates_xml_column + type = current_adapter?(:PostgreSQLAdapter) ? 'xml' : :text + with_new_table do |t| - t.expects(:column).with(:data, 'xml', {}) + t.expects(:column).with(:data, type, {}) t.xml :data end end + else + def test_xml_creates_xml_column + with_new_table do |t| + assert_raises(NotImplementedError) do + t.xml :data + end + end + end end protected -- cgit v1.2.3