diff --git a/motion/adapters/array_finder_query.rb b/motion/adapters/array_finder_query.rb index 6dd2c20..4a5dd0d 100644 --- a/motion/adapters/array_finder_query.rb +++ b/motion/adapters/array_finder_query.rb @@ -97,7 +97,7 @@ def eq(query_string, options = {:case_sensitive => false}) # see `eq` for notes on case sensitivity. def gt(query_string, options = {:case_sensitive => false}) do_comparison(query_string, options) do |comparator, item| - comparator > item + comparator < item end end alias_method :>, :gt @@ -108,7 +108,7 @@ def gt(query_string, options = {:case_sensitive => false}) # see `eq` for notes on case sensitivity. def lt(query_string, options = {:case_sensitive => false}) do_comparison(query_string, options) do |comparator, item| - comparator < item + comparator > item end end alias_method :<, :lt @@ -119,7 +119,7 @@ def lt(query_string, options = {:case_sensitive => false}) # see `eq` for notes on case sensitivity. def gte(query_string, options = {:case_sensitive => false}) do_comparison(query_string, options) do |comparator, item| - comparator >= item + comparator <= item end end alias_method :>=, :gte @@ -130,7 +130,7 @@ def gte(query_string, options = {:case_sensitive => false}) # see `eq` for notes on case sensitivity. def lte(query_string, options = {:case_sensitive => false}) do_comparison(query_string, options) do |comparator, item| - comparator <= item + comparator >= item end end alias_method :<=, :lte diff --git a/spec/finder_spec.rb b/spec/finder_spec.rb index b07c999..28008d6 100644 --- a/spec/finder_spec.rb +++ b/spec/finder_spec.rb @@ -132,6 +132,34 @@ class InTest it 'should returns last element' do Task.last.should.is_a Task end + + describe 'comparison finders' do + + it 'returns elements with id greater than 5' do + tasks = Task.where(:id).gt(5).all + tasks.length.should.equal(5) + tasks.reject{|t| [6,7,8,9,10].include?(t.id)}.should.be.empty + end + + it 'returns elements with id greater than or equal to 7' do + tasks = Task.where(:id).gte(7).all + tasks.length.should.equal(4) + tasks.reject{|t| [7,8,9,10].include?(t.id)}.should.be.empty + end + + it 'returns elements with id less than 5' do + tasks = Task.where(:id).lt(5).all + tasks.length.should.equal(4) + tasks.reject{|t| [1,2,3,4].include?(t.id)}.should.be.empty + end + + it 'returns elements with id less than or equal to 3' do + tasks = Task.where(:id).lte(3).all + tasks.length.should.equal(3) + tasks.reject{|t| [1,2,3].include?(t.id)}.should.be.empty + end + + end describe 'block-style finders' do before do