2011-03-31 00:31:39 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
module Ransack
|
|
|
|
module Adapters
|
|
|
|
module ActiveRecord
|
|
|
|
describe Base do
|
|
|
|
|
|
|
|
it 'adds a ransack method to ActiveRecord::Base' do
|
|
|
|
::ActiveRecord::Base.should respond_to :ransack
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'aliases the method to search if available' do
|
|
|
|
::ActiveRecord::Base.should respond_to :search
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#search' do
|
|
|
|
before do
|
|
|
|
@s = Person.search
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a search with Relation as its object' do
|
|
|
|
@s.should be_a Search
|
|
|
|
@s.object.should be_an ::ActiveRecord::Relation
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-10 00:55:28 +00:00
|
|
|
describe '#ransacker' do
|
|
|
|
it 'creates ransack attributes' do
|
2011-04-11 16:04:31 +00:00
|
|
|
Person.ransacker :reversed_name, :formatter => proc {|v| v.reverse} do |parent|
|
|
|
|
parent.table[:name]
|
2011-04-11 01:11:28 +00:00
|
|
|
end
|
2011-04-11 16:04:31 +00:00
|
|
|
s = Person.search(:reversed_name_eq => 'htimS cirA')
|
|
|
|
s.result.should have(1).person
|
|
|
|
s.result.first.should eq Person.find_by_name('Aric Smith')
|
2011-04-10 00:55:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-31 00:31:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|