diff options
author | jkeiser <jkeiser@opscode.com> | 2013-01-20 22:19:57 -0800 |
---|---|---|
committer | jkeiser <jkeiser@opscode.com> | 2013-01-20 22:19:57 -0800 |
commit | 0d5fc37486af0881429a0d60d2a407e9698a28d4 (patch) | |
tree | 7118527cd1aaeafe3c575cf7aa6f0da52a0f78b5 /lib/chef_zero/rest_base.rb | |
parent | e20a72a1eb57d8f0fb25e8c253478608fa09a8a4 (diff) | |
download | chef-zero-0d5fc37486af0881429a0d60d2a407e9698a28d4.tar.gz |
Add support for request/response verification to rspec api
Diffstat (limited to 'lib/chef_zero/rest_base.rb')
-rw-r--r-- | lib/chef_zero/rest_base.rb | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/chef_zero/rest_base.rb b/lib/chef_zero/rest_base.rb index bffcc35..1fa3f15 100644 --- a/lib/chef_zero/rest_base.rb +++ b/lib/chef_zero/rest_base.rb @@ -14,20 +14,19 @@ module ChefZero server.data end - def call(env) - rest_path = env['PATH_INFO'].split('/').select { |part| part != "" } - method = env['REQUEST_METHOD'].downcase.to_sym + def call(request) + method = request.method.downcase.to_sym if !self.respond_to?(method) accept_methods = [:get, :put, :post, :delete].select { |m| self.respond_to?(m) } accept_methods_str = accept_methods.map { |m| m.to_s.upcase }.join(', ') return [405, {"Content-Type" => "text/plain", "Allow" => accept_methods_str}, "Bad request method for '#{env['REQUEST_PATH']}': #{env['REQUEST_METHOD']}"] end - if json_only && !env['HTTP_ACCEPT'].split(';').include?('application/json') + if json_only && !request.env['HTTP_ACCEPT'].split(';').include?('application/json') return [406, {"Content-Type" => "text/plain"}, "Must accept application/json"] end # Dispatch to get()/post()/put()/delete() begin - self.send(method, RestRequest.new(env)) + self.send(method, request) rescue RestErrorResponse => e error(e.response_code, e.error) end |