From 8766efea906f57428ff175cae9355d4b03d499d9 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 30 Nov 2010 11:09:20 -0800 Subject: Maint: Make http handler code call the indirector through ".indirection" In commit 71ecad9904c8c48c023e90e5fbea5b26b180c9cf we removed the delegation from model class to indirection for the "find", "search", "destroy", and "expire" methods. When we did this we neglected to modify http handler code to call the indirector directly. This patch makes the appropriate changes to http handler code. --- lib/puppet/network/http/handler.rb | 6 +++--- spec/unit/network/http/handler_spec.rb | 36 ++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index 82238aa0a..fbd7d195f 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -103,7 +103,7 @@ module Puppet::Network::HTTP::Handler # Execute our find. def do_find(indirection_name, key, params, request, response) - unless result = model(indirection_name).find(key, params) + unless result = model(indirection_name).indirection.find(key, params) Puppet.info("Could not find #{indirection_name} for '#{key}'") return do_exception(response, "Could not find #{indirection_name} #{key}", 404) end @@ -120,7 +120,7 @@ module Puppet::Network::HTTP::Handler # Execute our search. def do_search(indirection_name, key, params, request, response) model = self.model(indirection_name) - result = model.search(key, params) + result = model.indirection.search(key, params) if result.nil? return do_exception(response, "Could not find instances in #{indirection_name} with '#{key}'", 404) @@ -134,7 +134,7 @@ module Puppet::Network::HTTP::Handler # Execute our destroy. def do_destroy(indirection_name, key, params, request, response) - result = model(indirection_name).destroy(key, params) + result = model(indirection_name).indirection.destroy(key, params) return_yaml_response(response, result) end diff --git a/spec/unit/network/http/handler_spec.rb b/spec/unit/network/http/handler_spec.rb index 16f1b5349..9dddc9962 100755 --- a/spec/unit/network/http/handler_spec.rb +++ b/spec/unit/network/http/handler_spec.rb @@ -46,6 +46,8 @@ describe Puppet::Network::HTTP::Handler do @request.stubs(:[]).returns "foo" @response = stub('http response') @model_class = stub('indirected model class') + @indirection = stub('indirection') + @model_class.stubs(:indirection).returns(@indirection) @result = stub 'result', :render => "mytext" @@ -126,7 +128,7 @@ describe Puppet::Network::HTTP::Handler do describe "when finding a model instance" do before do - @model_class.stubs(:find).returns @result + @indirection.stubs(:find).returns @result Puppet::Indirector::Indirection.expects(:instance).with(:my_handler).returns( stub "indirection", :model => @model_class ) @format = stub 'format', :suitable? => true, :mime => "text/format", :name => "format" @@ -141,14 +143,14 @@ describe Puppet::Network::HTTP::Handler do end it "should use the escaped request key" do - @model_class.expects(:find).with do |key, args| + @indirection.expects(:find).with do |key, args| key == "my_result" end.returns @result @handler.do_find("my_handler", "my_result", {}, @request, @response) end it "should use a common method for determining the request parameters" do - @model_class.expects(:find).with do |key, args| + @indirection.expects(:find).with do |key, args| args[:foo] == :baz and args[:bar] == :xyzzy end.returns @result @handler.do_find("my_handler", "my_result", {:foo => :baz, :bar => :xyzzy}, @request, @response) @@ -200,20 +202,20 @@ describe Puppet::Network::HTTP::Handler do @model_instance.expects(:render).returns "my_rendered_object" @handler.expects(:set_response).with { |response, body, status| body == "my_rendered_object" } - @model_class.stubs(:find).returns(@model_instance) + @indirection.stubs(:find).returns(@model_instance) @handler.do_find("my_handler", "my_result", {}, @request, @response) end it "should return a 404 when no model instance can be found" do @model_class.stubs(:name).returns "my name" @handler.expects(:set_response).with { |response, body, status| status == 404 } - @model_class.stubs(:find).returns(nil) + @indirection.stubs(:find).returns(nil) @handler.do_find("my_handler", "my_result", {}, @request, @response) end it "should write a log message when no model instance can be found" do @model_class.stubs(:name).returns "my name" - @model_class.stubs(:find).returns(nil) + @indirection.stubs(:find).returns(nil) Puppet.expects(:info).with("Could not find my_handler for 'my_result'") @@ -226,7 +228,7 @@ describe Puppet::Network::HTTP::Handler do @handler.expects(:format_to_use).returns(@oneformat) @model_instance.expects(:render).with(@oneformat).returns "my_rendered_object" - @model_class.stubs(:find).returns(@model_instance) + @indirection.stubs(:find).returns(@model_instance) @handler.do_find("my_handler", "my_result", {}, @request, @response) end end @@ -240,7 +242,7 @@ describe Puppet::Network::HTTP::Handler do @result = [@result1, @result2] @model_class.stubs(:render_multiple).returns "my rendered instances" - @model_class.stubs(:search).returns(@result) + @indirection.stubs(:search).returns(@result) @format = stub 'format', :suitable? => true, :mime => "text/format", :name => "format" Puppet::Network::FormatHandler.stubs(:format).returns @format @@ -254,14 +256,14 @@ describe Puppet::Network::HTTP::Handler do end it "should use a common method for determining the request parameters" do - @model_class.expects(:search).with do |key, args| + @indirection.expects(:search).with do |key, args| args[:foo] == :baz and args[:bar] == :xyzzy end.returns @result @handler.do_search("my_handler", "my_result", {:foo => :baz, :bar => :xyzzy}, @request, @response) end it "should use the default status when a model search call succeeds" do - @model_class.stubs(:search).returns(@result) + @indirection.stubs(:search).returns(@result) @handler.do_search("my_handler", "my_result", {}, @request, @response) end @@ -275,7 +277,7 @@ describe Puppet::Network::HTTP::Handler do it "should return a list of serialized objects when a model search call succeeds" do @handler.expects(:accept_header).with(@request).returns "one,two" - @model_class.stubs(:search).returns(@result) + @indirection.stubs(:search).returns(@result) @model_class.expects(:render_multiple).with(@oneformat, @result).returns "my rendered instances" @@ -285,7 +287,7 @@ describe Puppet::Network::HTTP::Handler do it "should return [] when searching returns an empty array" do @handler.expects(:accept_header).with(@request).returns "one,two" - @model_class.stubs(:search).returns([]) + @indirection.stubs(:search).returns([]) @model_class.expects(:render_multiple).with(@oneformat, []).returns "[]" @@ -296,7 +298,7 @@ describe Puppet::Network::HTTP::Handler do it "should return a 404 when searching returns nil" do @model_class.stubs(:name).returns "my name" @handler.expects(:set_response).with { |response, body, status| status == 404 } - @model_class.stubs(:search).returns(nil) + @indirection.stubs(:search).returns(nil) @handler.do_search("my_handler", "my_result", {}, @request, @response) end end @@ -306,7 +308,7 @@ describe Puppet::Network::HTTP::Handler do Puppet::Indirector::Indirection.expects(:instance).with(:my_handler).returns( stub "indirection", :model => @model_class ) @result = stub 'result', :render => "the result" - @model_class.stubs(:destroy).returns @result + @indirection.stubs(:destroy).returns @result end it "should use the indirection request to find the model" do @@ -314,14 +316,14 @@ describe Puppet::Network::HTTP::Handler do end it "should use the escaped request key to destroy the instance in the model" do - @model_class.expects(:destroy).with do |key, args| + @indirection.expects(:destroy).with do |key, args| key == "foo bar" end @handler.do_destroy("my_handler", "foo bar", {}, @request, @response) end it "should use a common method for determining the request parameters" do - @model_class.expects(:destroy).with do |key, args| + @indirection.expects(:destroy).with do |key, args| args[:foo] == :baz and args[:bar] == :xyzzy end @handler.do_destroy("my_handler", "my_result", {:foo => :baz, :bar => :xyzzy}, @request, @response) @@ -334,7 +336,7 @@ describe Puppet::Network::HTTP::Handler do it "should return a yaml-encoded result when a model destroy call succeeds" do @result = stub 'result', :to_yaml => "the result" - @model_class.expects(:destroy).returns(@result) + @indirection.expects(:destroy).returns(@result) @handler.expects(:set_response).with { |response, body, status| body == "the result" } -- cgit