Skip to content

Commit

Permalink
Remove more unecessary assertions from DataMapper::Query
Browse files Browse the repository at this point in the history
dkubb committed Feb 15, 2012
1 parent a0ecbfb commit eada604
Showing 2 changed files with 1 addition and 30 deletions.
15 changes: 1 addition & 14 deletions lib/dm-core/query.rb
Original file line number Diff line number Diff line change
@@ -823,8 +823,6 @@ def assert_valid_links(links)
#
# @api private
def assert_valid_conditions(conditions)
assert_kind_of 'options[:conditions]', conditions, Conditions::AbstractOperation, Conditions::AbstractComparison, Hash, Array

case conditions
when Hash
conditions.each do |subject, bind_value|
@@ -856,8 +854,6 @@ def assert_valid_conditions(conditions)
# Verifies that query offset is non-negative and only used together with limit
# @api private
def assert_valid_offset(offset, limit)
offset = offset.to_int

unless offset >= 0
raise ArgumentError, "+options[:offset]+ must be greater than or equal to 0, but was #{offset.inspect}"
end
@@ -874,8 +870,6 @@ def assert_valid_offset(offset, limit)
#
# @api private
def assert_valid_limit(limit)
limit = limit.to_int

unless limit >= 0
raise ArgumentError, "+options[:limit]+ must be greater than or equal to 0, but was #{limit.inspect}"
end
@@ -886,14 +880,7 @@ def assert_valid_limit(limit)
#
# @api private
def assert_valid_order(order, fields)
return if order.nil?

order = Array(order)
if order.empty? && fields && fields.any? { |property| !property.kind_of?(Operator) }
raise ArgumentError, '+options[:order]+ should not be empty if +options[:fields] contains a non-operator'
end

order.each do |order_entry|
Array(order).each do |order_entry|
case order_entry
when Symbol, String
unless @properties.named?(order_entry)
16 changes: 0 additions & 16 deletions spec/semipublic/query_spec.rb
Original file line number Diff line number Diff line change
@@ -723,14 +723,6 @@ class ::Contact < User; end
end
end

describe 'that is invalid' do
it 'should raise an exception' do
lambda {
DataMapper::Query.new(@repository, @model, @options.update(:conditions => 'invalid'))
}.should raise_error(ArgumentError, '+options[:conditions]+ should be DataMapper::Query::Conditions::AbstractOperation or DataMapper::Query::Conditions::AbstractComparison or Hash or Array, but was String')
end
end

describe 'that is an empty Array' do
it 'should raise an exception' do
lambda {
@@ -1058,14 +1050,6 @@ class ::Contact < User; end
end
end

describe 'that is an empty Array and the fields option contains a non-operator' do
it 'should raise an exception' do
lambda {
DataMapper::Query.new(@repository, @model, @options.update(:order => [], :fields => [ :name ]))
}.should raise_error(ArgumentError, '+options[:order]+ should not be empty if +options[:fields] contains a non-operator')
end
end

describe 'that is an Array containing an unknown String' do
it 'should raise an exception' do
lambda {

0 comments on commit eada604

Please sign in to comment.