Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CollectionDecorator#respond_to? for non AR collections #920

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading