diff options
author | TomK32 <tomk32@tomk32.de> | 2008-05-16 11:13:32 +0200 |
---|---|---|
committer | TomK32 <tomk32@tomk32.de> | 2008-05-16 11:13:32 +0200 |
commit | fa0cca368f74119b561595cc6ca7454f7debdf6b (patch) | |
tree | 85022a5047c4d8da55a981cc3c1b8cc65f1adcd8 /activerecord/test | |
parent | f16c22040d5b66cb285fbd9a90858294376192bb (diff) | |
parent | 4e2bc02163aa646ab1304b1b5bec98a7af8927f5 (diff) | |
download | rails-fa0cca368f74119b561595cc6ca7454f7debdf6b.tar.gz rails-fa0cca368f74119b561595cc6ca7454f7debdf6b.tar.bz2 rails-fa0cca368f74119b561595cc6ca7454f7debdf6b.zip |
Merge branch 'master' of git@github.com:lifo/docrails
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/dirty_test.rb | 21 | ||||
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 12 | ||||
-rwxr-xr-x | activerecord/test/cases/fixtures_test.rb | 20 | ||||
-rwxr-xr-x | activerecord/test/cases/inheritance_test.rb | 28 | ||||
-rwxr-xr-x | activerecord/test/models/company.rb | 4 | ||||
-rw-r--r-- | activerecord/test/models/pirate.rb | 2 |
6 files changed, 74 insertions, 13 deletions
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 diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 2acfe9b387..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 @@ -859,12 +860,17 @@ 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 + 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 def bind(statement, *vars) 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 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? } diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index 3d76dfd398..f637490c59 100755 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -15,6 +15,10 @@ class Company < AbstractCompany end end +module Namespaced + class Company < ::Company + end +end class Firm < Company has_many :clients, :order => "id", :dependent => :destroy, :counter_sql => diff --git a/activerecord/test/models/pirate.rb b/activerecord/test/models/pirate.rb index bb4d02c10f..51c8183dee 100644 --- a/activerecord/test/models/pirate.rb +++ b/activerecord/test/models/pirate.rb @@ -4,4 +4,6 @@ class Pirate < ActiveRecord::Base has_many :treasures, :as => :looter has_many :treasure_estimates, :through => :treasures, :source => :price_estimates + + validates_presence_of :catchphrase end |