File tree Expand file tree Collapse file tree 4 files changed +26
-2
lines changed
spec/rails_admin/adapters Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ def field_type
3333
3434 def klass
3535 if options [ :polymorphic ]
36- polymorphic_parents ( :active_record , model . name . to_s , name ) || [ ]
36+ polymorphic_parents ( :active_record , association . active_record . name . to_s , name ) || [ ]
3737 else
3838 association . klass
3939 end
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ def field_type
4646
4747 def klass
4848 if polymorphic? && %i[ referenced_in belongs_to ] . include? ( macro )
49- polymorphic_parents ( :mongoid , model . name , name ) || [ ]
49+ polymorphic_parents ( :mongoid , association . inverse_class_name , name ) || [ ]
5050 else
5151 association . klass
5252 end
Original file line number Diff line number Diff line change @@ -215,6 +215,18 @@ class FieldTestWithSymbolForeignKey < FieldTest
215215 expect ( @category . associations . detect { |a | a . name == :librarian } . klass ) . to eq [ ARUser ]
216216 expect ( @blog . associations . detect { |a | a . name == :librarian } . klass ) . to eq [ ARProfile ]
217217 end
218+
219+ describe 'on a subclass' do
220+ before do
221+ class ARReview < ARComment ; end
222+ allow ( RailsAdmin ::Config ) . to receive ( :models_pool ) . and_return ( %w[ ARBlog ARPost ARCategory ARUser ARProfile ARComment ARReview ] )
223+ end
224+ subject { RailsAdmin ::AbstractModel . new ( ARReview ) . associations . detect { |a | a . name == :commentable } }
225+
226+ it 'returns correct target klasses' do
227+ expect ( subject . klass ) . to eq [ ARBlog , ARPost ]
228+ end
229+ end
218230 end
219231
220232 describe 'polymorphic inverse has_many association' do
Original file line number Diff line number Diff line change @@ -168,6 +168,18 @@ class MongoNote
168168 expect ( subject . read_only? ) . to be_falsey
169169 expect ( subject . nested_options ) . to be_nil
170170 end
171+
172+ describe 'on a subclass' do
173+ before do
174+ class MongoReview < MongoComment ; end
175+ allow ( RailsAdmin ::Config ) . to receive ( :models_pool ) . and_return ( %w[ MongoBlog MongoPost MongoCategory MongoUser MongoProfile MongoComment MongoReview ] )
176+ end
177+ subject { RailsAdmin ::AbstractModel . new ( MongoReview ) . associations . detect { |a | a . name == :commentable } }
178+
179+ it 'returns correct target klasses' do
180+ expect ( subject . klass ) . to eq [ MongoBlog , MongoPost ]
181+ end
182+ end
171183 end
172184
173185 describe 'polymorphic inverse has_many association' do
You can’t perform that action at this time.
0 commit comments