From 0d2db8a7d112488c93680e88c9beecfdea0a9db5 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 24 Jan 2005 14:13:10 +0000 Subject: Added Base.update_collection that can update an array of id/attribute pairs, such as the ones produced by the recent added support for automatic id-based indexing for lists of items #526 [Duane Johnson] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@496 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/base_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 02690b7396..2119785caf 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -292,6 +292,23 @@ class BasicsTest < Test::Unit::TestCase assert_equal "bulk updated again!", Topic.find(2).content end + def test_update_collection + ids_and_attributes = { "1" => { "content" => "1 updated" }, "2" => { "content" => "2 updated" } } + updated = Topic.update_collection(ids_and_attributes) + + assert_equal 2, updated.size + assert_equal "1 updated", Topic.find(1).content + assert_equal "2 updated", Topic.find(2).content + + ids_and_attributes["1"]["content"] = "one updated" + ids_and_attributes["2"]["content"] = "two updated" + updated = Topic.update_collection(ids_and_attributes) { |ar, attrs| ar.id == 1 } + + assert_equal 1, updated.size + assert_equal "one updated", Topic.find(1).content + assert_equal "2 updated", Topic.find(2).content + end + def test_delete_all assert_equal 2, Topic.delete_all end -- cgit v1.2.3