Skip to content

Commit

Permalink
Fix CollectionDecorator#respond_to? for non AR collections
Browse files Browse the repository at this point in the history
  • Loading branch information
catks authored and Alexander-Senko committed Aug 30, 2024
1 parent 2836ea7 commit 9daf3ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/draper/query_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module QueryMethods
end

def respond_to_missing?(method, include_private = false)
strategy.allowed?(method) || super
object.respond_to?(method) && strategy.allowed?(method) || super
end

private
Expand Down
10 changes: 10 additions & 0 deletions spec/draper/query_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,24 @@ module Draper
context 'when strategy allows collection to call the method' do
before do
allow(fake_strategy).to receive(:allowed?).with(:some_query_method).and_return(true)
allow(collection).to receive(:respond_to?).with(:some_query_method).and_return(true)
end

it { is_expected.to eq(true) }

context 'and collection does not implement the method' do
before do
allow(collection).to receive(:respond_to?).with(:some_query_method).and_return(false)
end

it { is_expected.to eq(false) }
end
end

context 'when strategy does not allow collection to call the method' do
before do
allow(fake_strategy).to receive(:allowed?).with(:some_query_method).and_return(false)
allow(collection).to receive(:respond_to?).with(:some_query_method).and_return(true)
end

it { is_expected.to eq(false) }
Expand Down

0 comments on commit 9daf3ac

Please sign in to comment.