File tree Expand file tree Collapse file tree
lib/rails_admin/adapters/active_record
spec/rails_admin/adapters/active_record Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -92,7 +92,7 @@ def inverse_of
9292 end
9393
9494 def read_only?
95- ( klass . all . instance_eval ( &scope ) . readonly_value if scope . is_a? Proc ) ||
95+ ( klass . all . instance_exec ( &scope ) . readonly_value if scope . is_a? ( Proc ) && scope . arity == 0 ) ||
9696 association . nested? ||
9797 false
9898 end
Original file line number Diff line number Diff line change @@ -20,7 +20,8 @@ class ARPost < Tableless
2020 end
2121
2222 class ARCategory < Tableless
23- has_and_belongs_to_many :a_r_posts
23+ has_and_belongs_to_many :a_r_posts , -> { readonly }
24+ has_and_belongs_to_many :scoped_posts , -> ( category ) { where ( id : category . id ) } , class_name : 'ARPost'
2425 belongs_to :librarian , polymorphic : true
2526 end
2627
@@ -173,6 +174,22 @@ class FieldTestWithSymbolForeignKey < FieldTest
173174 expect ( subject . read_only? ) . to be_falsey
174175 expect ( subject . nested_options ) . to be_nil
175176 end
177+
178+ context 'with a scope given' do
179+ subject { @category . associations . detect { |a | a . name == :a_r_posts } }
180+
181+ it 'does not break' do
182+ expect ( subject . read_only? ) . to be_truthy
183+ end
184+ end
185+
186+ context 'with a scope that receives an argument given' do
187+ subject { @category . associations . detect { |a | a . name == :scoped_posts } }
188+
189+ it 'ignores the scope' do
190+ expect ( subject . read_only? ) . to be_falsey
191+ end
192+ end
176193 end
177194
178195 describe 'polymorphic belongs_to association' do
You can’t perform that action at this time.
0 commit comments