aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2008-09-22 21:35:35 +0200
committerMichael Koziarski <michael@koziarski.com>2008-09-22 21:35:35 +0200
commit638bd19c7fdf4a4c09bfa5b4ada23c6f37724f9b (patch)
treec27414d94e86b396fe716e031a6fafb0fc8ca575 /activerecord/test
parent5795c509a7c0ab9c6d3d707f34526430e58e535c (diff)
parent5f86451a4c5d0beca5a746c4708be48b13f665be (diff)
downloadrails-638bd19c7fdf4a4c09bfa5b4ada23c6f37724f9b.tar.gz
rails-638bd19c7fdf4a4c09bfa5b4ada23c6f37724f9b.tar.bz2
rails-638bd19c7fdf4a4c09bfa5b4ada23c6f37724f9b.zip
Merge branch 'patches' into multibyte
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb2
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb13
-rwxr-xr-xactiverecord/test/cases/base_test.rb26
3 files changed, 40 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index 9981f4c5d5..c1d4ea8b50 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -253,7 +253,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
assert !devel.projects.loaded?
assert_equal devel.projects.last, proj
- assert devel.projects.loaded?
+ assert !devel.projects.loaded?
assert !proj.new_record?
assert_equal Developer.find(1).projects.sort_by(&:id).last, proj # prove join table is updated
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index ba750b266c..9d550916d7 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1009,6 +1009,19 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert firm.clients.loaded?
end
+ def test_calling_first_or_last_on_existing_record_with_create_should_not_load_association
+ firm = companies(:first_firm)
+ firm.clients.create(:name => 'Foo')
+ assert !firm.clients.loaded?
+
+ assert_queries 2 do
+ firm.clients.first
+ firm.clients.last
+ end
+
+ assert !firm.clients.loaded?
+ end
+
def test_calling_first_or_last_on_new_record_should_not_run_queries
firm = Firm.new
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index a4fddc2571..d512834237 100755
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -472,6 +472,18 @@ class BasicsTest < ActiveRecord::TestCase
assert topic.instance_variable_get("@custom_approved")
end
+ def test_delete
+ topic = Topic.find(1)
+ assert_equal topic, topic.delete, 'topic.delete did not return self'
+ assert topic.frozen?, 'topic not frozen after delete'
+ assert_raise(ActiveRecord::RecordNotFound) { Topic.find(topic.id) }
+ end
+
+ def test_delete_doesnt_run_callbacks
+ Topic.find(1).delete
+ assert_not_nil Topic.find(2)
+ end
+
def test_destroy
topic = Topic.find(1)
assert_equal topic, topic.destroy, 'topic.destroy did not return self'
@@ -820,6 +832,20 @@ class BasicsTest < ActiveRecord::TestCase
assert_equal [ Topic.find(1) ], [ Topic.find(2).topic ] & [ Topic.find(1) ]
end
+ def test_delete_new_record
+ client = Client.new
+ client.delete
+ assert client.frozen?
+ end
+
+ def test_delete_record_with_associations
+ client = Client.find(3)
+ client.delete
+ assert client.frozen?
+ assert_kind_of Firm, client.firm
+ assert_raises(ActiveSupport::FrozenObjectError) { client.name = "something else" }
+ end
+
def test_destroy_new_record
client = Client.new
client.destroy