Skip to content

Commit

Permalink
Restore caching in RailsAdmin::Config::Model#excluded? (#3587)
Browse files Browse the repository at this point in the history
Partially reverts 2fa86c3. The commit
introduced a regression such that RailsAdmin::Config::Model#excluded?
stopped caching false values.
  • Loading branch information
jdufresne committed Jan 12, 2023
1 parent e8319bc commit edd9f24
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/rails_admin/config/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def initialize(entity)
end

def excluded?
@excluded ||= !RailsAdmin::AbstractModel.all.collect(&:model_name).include?(abstract_model.try(:model_name))
return @excluded if defined?(@excluded)

@excluded = !RailsAdmin::AbstractModel.all.collect(&:model_name).include?(abstract_model.try(:model_name))
end

def object_label
Expand Down
17 changes: 15 additions & 2 deletions spec/rails_admin/config/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@
end

it 'returns false when included, true otherwise' do
expect(RailsAdmin.config(Player).excluded?).to be_truthy
expect(RailsAdmin.config(Comment).excluded?).to be_falsey
allow(RailsAdmin::AbstractModel).to receive(:all).and_call_original

player_config = RailsAdmin.config(Player)
expect(player_config.excluded?).to be_truthy
expect(RailsAdmin::AbstractModel).to have_received(:all).once
# Calling a second time uses the cached value.
expect(player_config.excluded?).to be_truthy
expect(RailsAdmin::AbstractModel).to have_received(:all).once

comment_config = RailsAdmin.config(Comment)
expect(comment_config.excluded?).to be_falsey
expect(RailsAdmin::AbstractModel).to have_received(:all).twice
# Calling a second time uses the cached value.
expect(comment_config.excluded?).to be_falsey
expect(RailsAdmin::AbstractModel).to have_received(:all).twice
end
end

Expand Down

0 comments on commit edd9f24

Please sign in to comment.