Permalink
Browse files

there's no need to test for args length in criteria_and_keys_from_args

  • Loading branch information...
1 parent 39321c8 commit cf82ec6e7d4874dd4860d433a995ea2e5add9cdc @hamin committed Mar 14, 2012
Showing with 11 additions and 17 deletions.
  1. +8 −14 lib/mongo_mapper/plugins/modifiers.rb
  2. +3 −3 test/functional/test_modifiers.rb
@@ -73,21 +73,15 @@ def modifier_update(modifier, args)
end
def criteria_and_keys_from_args(args)
- if args.length < 3
- options = args[2].nil? ? nil : args[2]
- updates = args[1].nil? ? nil : args[1]
- criteria = args[0].is_a?(Hash) ? args[0] : {:id => args}
+ if args[0].is_a?(Hash)
+ criteria = args[0]
+ updates = args[1]
+ options = args[2]
else
- if args[0].is_a?(Hash)
- criteria = args[0].nil? ? nil : args[0]
- updates = args[1].nil? ? nil : args[1]
- options = args[2].nil? ? nil : 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
- end
+ 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
end
[criteria_hash(criteria).to_hash, updates, options]
end
@@ -1,5 +1,5 @@
-# require 'test_helper'
-require File.expand_path("../../test_helper", __FILE__)
+require 'test_helper'
+
class ModifierTest < Test::Unit::TestCase
def setup
@page_class = Doc do
@@ -329,7 +329,7 @@ def assert_keys_removed(page, *keys)
new_key_value = DateTime.now.to_s
@page_class.increment({:title => new_key_value}, {:day_count => 1}, {:upsert => true})
@page_class.count(:title => new_key_value).should == 1
- # @page_class.first(:title => new_key_value).day_count.should == 1
+ @page_class.first(:title => new_key_value).day_count.should == 1
end
should "be able to pass safe option" do

0 comments on commit cf82ec6

Please sign in to comment.