diff options
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/named_scope_test.rb | 15 |
2 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 3d2a03d2b9..5dc5f99582 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -666,6 +666,10 @@ class FinderTest < ActiveRecord::TestCase assert_nil Topic.find_by_title_and_author_name("The First Topic", "Mary") end + def test_find_by_two_attributes_but_passing_only_one + assert_raise(ArgumentError) { Topic.find_by_title_and_author_name("The First Topic") } + end + def test_find_last_by_one_attribute assert_equal Topic.last, Topic.find_last_by_title(Topic.last.title) assert_nil Topic.find_last_by_title("A title with no matches") @@ -947,6 +951,10 @@ class FinderTest < ActiveRecord::TestCase assert !another.persisted? end + def test_find_or_initialize_from_two_attributes_but_passing_only_one + assert_raise(ArgumentError) { Topic.find_or_initialize_by_title_and_author_name("Another topic") } + end + def test_find_or_initialize_from_one_aggregate_attribute_and_one_not new_customer = Customer.find_or_initialize_by_balance_and_name(Money.new(123), "Elizabeth") assert_equal 123, new_customer.balance.amount diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index 2afe3c8f32..01893e4dc3 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -497,6 +497,17 @@ end class DynamicScopeTest < ActiveRecord::TestCase fixtures :posts + def setup + # Ensure we start with a clean model with no generated class method + Post.methods.select{ |c| c =~ /scoped_by_/ }.each do |method_name| + Post.class_eval <<-RUBY + class << self + remove_method :#{method_name} + end + RUBY + end + end + def test_dynamic_scope assert_equal Post.scoped_by_author_id(1).find(1), Post.find(1) assert_equal Post.scoped_by_author_id_and_title(1, "Welcome to the weblog").first, Post.find(:first, :conditions => { :author_id => 1, :title => "Welcome to the weblog"}) @@ -507,4 +518,8 @@ class DynamicScopeTest < ActiveRecord::TestCase Developer.scoped_by_created_at(nil) assert_present Developer.methods.grep(/scoped_by_created_at/) end + + def test_dynamic_scope_with_less_number_of_arguments + assert_raise(ArgumentError){ Post.scoped_by_author_id_and_title(1) } + end end |