Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: mongomapper/mongomapper
...
head fork: mongomapper/mongomapper
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Oct 01, 2012
Chris Gaffney gaffneyc Support non-ObjectID ids being given to modifiers.
The partially broken by cf82ec6 where it allowed a single ID to be
passed and it would work as expected. This also adds support for
multiple IDs to be provided.
73f30d9
Commits on Oct 02, 2012
John Nunemaker jnunemaker Merge pull request #459 from jnunemaker/support-string-ids-in-modifiers
Support non-ObjectID ids being given to modifiers.
e3521dc
11 lib/mongo_mapper/plugins/modifiers.rb
View
@@ -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
14 test/functional/test_modifiers.rb
View
@@ -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

No commit comments for this range

Something went wrong with that request. Please try again.