aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-11-22 10:31:47 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2009-11-22 10:31:47 -0800
commite68bc3f14ea93eabdd4274e66071b65debb5a0a8 (patch)
tree223c11f38dac1217d8e7e3cd427fdf6018975a9d /activerecord/test/cases
parent3cb46b40a0df1a1f4912625cc2be40b3d630f1f3 (diff)
parente1935e3c0c35f8f1196239e2b1213c4436049fa5 (diff)
downloadrails-e68bc3f14ea93eabdd4274e66071b65debb5a0a8.tar.gz
rails-e68bc3f14ea93eabdd4274e66071b65debb5a0a8.tar.bz2
rails-e68bc3f14ea93eabdd4274e66071b65debb5a0a8.zip
Merge commit 'origin/master' into mail
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb12
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb22
-rw-r--r--activerecord/test/cases/copy_table_test_sqlite.rb4
-rw-r--r--activerecord/test/cases/helper.rb4
-rw-r--r--activerecord/test/cases/locking_test.rb31
-rw-r--r--activerecord/test/cases/pooled_connections_test.rb2
-rw-r--r--activerecord/test/cases/reflection_test.rb4
-rw-r--r--activerecord/test/cases/relations_test.rb2
8 files changed, 51 insertions, 30 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index b193f8d8ba..86d14c9c81 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -659,6 +659,18 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal 1, Client.find_all_by_client_of(firm.id).size
end
+ def test_delete_all_association_with_primary_key_deletes_correct_records
+ firm = Firm.find(:first)
+ # break the vanilla firm_id foreign key
+ assert_equal 2, firm.clients.count
+ firm.clients.first.update_attribute(:firm_id, nil)
+ assert_equal 1, firm.clients(true).count
+ assert_equal 1, firm.clients_using_primary_key_with_delete_all.count
+ old_record = firm.clients_using_primary_key_with_delete_all.first
+ firm = Firm.find(:first)
+ firm.destroy
+ assert Client.find_by_id(old_record.id).nil?
+ end
def test_creation_respects_hash_condition
ms_client = companies(:first_firm).clients_like_ms_with_hash_conditions.build
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 5f13b66d11..fe68d03de2 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -137,6 +137,28 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert !posts(:welcome).reload.people(true).include?(people(:michael))
end
+ def test_replace_order_is_preserved
+ posts(:welcome).people.clear
+ posts(:welcome).people = [people(:david), people(:michael)]
+ assert_equal [people(:david).id, people(:michael).id], posts(:welcome).readers.all(:order => 'id').map(&:person_id)
+
+ # Test the inverse order in case the first success was a coincidence
+ posts(:welcome).people.clear
+ posts(:welcome).people = [people(:michael), people(:david)]
+ assert_equal [people(:michael).id, people(:david).id], posts(:welcome).readers.all(:order => 'id').map(&:person_id)
+ end
+
+ def test_replace_by_id_order_is_preserved
+ posts(:welcome).people.clear
+ posts(:welcome).person_ids = [people(:david).id, people(:michael).id]
+ assert_equal [people(:david).id, people(:michael).id], posts(:welcome).readers.all(:order => 'id').map(&:person_id)
+
+ # Test the inverse order in case the first success was a coincidence
+ posts(:welcome).people.clear
+ posts(:welcome).person_ids = [people(:michael).id, people(:david).id]
+ assert_equal [people(:michael).id, people(:david).id], posts(:welcome).readers.all(:order => 'id').map(&:person_id)
+ end
+
def test_associate_with_create
assert_queries(1) { posts(:thinking) }
diff --git a/activerecord/test/cases/copy_table_test_sqlite.rb b/activerecord/test/cases/copy_table_test_sqlite.rb
index de8af30997..575b4806c1 100644
--- a/activerecord/test/cases/copy_table_test_sqlite.rb
+++ b/activerecord/test/cases/copy_table_test_sqlite.rb
@@ -1,7 +1,7 @@
require "cases/helper"
class CopyTableTest < ActiveRecord::TestCase
- fixtures :companies, :comments
+ fixtures :customers, :companies, :comments
def setup
@connection = ActiveRecord::Base.connection
@@ -27,8 +27,8 @@ class CopyTableTest < ActiveRecord::TestCase
test_copy_table('customers', 'customers2',
:rename => {'name' => 'person_name'}) do |from, to, options|
expected = column_values(from, 'name')
- assert expected.any?, 'only nils in resultset; real values are needed'
assert_equal expected, column_values(to, 'person_name')
+ assert expected.any?, "No values in table: #{expected.inspect}"
end
end
diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb
index 871cfa6468..25613da912 100644
--- a/activerecord/test/cases/helper.rb
+++ b/activerecord/test/cases/helper.rb
@@ -3,9 +3,11 @@ begin
require "#{root}/vendor/gems/environment"
rescue LoadError
$:.unshift("#{root}/activesupport/lib")
- $:.unshift("#{root}/activerecord/lib")
end
+lib = File.expand_path("#{File.dirname(__FILE__)}/../../lib")
+$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
+
require 'config'
require 'rubygems'
diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb
index e177235591..a64c01292f 100644
--- a/activerecord/test/cases/locking_test.rb
+++ b/activerecord/test/cases/locking_test.rb
@@ -38,24 +38,6 @@ class OptimisticLockingTest < ActiveRecord::TestCase
assert_raise(ActiveRecord::StaleObjectError) { p2.save! }
end
- def test_lock_destroy
- p1 = Person.find(1)
- p2 = Person.find(1)
- assert_equal 0, p1.lock_version
- assert_equal 0, p2.lock_version
-
- p1.first_name = 'stu'
- p1.save!
- assert_equal 1, p1.lock_version
- assert_equal 0, p2.lock_version
-
- assert_raises(ActiveRecord::StaleObjectError) { p2.destroy }
-
- assert p1.destroy
- assert_equal true, p1.frozen?
- assert_raises(ActiveRecord::RecordNotFound) { Person.find(1) }
- end
-
def test_lock_repeating
p1 = Person.find(1)
p2 = Person.find(1)
@@ -282,11 +264,14 @@ unless current_adapter?(:SybaseAdapter, :OpenBaseAdapter)
assert first.end > second.end
end
- def test_second_lock_waits
- assert [0.2, 1, 5].any? { |zzz|
- first, second = duel(zzz) { Person.find 1, :lock => true }
- second.end > first.end
- }
+ # Hit by ruby deadlock detection since connection checkout is mutexed.
+ if RUBY_VERSION < '1.9.0'
+ def test_second_lock_waits
+ assert [0.2, 1, 5].any? { |zzz|
+ first, second = duel(zzz) { Person.find 1, :lock => true }
+ second.end > first.end
+ }
+ end
end
protected
diff --git a/activerecord/test/cases/pooled_connections_test.rb b/activerecord/test/cases/pooled_connections_test.rb
index f9eea3d118..2529a33dab 100644
--- a/activerecord/test/cases/pooled_connections_test.rb
+++ b/activerecord/test/cases/pooled_connections_test.rb
@@ -105,7 +105,7 @@ class PooledConnectionsTest < ActiveRecord::TestCase
Thread.new do
ActiveRecord::Base.connection.rollback_db_transaction
ActiveRecord::Base.connection_pool.release_connection
- end.join rescue nil
+ end
add_record('three')
end
diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb
index 99e248743a..acd214eb5a 100644
--- a/activerecord/test/cases/reflection_test.rb
+++ b/activerecord/test/cases/reflection_test.rb
@@ -176,8 +176,8 @@ class ReflectionTest < ActiveRecord::TestCase
def test_reflection_of_all_associations
# FIXME these assertions bust a lot
- assert_equal 36, Firm.reflect_on_all_associations.size
- assert_equal 26, Firm.reflect_on_all_associations(:has_many).size
+ assert_equal 37, Firm.reflect_on_all_associations.size
+ assert_equal 27, Firm.reflect_on_all_associations(:has_many).size
assert_equal 10, Firm.reflect_on_all_associations(:has_one).size
assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size
end
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 4833d04aff..1a2c8030fb 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -78,7 +78,7 @@ class RelationTest < ActiveRecord::TestCase
relation = Topic.all
["map", "uniq", "sort", "insert", "delete", "update"].each do |method|
- assert relation.respond_to?(method)
+ assert relation.respond_to?(method), "Topic.all should respond to #{method.inspect}"
end
end