Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue 130, updated gt, gte, lt, lte comparison methods #131

Merged
merged 1 commit into from
Jan 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions motion/adapters/array_finder_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions spec/finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down