diff options
Diffstat (limited to 'activerecord/test/cases')
-rwxr-xr-x | activerecord/test/cases/base_test.rb | 10 | ||||
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 18 | ||||
-rw-r--r-- | activerecord/test/cases/locking_test.rb | 9 | ||||
-rw-r--r-- | activerecord/test/cases/nested_attributes_test.rb | 25 | ||||
-rw-r--r-- | activerecord/test/cases/validations_test.rb | 2 |
5 files changed, 59 insertions, 5 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 3623680de9..bbc4e543d5 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1994,6 +1994,16 @@ class BasicsTest < ActiveRecord::TestCase assert_equal last, Developer.find(:all, :order => 'developers.name, developers.salary DESC').last end + def test_find_keeps_multiple_order_values + combined = Developer.find(:all, :order => 'developers.name, developers.salary') + assert_equal combined, Developer.find(:all, :order => ['developers.name', 'developers.salary']) + end + + def test_find_keeps_multiple_group_values + combined = Developer.find(:all, :group => 'developers.name, developers.salary, developers.id, developers.created_at, developers.updated_at') + assert_equal combined, Developer.find(:all, :group => ['developers.name', 'developers.salary', 'developers.id', 'developers.created_at', 'developers.updated_at']) + end + def test_find_symbol_ordered_last last = Developer.find :last, :order => :salary assert_equal last, Developer.find(:all, :order => :salary).last diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 77b2b748b1..e78db8969d 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -840,7 +840,7 @@ class FinderTest < ActiveRecord::TestCase assert c.new_record? end - def test_find_or_create_from_one_attribute_should_set_not_attribute_even_when_protected + def test_find_or_create_from_one_attribute_should_not_set_attribute_even_when_protected c = Company.find_or_create_by_name({:name => "Fortune 1000", :rating => 1000}) assert_equal "Fortune 1000", c.name assert_not_equal 1000, c.rating @@ -864,6 +864,22 @@ class FinderTest < ActiveRecord::TestCase assert !c.new_record? end + def test_find_or_initialize_from_one_attribute_should_set_attribute_even_when_protected_and_also_set_the_hash + c = Company.find_or_initialize_by_rating(1000, {:name => "Fortune 1000"}) + assert_equal "Fortune 1000", c.name + assert_equal 1000, c.rating + assert c.valid? + assert c.new_record? + end + + def test_find_or_create_from_one_attribute_should_set_attribute_even_when_protected_and_also_set_the_hash + c = Company.find_or_create_by_rating(1000, {:name => "Fortune 1000"}) + assert_equal "Fortune 1000", c.name + assert_equal 1000, c.rating + assert c.valid? + assert !c.new_record? + end + def test_find_or_initialize_should_set_protected_attributes_if_given_as_block c = Company.find_or_initialize_by_name(:name => "Fortune 1000") { |f| f.rating = 1000 } assert_equal "Fortune 1000", c.name diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb index aa2d9527f9..66874cdad1 100644 --- a/activerecord/test/cases/locking_test.rb +++ b/activerecord/test/cases/locking_test.rb @@ -195,7 +195,7 @@ class OptimisticLockingTest < ActiveRecord::TestCase assert_raises(ActiveRecord::RecordNotFound) { Person.find(p1.id) } assert_raises(ActiveRecord::RecordNotFound) { LegacyThing.find(t.id) } end - + def test_quote_table_name ref = references(:michael_magician) ref.favourite = !ref.favourite @@ -206,8 +206,11 @@ class OptimisticLockingTest < ActiveRecord::TestCase # is nothing else being updated. def test_update_without_attributes_does_not_only_update_lock_version assert_nothing_raised do - p1 = Person.new(:first_name => 'anika') - p1.send(:update_with_lock, []) + p1 = Person.create!(:first_name => 'anika') + lock_version = p1.lock_version + p1.save + p1.reload + assert_equal lock_version, p1.lock_version end end diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index eae8ae7e39..fadd62b5a1 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -6,6 +6,8 @@ require "models/parrot" require "models/treasure" require "models/man" require "models/interest" +require "models/owner" +require "models/pet" require 'active_support/hash_with_indifferent_access' module AssertRaiseWithMessage @@ -707,3 +709,26 @@ class TestNestedAttributesLimit < ActiveRecord::TestCase end end end + +class TestNestedAttributesWithNonStandardPrimaryKeys < ActiveRecord::TestCase + fixtures :owners, :pets + + def setup + Owner.accepts_nested_attributes_for :pets + + @owner = owners(:ashley) + @pet1, @pet2 = pets(:chew), pets(:mochi) + + @params = { + :pets_attributes => { + '0' => { :id => @pet1.id, :name => 'Foo' }, + '1' => { :id => @pet2.id, :name => 'Bar' } + } + } + end + + def test_should_update_existing_records_with_non_standard_primary_key + @owner.update_attributes(@params) + assert_equal ['Foo', 'Bar'], @owner.pets.map(&:name) + end +end diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index 937e08ac68..e1fb911cc9 100644 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -44,7 +44,7 @@ class ValidationsTest < ActiveRecord::TestCase def test_error_on_create r = WrongReply.new r.title = "Wrong Create" - assert !r.valid? + assert !r.save assert r.errors[:title].any?, "A reply with a bad title should mark that attribute as invalid" assert_equal ["is Wrong Create"], r.errors[:title], "A reply with a bad content should contain an error" end |