From 593e21d6aedcc05d744be4996bd7180edce57efe Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 13 May 2008 00:46:57 +0200 Subject: Dirty attributes aren't cleared if save fails. [#174 state:resolved] Signed-off-by: Jeremy Kemper --- activerecord/test/cases/dirty_test.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index 7412e63872..1266eb5036 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -78,7 +78,7 @@ class DirtyTest < ActiveRecord::TestCase end def test_association_assignment_changes_foreign_key - pirate = Pirate.create! + pirate = Pirate.create!(:catchphrase => 'jarl') pirate.parrot = Parrot.create! assert pirate.changed? assert_equal %w(parrot_id), pirate.changed @@ -115,6 +115,18 @@ class DirtyTest < ActiveRecord::TestCase end end + def test_changed_attributes_should_be_preserved_if_save_failure + pirate = Pirate.new + pirate.parrot_id = 1 + assert !pirate.save + check_pirate_after_save_failure(pirate) + + pirate = Pirate.new + pirate.parrot_id = 1 + assert_raises(ActiveRecord::RecordInvalid) { pirate.save! } + check_pirate_after_save_failure(pirate) + end + private def with_partial_updates(klass, on = true) old = klass.partial_updates? @@ -123,4 +135,11 @@ class DirtyTest < ActiveRecord::TestCase ensure klass.partial_updates = old end + + def check_pirate_after_save_failure(pirate) + assert pirate.changed? + assert pirate.parrot_id_changed? + assert_equal %w(parrot_id), pirate.changed + assert_nil pirate.parrot_id_was + end end -- cgit v1.2.3 From 3a0d8adcf25e27f7976a1d0996be05f21ffc3805 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 13 May 2008 15:22:48 -0400 Subject: Fix tests broken by mocha absence [#186 state:resolved] Two ActiveRecord tests depended on mocha but were not marked as such. Place them in a use_mocha block so the test suite passes. Signed-off-by: Pratik Naik --- activerecord/test/cases/fixtures_test.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index 2787b9a39d..aca7cfb367 100755 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -610,15 +610,17 @@ class ActiveSupportSubclassWithFixturesTest < ActiveRecord::TestCase end class FixtureLoadingTest < ActiveRecord::TestCase - def test_logs_message_for_failed_dependency_load - Test::Unit::TestCase.expects(:require_dependency).with(:does_not_exist).raises(LoadError) - ActiveRecord::Base.logger.expects(:warn) - Test::Unit::TestCase.try_to_load_dependency(:does_not_exist) - end + uses_mocha 'reloading_fixtures_through_accessor_methods' do + def test_logs_message_for_failed_dependency_load + Test::Unit::TestCase.expects(:require_dependency).with(:does_not_exist).raises(LoadError) + ActiveRecord::Base.logger.expects(:warn) + Test::Unit::TestCase.try_to_load_dependency(:does_not_exist) + end - def test_does_not_logs_message_for_successful_dependency_load - Test::Unit::TestCase.expects(:require_dependency).with(:works_out_fine) - ActiveRecord::Base.logger.expects(:warn).never - Test::Unit::TestCase.try_to_load_dependency(:works_out_fine) + def test_does_not_logs_message_for_successful_dependency_load + Test::Unit::TestCase.expects(:require_dependency).with(:works_out_fine) + ActiveRecord::Base.logger.expects(:warn).never + Test::Unit::TestCase.try_to_load_dependency(:works_out_fine) + end end end -- cgit v1.2.3 From bca8751e40a5594c4de2ca58e089b8d98e44632b Mon Sep 17 00:00:00 2001 From: Rodrigo Kochenburger Date: Fri, 11 Apr 2008 12:35:09 -0300 Subject: Add ActiveRecord option to store the full class name on STI's type column, allowing one to have STI subclasses in different namespaces [#114] Signed-off-by: rick --- activerecord/test/cases/inheritance_test.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index c9eb83e371..27394924a1 100755 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -5,6 +5,34 @@ require 'models/subscriber' class InheritanceTest < ActiveRecord::TestCase fixtures :companies, :projects, :subscribers, :accounts + + def test_should_store_demodulized_class_name_with_store_full_sti_class_option_disabled + old = ActiveRecord::Base.store_full_sti_class + ActiveRecord::Base.store_full_sti_class = false + item = Namespaced::Company.new + assert_equal 'Company', item[:type] + ensure + ActiveRecord::Base.store_full_sti_class = old + end + + def test_should_store_full_class_name_with_store_full_sti_class_option_enabled + old = ActiveRecord::Base.store_full_sti_class + ActiveRecord::Base.store_full_sti_class = true + item = Namespaced::Company.new + assert_equal 'Namespaced::Company', item[:type] + ensure + ActiveRecord::Base.store_full_sti_class = old + end + + def test_different_namespace_subclass_should_load_correctly_with_store_full_sti_class_option + old = ActiveRecord::Base.store_full_sti_class + ActiveRecord::Base.store_full_sti_class = true + item = Namespaced::Company.create :name => "Wolverine 2" + assert_not_nil Company.find(item.id) + assert_not_nil Namespaced::Company.find(item.id) + ensure + ActiveRecord::Base.store_full_sti_class = old + end def test_company_descends_from_active_record assert_raise(NoMethodError) { ActiveRecord::Base.descends_from_active_record? } -- cgit v1.2.3 From b28b54cab090bed8f099ef375b419a8f92390dd4 Mon Sep 17 00:00:00 2001 From: John Devine Date: Sun, 4 May 2008 14:08:19 -0500 Subject: Make sure needed table joins are included :select option. [#110 state:resolved] Signed-off-by: Pratik Naik --- activerecord/test/cases/finder_test.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 2acfe9b387..d3e2f33f99 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -859,12 +859,15 @@ class FinderTest < ActiveRecord::TestCase end def test_find_with_order_on_included_associations_with_construct_finder_sql_for_association_limiting_and_is_distinct - assert_equal 2, Post.find(:all,:include=>{:authors=>:author_address},:order=>' author_addresses.id DESC ', :limit=>2).size + assert_equal 2, Post.find(:all, :include => { :authors => :author_address }, :order => ' author_addresses.id DESC ', :limit => 2).size - assert_equal 3, Post.find(:all,:include=>{:author=>:author_address,:authors=>:author_address}, - :order=>' author_addresses_authors.id DESC ', :limit=>3).size + assert_equal 3, Post.find(:all, :include => { :author => :author_address, :authors => :author_address}, + :order => ' author_addresses_authors.id DESC ', :limit => 3).size end + def test_with_limiting_with_custom_select + assert_equal 3, Post.find(:all, :include => :author, :select => ' posts.*, authors.id as "author_id"', :limit => 3).size + end protected def bind(statement, *vars) -- cgit v1.2.3 From 802034ff5f1c3e3b576b664d5660e76c8f44909d Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 15 May 2008 13:41:54 +0100 Subject: DRY associations code and improve eager loading tests. --- activerecord/test/cases/finder_test.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index d3e2f33f99..5c0f0e2ef1 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -9,6 +9,7 @@ require 'models/developer' require 'models/post' require 'models/customer' require 'models/job' +require 'models/categorization' class FinderTest < ActiveRecord::TestCase fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts, :comments, :accounts, :authors, :customers @@ -866,7 +867,9 @@ class FinderTest < ActiveRecord::TestCase end def test_with_limiting_with_custom_select - assert_equal 3, Post.find(:all, :include => :author, :select => ' posts.*, authors.id as "author_id"', :limit => 3).size + posts = Post.find(:all, :include => :author, :select => ' posts.*, authors.id as "author_id"', :limit => 3) + assert_equal 3, posts.size + assert_equal [0, 1, 1], posts.map(&:author_id).sort end protected -- cgit v1.2.3