diff options
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 17 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/dirty_test.rb | 21 | ||||
-rw-r--r-- | activerecord/test/cases/migration_test.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/named_scope_test.rb | 6 | ||||
-rwxr-xr-x | activerecord/test/cases/validations_test.rb | 8 |
6 files changed, 64 insertions, 2 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 67b57ceb42..3a3358e39b 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -275,6 +275,17 @@ class EagerAssociationTest < ActiveRecord::TestCase Author.find(:first, :order => 'authors.id').hello_post_comments.sort_by(&:id) end + def test_eager_with_has_many_through_join_model_with_conditions_on_top_level + assert_equal comments(:more_greetings), Author.find(authors(:david).id, :include => :comments_with_order_and_conditions).comments_with_order_and_conditions.first + end + + def test_eager_with_has_many_through_join_model_with_include + author_comments = Author.find(authors(:david).id, :include => :comments_with_include).comments_with_include.to_a + assert_no_queries do + author_comments.first.post.title + end + end + def test_eager_with_has_many_and_limit posts = Post.find(:all, :order => 'posts.id asc', :include => [ :author, :comments ], :limit => 2) assert_equal 2, posts.size @@ -592,4 +603,10 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "length(comments.body) > 15") end end + + def test_load_with_sti_sharing_association + assert_queries(2) do #should not do 1 query per subclass + Comment.find :all, :include => :post + end + 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 7b97afe42c..9e26e2ad58 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -48,6 +48,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal 2, Firm.find(:first).clients.length end + def test_find_with_blank_conditions + [[], {}, nil, ""].each do |blank| + assert_equal 2, Firm.find(:first).clients.find(:all, :conditions => blank).size + end + end + def test_find_many_with_merged_options assert_equal 1, companies(:first_firm).limited_clients.size assert_equal 1, companies(:first_firm).limited_clients.find(:all).size @@ -851,4 +857,4 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert ! firm.clients.include?(client) end -end
\ No newline at end of file +end 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/migration_test.rb b/activerecord/test/cases/migration_test.rb index 6be31b5f86..527856b4c0 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -984,6 +984,12 @@ if ActiveRecord::Base.connection.supports_migrations? end end + def test_migrator_with_duplicate_names + assert_raises(ActiveRecord::DuplicateMigrationNameError, "Multiple migrations have the name Chunky") do + ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/duplicate_names", nil) + end + end + def test_migrator_with_missing_version_numbers assert_raise(ActiveRecord::UnknownMigrationVersionError) do ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/missing", 500) diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index e99448c23e..30c074c9d8 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -112,4 +112,10 @@ class NamedScopeTest < ActiveRecord::TestCase assert_equal Topic.find(:all, scope), Topic.scoped(scope) end + + def test_proxy_options + expected_proxy_options = { :conditions => { :approved => true } } + assert_equal expected_proxy_options, Topic.approved.proxy_options + end + end diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index e3ca8660ac..a4d9da4806 100755 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -5,6 +5,7 @@ require 'models/reply' require 'models/person' require 'models/developer' require 'models/warehouse_thing' +require 'models/guid' # The following methods in Topic are used in test_conditional_validation_* class Topic @@ -493,6 +494,13 @@ class ValidationsTest < ActiveRecord::TestCase end end + def test_validate_uniqueness_with_columns_which_are_sql_keywords + Guid.validates_uniqueness_of :key + g = Guid.new + g.key = "foo" + assert_nothing_raised { !g.valid? } + end + def test_validate_straight_inheritance_uniqueness w1 = IneptWizard.create(:name => "Rincewind", :city => "Ankh-Morpork") assert w1.valid?, "Saving w1" |