Skip to content

Commit

Permalink
Merge pull request #2011 from amatsuda/with_index
Browse files Browse the repository at this point in the history
replaced some "i += 1" sort of codes with Enumerable#with_index
  • Loading branch information
spastorino committed Jul 8, 2011
2 parents ad912c0 + dab0de4 commit 3a1ec9b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
3 changes: 1 addition & 2 deletions activerecord/lib/active_record/relation.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ def update_all(updates, conditions = nil, options = {})
# Person.update(people.keys, people.values) # Person.update(people.keys, people.values)
def update(id, attributes) def update(id, attributes)
if id.is_a?(Array) if id.is_a?(Array)
idx = -1 id.each.with_index.map {|one_id, idx| update(one_id, attributes[idx])}
id.collect { |one_id| idx += 1; update(one_id, attributes[idx]) }
else else
object = find(id) object = find(id)
object.update_attributes(attributes) object.update_attributes(attributes)
Expand Down
4 changes: 1 addition & 3 deletions activerecord/test/cases/fixtures_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -178,11 +178,9 @@ def test_omap_fixtures
assert_nothing_raised do assert_nothing_raised do
fixtures = ActiveRecord::Fixtures.new(Account.connection, 'categories', 'Category', FIXTURES_ROOT + "/categories_ordered") fixtures = ActiveRecord::Fixtures.new(Account.connection, 'categories', 'Category', FIXTURES_ROOT + "/categories_ordered")


i = 0 fixtures.each.with_index do |(name, fixture), i|
fixtures.each do |name, fixture|
assert_equal "fixture_no_#{i}", name assert_equal "fixture_no_#{i}", name
assert_equal "Category #{i}", fixture['name'] assert_equal "Category #{i}", fixture['name']
i += 1
end end
end end
end end
Expand Down

0 comments on commit 3a1ec9b

Please sign in to comment.