diff options
author | Tim Hinderliter <tim@opscode.com> | 2010-11-24 13:29:14 -0800 |
---|---|---|
committer | Seth Falcon <seth@opscode.com> | 2010-11-24 15:22:17 -0800 |
commit | eee11a47b7263f9d771683d160eb3c68208ce9ae (patch) | |
tree | 2b5a5465353bd01dd7479a719965a51f7980b19b | |
parent | 9dca1e9e0cb9aefc6538fd98af9d57df5ac9d8c0 (diff) | |
download | chef-eee11a47b7263f9d771683d160eb3c68208ce9ae.tar.gz |
More fixes for CHEF-1292: updated comments, refactored feature tests. Added
some require's
-rw-r--r-- | chef-server-api/app/controllers/application.rb | 13 | ||||
-rw-r--r-- | chef/lib/chef/json.rb | 1 | ||||
-rw-r--r-- | chef/lib/chef/provider/deploy/revision.rb | 7 | ||||
-rw-r--r-- | chef/lib/chef/shef.rb | 17 | ||||
-rw-r--r-- | chef/lib/chef/shef/ext.rb | 1 | ||||
-rw-r--r-- | features/api/nodes/deep_node_show_save.feature | 7 | ||||
-rw-r--r-- | features/steps/fixture_steps.rb | 11 | ||||
-rw-r--r-- | features/steps/response_steps.rb | 30 |
8 files changed, 67 insertions, 20 deletions
diff --git a/chef-server-api/app/controllers/application.rb b/chef-server-api/app/controllers/application.rb index 0e2db2901e..7141bf91e5 100644 --- a/chef-server-api/app/controllers/application.rb +++ b/chef-server-api/app/controllers/application.rb @@ -119,13 +119,18 @@ class Application < Merb::Controller available_recipes end - # Use Chef's JSON conversion library for sending JSON instead of the - # default Merb, which calls obj.to_json. Fixes CHEF-1292/PL-538. + # Fix CHEF-1292/PL-538; cause Merb to pass the max nesting constant into + # obj.to_json, which it calls by default based on the original request's + # accept headers and the type passed into Merb::Controller.display + # + # TODO: tim, 2010-11-24: would be nice to instead have Merb call + # Chef::JSON.to_json, instead of obj.to_json, but changing that + # behavior is convoluted in Merb. This override is assuming that + # Merb is eventually calling obj.to_json, which takes the :max_nesting + # option. override! :display def display(obj) super(obj, nil, {:max_nesting => Chef::JSON::JSON_MAX_NESTING}) - #super.display(Chef::JSON.to_json(obj)) - #Chef::JSON.to_json(obj) end end diff --git a/chef/lib/chef/json.rb b/chef/lib/chef/json.rb index f83700dc40..24020356ba 100644 --- a/chef/lib/chef/json.rb +++ b/chef/lib/chef/json.rb @@ -41,7 +41,6 @@ class Chef end def to_json(obj, opts = nil) - #::JSON.generate(obj, opts_add_max_nesting(opts)) obj.to_json(opts_add_max_nesting(opts)) end diff --git a/chef/lib/chef/provider/deploy/revision.rb b/chef/lib/chef/provider/deploy/revision.rb index 18c2c03f8a..6b5848827a 100644 --- a/chef/lib/chef/provider/deploy/revision.rb +++ b/chef/lib/chef/provider/deploy/revision.rb @@ -1,6 +1,9 @@ # # Author:: Daniel DeLeo (<dan@kallistec.com>) +# Author:: Tim Hinderliter (<tim@opscode.com>) +# Author:: Seth Falcon (<seth@opscode.com>) # Copyright:: Copyright (c) 2009 Daniel DeLeo +# Copyright:: Copyright (c) 2010 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +19,10 @@ # limitations under the License. # +require 'chef/provider' +require 'chef/provider/deploy' +require 'chef/json' + class Chef class Provider class Deploy diff --git a/chef/lib/chef/shef.rb b/chef/lib/chef/shef.rb index bcab49fb4b..2710e7fbb1 100644 --- a/chef/lib/chef/shef.rb +++ b/chef/lib/chef/shef.rb @@ -15,17 +15,18 @@ # limitations under the License. # -require "singleton" -require "pp" -require "etc" -require "mixlib/cli" +require 'singleton' +require 'pp' +require 'etc' +require 'mixlib/cli' require 'chef/version' -require "chef/client" -require "chef/config" +require 'chef/client' +require 'chef/config' -require "chef/shef/shef_session" -require "chef/shef/ext" +require 'chef/shef/shef_session' +require 'chef/shef/ext' +require 'chef/json' # = Shef # Shef is Chef in an IRB session. Shef can interact with a Chef server via the diff --git a/chef/lib/chef/shef/ext.rb b/chef/lib/chef/shef/ext.rb index 77c63cfc07..6c5116f4a5 100644 --- a/chef/lib/chef/shef/ext.rb +++ b/chef/lib/chef/shef/ext.rb @@ -23,6 +23,7 @@ require 'chef/version' require 'chef/shef/shef_session' require 'chef/shef/model_wrapper' require 'chef/shef/shef_rest' +require 'chef/json' module Shef module Extensions diff --git a/features/api/nodes/deep_node_show_save.feature b/features/api/nodes/deep_node_show_save.feature index 309b7c4237..71290434b8 100644 --- a/features/api/nodes/deep_node_show_save.feature +++ b/features/api/nodes/deep_node_show_save.feature @@ -1,13 +1,14 @@ -@api @api_nodes @nodes_show @json_recusion @pl_538 +@api @api_nodes @nodes_show @json_recusion @pl_538 @chef_1292 Feature: Save and show a node with deep structure via the API In order to verify that I can save and show very deep structure in a node object As a Developer I want to show the details for a specific node - Scenario: Show a really deep node + Scenario: Show a deeply nested node Given I am an administrator And a 'node' named 'really_deep_node' exists When I 'GET' the path '/nodes/really_deep_node' Then I should not get an exception And the inflated response should respond to 'name' with 'really_deep_node' - And the inflated response should respond to 'deep_array' and match '.*10,\"really_deep_string\".*' as json + And the 'deep_array' component has depth of '50' levels + And the 'deep_hash' component has depth of '50' levels diff --git a/features/steps/fixture_steps.rb b/features/steps/fixture_steps.rb index 539b866455..fb1b6a2cbb 100644 --- a/features/steps/fixture_steps.rb +++ b/features/steps/fixture_steps.rb @@ -194,17 +194,20 @@ Before do end, 'really_deep_node' => Proc.new do array = [] + hash = {} max_levels = 50 - num_level = 0 - begin - array = [num_level, "really_deep_string", array] + + max_levels.times do |num_level| + array = [num_level, "really_deep_string_in_array", array] + hash = {"really_deep_string_in_hash_#{num_level}" => hash} num_level += 1 - end while num_level < max_levels + end n = Chef::Node.new n.name 'really_deep_node' n.run_list << "deep_node_recipe" n.deep_array = array + n.deep_hash = hash n end }, diff --git a/features/steps/response_steps.rb b/features/steps/response_steps.rb index 99e627ed2d..989099d78d 100644 --- a/features/steps/response_steps.rb +++ b/features/steps/response_steps.rb @@ -1,3 +1,28 @@ + +# Walk array/hash to determine maximum depth. A scalar (anything but an +# Array or Hash) has depth 0. +def count_structure_levels(obj) + if obj.respond_to?(:keys) + # empty hash also has depth 0. + max_depth = 0 + obj.keys.each do |key| + child_levels = 1 + count_structure_levels(obj[key]) + max_depth = [max_depth, child_levels].max + end + max_depth + elsif obj.is_a?(Array) + # empty array also has depth 0. + max_depth = 0 + obj.each do |child| + child_levels = 1 + count_structure_levels(child) + max_depth = [max_depth, child_levels].max + end + max_depth + else + 0 + end +end + Then /^I should get a '(.+)' exception$/ do |exception| self.exception.message.to_s.should == exception end @@ -149,6 +174,11 @@ Then /^the inflated response should respond to '(.+)' and match '(.+)' as json$/ Chef::JSON.to_json(self.inflated_response.to_hash[method]).should =~ /#{regex}/m end +#And the 'deep_array' component has depth of '50' levels +Then /^the '(.+)' component has depth of '(.+)' levels$/ do |method, levels| + count_structure_levels(self.inflated_response.to_hash[method]).should == levels.to_i +end + Then /^the fields in the inflated response should match the '(.+)'$/ do |stash_name| self.inflated_response.each do |k,v| unless k =~ /^_/ || k == 'couchrest-type' |