Add failing test for #437

Give person a ```belongs_to``` association to group for testing
Fix for #437
This commit is contained in:
John Dell 2014-10-13 16:15:35 -07:00
parent eac62ff044
commit c41c56722f
3 changed files with 37 additions and 5 deletions

View File

@ -100,9 +100,9 @@ module Ransack
def self.build_interpolations(associated_class)
{
:attr_fallback_name => attr_fallback_name(associated_class),
:association_name => association_name
:association_name => association_name
}
.reject! { |_, value| value.nil? }
.reject { |_, value| value.nil? }
end
def self.attr_fallback_name(associated_class)

View File

@ -43,9 +43,30 @@ module Ransack
describe '#label' do
it 'localizes attribute names' do
html = @f.label :name_cont
expect(html).to match /Full Name contains/
context 'with direct model attributes' do
it 'localizes attribute names' do
html = @f.label :name_cont
expect(html).to match /Full Name contains/
end
it 'falls back to column name when no translation' do
html = @f.label :email_cont
expect(html).to match /Email contains/
end
end
context 'with has_many association attributes' do
it 'falls back to associated model + column name when no translation' do
html = @f.label :article_title_cont
expect(html).to match /Article title contains/
end
end
context 'with belongs_to association attributes' do
it 'falls back to associated model + column name when no translation' do
html = @f.label :group_name_cont
expect(html).to match /Group name contains/
end
end
end

View File

@ -22,6 +22,10 @@ else
)
end
class Group < ActiveRecord::Base
has_many :people
end
class Person < ActiveRecord::Base
if ActiveRecord::VERSION::MAJOR == 3
default_scope order('id DESC')
@ -29,6 +33,7 @@ class Person < ActiveRecord::Base
default_scope { order(id: :desc) }
end
belongs_to :parent, :class_name => 'Person', :foreign_key => :parent_id
belongs_to :group
has_many :children, :class_name => 'Person', :foreign_key => :parent_id
has_many :articles
has_many :comments
@ -126,8 +131,14 @@ module Schema
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define do
create_table :groups, :force => true do |t|
t.string :name
t.timestamps null: false
end
create_table :people, :force => true do |t|
t.integer :parent_id
t.integer :group_id
t.string :name
t.string :email
t.string :only_search