Skip to content

Commit

Permalink
more specs
Browse files Browse the repository at this point in the history
  • Loading branch information
ajb committed Dec 10, 2013
1 parent cc848c0 commit 1a342f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Binary file modified spec/dummy/filterer-test
Binary file not shown.
22 changes: 22 additions & 0 deletions spec/lib/filterer/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ def starting_query
sort_option 'foo', 'baz', nulls_last: true
end

class SortingFiltererE < Filterer::Base
def starting_query
FakeQuery.new
end

sort_option 'id', default: true
sort_option Regexp.new('foo([0-9]+)'), -> (results, matches, filterer) { results.order(matches[1] + ' ' + filterer.direction) }
sort_option Regexp.new('zoo([0-9]+)'), -> (results, matches, filterer) { results.order('zoo') }
end

describe Filterer::Base do

it 'warns if starting_query is not overriden' do
Expand Down Expand Up @@ -168,6 +178,18 @@ def starting_query
filterer = SortingFiltererD.new(sort: 'foo', direction: 'desc')
end

it 'can distinguish between two regexps' do
FakeQuery.any_instance.should_receive(:order).with('zoo').and_return(FakeQuery.new)
filterer = SortingFiltererE.new(sort: 'zoo111')
filterer.sort.should == 'zoo111'
end

it 'can distinguish between two regexps part 2' do
FakeQuery.any_instance.should_receive(:order).with('111 ASC').and_return(FakeQuery.new)
filterer = SortingFiltererE.new(sort: 'foo111')
filterer.sort.should == 'foo111'
end

it 'throws an error when key is a regexp and no query string given' do
expect {
class ErrorSortingFiltererA < Filterer::Base
Expand Down

0 comments on commit 1a342f7

Please sign in to comment.