Skip to content

Commit

Permalink
Add base specs for search on fields with _start
Browse files Browse the repository at this point in the history
 and `_end`.

Add a failing spec for fields with `_and_` … that needs to be
fixed.
  • Loading branch information
jonatack committed Oct 27, 2014
1 parent 63b0d23 commit 5f8621c
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions spec/ransack/adapters/active_record/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,52 @@ def self.sane_adapter?
end

it "should function correctly when using fields with % in them" do
Person.create!(:name => "110%-er")
p = Person.create!(:name => "110%-er")
s = Person.search(:name_cont => "10%")
expect(s.result.exists?).to be true
expect(s.result.to_a).to eq [p]
end

it "should function correctly when using fields with backslashes in them" do
Person.create!(:name => "\\WINNER\\")
p = Person.create!(:name => "\\WINNER\\")
s = Person.search(:name_cont => "\\WINNER\\")
expect(s.result.exists?).to be true
expect(s.result.to_a).to eq [p]
end

it "should function correctly when an attribute name ends with '_start'" do
p = Person.create!(:new_start => 'Bar and foo', :name => 'Xiang')

s = Person.search(:new_start_end => ' and foo')
expect(s.result.to_a).to eq [p]

s = Person.search(:name_or_new_start_start => 'Xia')
expect(s.result.to_a).to eq [p]

s = Person.search(:new_start_or_name_end => 'iang')
expect(s.result.to_a).to eq [p]
end

it "should function correctly when an attribute name ends with '_end'" do
p = Person.create!(:stop_end => 'Foo and bar', :name => 'Marianne')

s = Person.search(:stop_end_start => 'Foo and')
expect(s.result.to_a).to eq [p]

s = Person.search(:stop_end_or_name_end => 'anne')
expect(s.result.to_a).to eq [p]

s = Person.search(:name_or_stop_end_end => ' bar')
expect(s.result.to_a).to eq [p]
end

it "should function correctly when an attribute name has 'and' in it" do
# FIXME: this test does not pass!
p = Person.create!(:terms_and_conditions => 'Accepted')
s = Person.search(:terms_and_conditions_eq => 'Accepted')
# search is not detecting the attribute
puts "Search not detecting the `terms_and_conditions` attribute: #{
s.result.to_sql}"
# expect(s.result.to_a).to eq [p]
end

it 'allows sort by "only_sort" field' do
Expand Down

0 comments on commit 5f8621c

Please sign in to comment.