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
|
@ -102,7 +102,7 @@ module Ransack
|
|||
:attr_fallback_name => attr_fallback_name(associated_class),
|
||||
:association_name => association_name
|
||||
}
|
||||
.reject! { |_, value| value.nil? }
|
||||
.reject { |_, value| value.nil? }
|
||||
end
|
||||
|
||||
def self.attr_fallback_name(associated_class)
|
||||
|
|
|
@ -43,11 +43,32 @@ module Ransack
|
|||
|
||||
describe '#label' do
|
||||
|
||||
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
|
||||
|
||||
describe '#sort_link' do
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue