diff --git a/lib/draper/query_methods.rb b/lib/draper/query_methods.rb index abeeda81..1f9c6019 100644 --- a/lib/draper/query_methods.rb +++ b/lib/draper/query_methods.rb @@ -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 diff --git a/spec/draper/query_methods_spec.rb b/spec/draper/query_methods_spec.rb index 7849654d..4bafffdb 100644 --- a/spec/draper/query_methods_spec.rb +++ b/spec/draper/query_methods_spec.rb @@ -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) }