Add failing test for #437
Give person a ```belongs_to``` association to group for testing Fix for #437
This commit is contained in:
parent
eac62ff044
commit
c41c56722f
|
@ -100,9 +100,9 @@ module Ransack
|
||||||
def self.build_interpolations(associated_class)
|
def self.build_interpolations(associated_class)
|
||||||
{
|
{
|
||||||
:attr_fallback_name => attr_fallback_name(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
|
end
|
||||||
|
|
||||||
def self.attr_fallback_name(associated_class)
|
def self.attr_fallback_name(associated_class)
|
||||||
|
|
|
@ -43,9 +43,30 @@ module Ransack
|
||||||
|
|
||||||
describe '#label' do
|
describe '#label' do
|
||||||
|
|
||||||
it 'localizes attribute names' do
|
context 'with direct model attributes' do
|
||||||
html = @f.label :name_cont
|
it 'localizes attribute names' do
|
||||||
expect(html).to match /Full Name contains/
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,6 +22,10 @@ else
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Group < ActiveRecord::Base
|
||||||
|
has_many :people
|
||||||
|
end
|
||||||
|
|
||||||
class Person < ActiveRecord::Base
|
class Person < ActiveRecord::Base
|
||||||
if ActiveRecord::VERSION::MAJOR == 3
|
if ActiveRecord::VERSION::MAJOR == 3
|
||||||
default_scope order('id DESC')
|
default_scope order('id DESC')
|
||||||
|
@ -29,6 +33,7 @@ class Person < ActiveRecord::Base
|
||||||
default_scope { order(id: :desc) }
|
default_scope { order(id: :desc) }
|
||||||
end
|
end
|
||||||
belongs_to :parent, :class_name => 'Person', :foreign_key => :parent_id
|
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 :children, :class_name => 'Person', :foreign_key => :parent_id
|
||||||
has_many :articles
|
has_many :articles
|
||||||
has_many :comments
|
has_many :comments
|
||||||
|
@ -126,8 +131,14 @@ module Schema
|
||||||
ActiveRecord::Migration.verbose = false
|
ActiveRecord::Migration.verbose = false
|
||||||
|
|
||||||
ActiveRecord::Schema.define do
|
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|
|
create_table :people, :force => true do |t|
|
||||||
t.integer :parent_id
|
t.integer :parent_id
|
||||||
|
t.integer :group_id
|
||||||
t.string :name
|
t.string :name
|
||||||
t.string :email
|
t.string :email
|
||||||
t.string :only_search
|
t.string :only_search
|
||||||
|
|
Loading…
Reference in New Issue