aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-01-24 14:13:10 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-01-24 14:13:10 +0000
commit0d2db8a7d112488c93680e88c9beecfdea0a9db5 (patch)
tree3719345ceb657582cbddcbbd70118fbf35cdc4ed /activerecord/test
parentb953ca8561ae05efbaedd84eec876a46d3b63ee1 (diff)
downloadrails-0d2db8a7d112488c93680e88c9beecfdea0a9db5.tar.gz
rails-0d2db8a7d112488c93680e88c9beecfdea0a9db5.tar.bz2
rails-0d2db8a7d112488c93680e88c9beecfdea0a9db5.zip
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
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/base_test.rb17
1 files changed, 17 insertions, 0 deletions
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