Permalink
Browse files

Merge pull request #459 from jnunemaker/support-string-ids-in-modifiers

Support non-ObjectID ids being given to modifiers.
  • Loading branch information...
2 parents 94e9825 + 73f30d9 commit e3521dcc6ccbb227f2608d3b6790877478d05abd @jnunemaker jnunemaker committed Oct 2, 2012
Showing with 19 additions and 6 deletions.
  1. +5 −6 lib/mongo_mapper/plugins/modifiers.rb
  2. +14 −0 test/functional/test_modifiers.rb
@@ -77,14 +77,13 @@ def modifier_update(modifier, args)
def criteria_and_keys_from_args(args)
if args[0].is_a?(Hash)
criteria = args[0]
- updates = args[1]
- options = args[2]
+ updates = args[1]
+ options = args[2]
else
- split_args = args.partition{|a| a.is_a?(BSON::ObjectId)}
- criteria = {:id => split_args[0]}
- updates = split_args[1].first
- options = split_args[1].last
+ criteria, (updates, options) = args.partition { |a| !a.is_a?(Hash) }
+ criteria = { :id => criteria }
end
+
[criteria_hash(criteria).to_hash, updates, options]
end
end
@@ -109,6 +109,13 @@ def assert_keys_removed(page, *keys)
assert_page_counts @page, 1, 2, 3
assert_page_counts @page2, 1, 2, 3
end
+
+ should "work with ids given as strings" do
+ @page_class.increment(@page.id.to_s, @page2.id.to_s, :day_count => 1, :week_count => 2, :month_count => 3)
+
+ assert_page_counts @page, 1, 2, 3
+ assert_page_counts @page2, 1, 2, 3
+ end
end
context "decrement" do
@@ -137,6 +144,13 @@ def assert_keys_removed(page, *keys)
assert_page_counts @page, 0, 0, 0
assert_page_counts @page2, 0, 0, 0
end
+
+ should "work with ids given as strings" do
+ @page_class.decrement(@page.id.to_s, @page2.id.to_s, :day_count => -1, :week_count => 2, :month_count => -3)
+
+ assert_page_counts @page, 0, 0, 0
+ assert_page_counts @page2, 0, 0, 0
+ end
end
context "set" do

0 comments on commit e3521dc

Please sign in to comment.