Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.

Commit eada604

Browse files
committed
Remove more unecessary assertions from DataMapper::Query
1 parent a0ecbfb commit eada604

2 files changed

Lines changed: 1 addition & 30 deletions

File tree

lib/dm-core/query.rb

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,6 @@ def assert_valid_links(links)
823823
#
824824
# @api private
825825
def assert_valid_conditions(conditions)
826-
assert_kind_of 'options[:conditions]', conditions, Conditions::AbstractOperation, Conditions::AbstractComparison, Hash, Array
827-
828826
case conditions
829827
when Hash
830828
conditions.each do |subject, bind_value|
@@ -856,8 +854,6 @@ def assert_valid_conditions(conditions)
856854
# Verifies that query offset is non-negative and only used together with limit
857855
# @api private
858856
def assert_valid_offset(offset, limit)
859-
offset = offset.to_int
860-
861857
unless offset >= 0
862858
raise ArgumentError, "+options[:offset]+ must be greater than or equal to 0, but was #{offset.inspect}"
863859
end
@@ -874,8 +870,6 @@ def assert_valid_offset(offset, limit)
874870
#
875871
# @api private
876872
def assert_valid_limit(limit)
877-
limit = limit.to_int
878-
879873
unless limit >= 0
880874
raise ArgumentError, "+options[:limit]+ must be greater than or equal to 0, but was #{limit.inspect}"
881875
end
@@ -886,14 +880,7 @@ def assert_valid_limit(limit)
886880
#
887881
# @api private
888882
def assert_valid_order(order, fields)
889-
return if order.nil?
890-
891-
order = Array(order)
892-
if order.empty? && fields && fields.any? { |property| !property.kind_of?(Operator) }
893-
raise ArgumentError, '+options[:order]+ should not be empty if +options[:fields] contains a non-operator'
894-
end
895-
896-
order.each do |order_entry|
883+
Array(order).each do |order_entry|
897884
case order_entry
898885
when Symbol, String
899886
unless @properties.named?(order_entry)

spec/semipublic/query_spec.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -723,14 +723,6 @@ class ::Contact < User; end
723723
end
724724
end
725725

726-
describe 'that is invalid' do
727-
it 'should raise an exception' do
728-
lambda {
729-
DataMapper::Query.new(@repository, @model, @options.update(:conditions => 'invalid'))
730-
}.should raise_error(ArgumentError, '+options[:conditions]+ should be DataMapper::Query::Conditions::AbstractOperation or DataMapper::Query::Conditions::AbstractComparison or Hash or Array, but was String')
731-
end
732-
end
733-
734726
describe 'that is an empty Array' do
735727
it 'should raise an exception' do
736728
lambda {
@@ -1058,14 +1050,6 @@ class ::Contact < User; end
10581050
end
10591051
end
10601052

1061-
describe 'that is an empty Array and the fields option contains a non-operator' do
1062-
it 'should raise an exception' do
1063-
lambda {
1064-
DataMapper::Query.new(@repository, @model, @options.update(:order => [], :fields => [ :name ]))
1065-
}.should raise_error(ArgumentError, '+options[:order]+ should not be empty if +options[:fields] contains a non-operator')
1066-
end
1067-
end
1068-
10691053
describe 'that is an Array containing an unknown String' do
10701054
it 'should raise an exception' do
10711055
lambda {

0 commit comments

Comments
 (0)