Skip to content

Instantly share code, notes, and snippets.

@snusnu
Created November 4, 2008 15:16
Show Gist options
  • Save snusnu/22146 to your computer and use it in GitHub Desktop.
Save snusnu/22146 to your computer and use it in GitHub Desktop.
# Trip obviously being a DataMapper::Resource here ...
irb(main):001:0> Trip.all :conditions => {}
ArgumentError: +options[:conditions]+ cannot be empty
from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/query.rb:226:in `assert_valid_options'
from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/query.rb:163:in `initialize'
from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/model.rb:394:in `new'
from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/model.rb:394:in `scoped_query'
from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/model.rb:252:in `all'
from (irb):1
from :0
irb(main):002:0> Trip.all :conditions => nil
ArgumentError: +options[:conditions]+ should be Hash or Array, but was NilClass
from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/query.rb:226:in `each_pair'
from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/query.rb:226:in `assert_valid_options'
from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/query.rb:163:in `initialize'
from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/model.rb:394:in `new'
from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/model.rb:394:in `scoped_query'
from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/model.rb:252:in `all'
from (irb):2
from :0
# -------------------------------------------------------------------------------------------------------
# Initial take on fixing this
# -------------------------------------------------------------------------------------------------------
From a02f6f62608d222faba0e6775d7b13632c292415 Mon Sep 17 00:00:00 2001
From: Martin Gamsjaeger <gamsnjaga@gmail.com>
Date: Tue, 4 Nov 2008 15:58:10 +0100
Subject: [PATCH] First step towards allowing an empty Hash as query condition.
---
lib/dm-core/query.rb | 4 ----
spec/unit/query_spec.rb | 2 +-
2 files changed, 1 insertions(+), 5 deletions(-)
diff --git a/lib/dm-core/query.rb b/lib/dm-core/query.rb
index 7c4dd37..46f1f5b 100644
--- a/lib/dm-core/query.rb
+++ b/lib/dm-core/query.rb
@@ -262,10 +262,6 @@ module DataMapper
# validates the :conditions option
elsif :conditions == attribute
assert_kind_of 'options[:conditions]', value, Hash, Array
-
- if value.empty?
- raise ArgumentError, '+options[:conditions]+ cannot be empty', caller(2)
- end
end
end
end
diff --git a/spec/unit/query_spec.rb b/spec/unit/query_spec.rb
index 93a9f96..fe18118 100644
--- a/spec/unit/query_spec.rb
+++ b/spec/unit/query_spec.rb
@@ -157,7 +157,7 @@ describe DataMapper::Query do
it "when options[:#{attribute}] is #{value.kind_of?(Array) && value.empty? ? 'an empty Array' : value.inspect}" do
lambda {
DataMapper::Query.new(@repository, Article, attribute => value)
- }.should raise_error(ArgumentError)
+ }.should_not raise_error
end
end
--
1.5.4.5
# ------------------------------------------------------------------------------------------------------
# Leads to the following new spec failures
# ------------------------------------------------------------------------------------------------------
6)
'DataMapper::Query.new should raise an ArgumentError when options[:includes] is an empty Array' FAILED
expected no Exception, got #<ArgumentError: +options[:includes]+ cannot be empty>
/Users/snusnu/projects/github/dm-core/spec/unit/query_spec.rb:158:
7)
'DataMapper::Query.new should raise an ArgumentError when options[:links] is an empty Array' FAILED
expected no Exception, got #<ArgumentError: +options[:links]+ cannot be empty>
/Users/snusnu/projects/github/dm-core/spec/unit/query_spec.rb:158:
8)
'DataMapper::Query.new should raise an ArgumentError when options[:reload] is "true"' FAILED
expected no Exception, got #<ArgumentError: +options[:reload]+ must be true or false, but was "true">
/Users/snusnu/projects/github/dm-core/spec/unit/query_spec.rb:158:
9)
'DataMapper::Query.new should raise an ArgumentError when options[:limit] is 0' FAILED
expected no Exception, got #<ArgumentError: +options[:limit]+ must be greater than or equal to 1, but was 0>
/Users/snusnu/projects/github/dm-core/spec/unit/query_spec.rb:158:
10)
'DataMapper::Query.new should raise an ArgumentError when options[:offset] is -1' FAILED
expected no Exception, got #<ArgumentError: +options[:offset]+ must be greater than or equal to 0, but was -1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment