Test ransacker access via associations
This commit is contained in:
parent
62cf765c12
commit
d936136749
|
@ -26,13 +26,15 @@ module Ransack
|
|||
|
||||
describe '#ransacker' do
|
||||
it 'creates ransack attributes' do
|
||||
Person.ransacker :reversed_name, :formatter => proc {|v| v.reverse} do |parent|
|
||||
parent.table[:name]
|
||||
end
|
||||
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')
|
||||
end
|
||||
|
||||
it 'allows access of attributes through associations' do
|
||||
s = Person.search(:children_reversed_name_eq => 'htimS cirA')
|
||||
s.result.to_sql.should match /"children_people"."name" = 'Aric Smith'/
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'machinist/active_record'
|
||||
require 'sham'
|
||||
require 'faker'
|
||||
require 'ransack'
|
||||
|
||||
Time.zone = 'Eastern Time (US & Canada)'
|
||||
|
||||
|
@ -23,6 +24,4 @@ RSpec.configure do |config|
|
|||
config.before(:each) { Sham.reset(:before_each) }
|
||||
|
||||
config.include RansackHelper
|
||||
end
|
||||
|
||||
require 'ransack'
|
||||
end
|
|
@ -13,6 +13,10 @@ class Person < ActiveRecord::Base
|
|||
has_many :authored_article_comments, :through => :articles,
|
||||
:class_name => 'Comment', :foreign_key => :person_id
|
||||
has_many :notes, :as => :notable
|
||||
|
||||
ransacker :reversed_name, :formatter => proc {|v| v.reverse} do |parent|
|
||||
parent.table[:name]
|
||||
end
|
||||
end
|
||||
|
||||
class Article < ActiveRecord::Base
|
||||
|
|
Loading…
Reference in New Issue