Fix issue where trying to add a polymorphic field in search form resulted in NameError
Fixes #159 Fixes #313
This commit is contained in:
parent
ad5cd7a8b0
commit
f491cb2ad0
|
@ -180,10 +180,15 @@ module Ransack
|
|||
|
||||
def strip_predicate_and_index(str)
|
||||
string = str.split(/\(/).first
|
||||
string = strip_before_type_cast(string)
|
||||
Predicate.detect_and_strip_from_string!(string)
|
||||
string
|
||||
end
|
||||
|
||||
def strip_before_type_cast(str)
|
||||
str.split("_before_type_cast").first
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,3 +1,5 @@
|
|||
Note.blueprint do
|
||||
note
|
||||
notable_type { "Article" }
|
||||
notable_id
|
||||
end
|
|
@ -7,6 +7,7 @@ module Ransack
|
|||
router = ActionDispatch::Routing::RouteSet.new
|
||||
router.draw do
|
||||
resources :people
|
||||
resources :notes
|
||||
get ':controller(/:action(/:id(.:format)))'
|
||||
end
|
||||
|
||||
|
@ -132,6 +133,22 @@ module Ransack
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'fields used in polymorphic relations as search attributes in form' do
|
||||
before do
|
||||
@controller.view_context.search_form_for Note.search do |f|
|
||||
@f = f
|
||||
end
|
||||
end
|
||||
it 'accepts poly_id field' do
|
||||
html = @f.text_field(:notable_id_eq)
|
||||
html.should match /id=\"q_notable_id_eq\"/
|
||||
end
|
||||
it 'accepts poly_type field' do
|
||||
html = @f.text_field(:notable_type_eq)
|
||||
html.should match /id=\"q_notable_type_eq\"/
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,12 +11,13 @@ Dir[File.expand_path('../{helpers,support,blueprints}/*.rb', __FILE__)].each do
|
|||
end
|
||||
|
||||
Sham.define do
|
||||
name { Faker::Name.name }
|
||||
title { Faker::Lorem.sentence }
|
||||
body { Faker::Lorem.paragraph }
|
||||
salary {|index| 30000 + (index * 1000)}
|
||||
tag_name { Faker::Lorem.words(3).join(' ') }
|
||||
note { Faker::Lorem.words(7).join(' ') }
|
||||
name { Faker::Name.name }
|
||||
title { Faker::Lorem.sentence }
|
||||
body { Faker::Lorem.paragraph }
|
||||
salary {|index| 30000 + (index * 1000)}
|
||||
tag_name { Faker::Lorem.words(3).join(' ') }
|
||||
note { Faker::Lorem.words(7).join(' ') }
|
||||
notable_id { |id| id }
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
|
|
Loading…
Reference in New Issue