microwave 1.0.4 → 11.400.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. data/CONTRIBUTING.md +155 -0
  2. data/README.md +89 -0
  3. data/Rakefile +2 -2
  4. data/bin/chef-apply +25 -0
  5. data/bin/chef-shell +34 -0
  6. data/bin/chef-solo +0 -2
  7. data/bin/shef +6 -5
  8. data/lib/chef.rb +2 -4
  9. data/spec/data/big_json.json +2 -1
  10. data/spec/data/big_json_plus_one.json +2 -1
  11. data/spec/data/cookbooks/chefignore +2 -0
  12. data/spec/data/cookbooks/openldap/attributes/default.rb +10 -9
  13. data/spec/data/cookbooks/openldap/attributes/smokey.rb +1 -1
  14. data/spec/data/git_bundles/sinatra-test-app-with-callback-files.gitbundle +0 -0
  15. data/spec/data/git_bundles/sinatra-test-app-with-symlinks.gitbundle +0 -0
  16. data/spec/data/git_bundles/sinatra-test-app.gitbundle +0 -0
  17. data/spec/data/lwrp/providers/inline_compiler.rb +26 -0
  18. data/spec/data/nodes/default.rb +3 -3
  19. data/spec/data/nodes/test.example.com.rb +3 -3
  20. data/spec/data/nodes/test.rb +3 -3
  21. data/spec/data/partial_one.erb +1 -0
  22. data/spec/data/run_context/cookbooks/circular-dep1/attributes/default.rb +4 -0
  23. data/spec/data/run_context/cookbooks/circular-dep1/definitions/circular_dep1_res.rb +1 -0
  24. data/spec/data/run_context/cookbooks/circular-dep1/libraries/lib.rb +2 -0
  25. data/spec/data/run_context/cookbooks/circular-dep1/metadata.rb +2 -0
  26. data/spec/data/run_context/cookbooks/circular-dep1/providers/provider.rb +1 -0
  27. data/spec/data/run_context/cookbooks/circular-dep1/recipes/default.rb +0 -0
  28. data/spec/data/run_context/cookbooks/circular-dep1/resources/resource.rb +1 -0
  29. data/spec/data/run_context/cookbooks/circular-dep2/attributes/default.rb +3 -0
  30. data/spec/data/run_context/cookbooks/circular-dep2/definitions/circular_dep2_res.rb +1 -0
  31. data/spec/data/run_context/cookbooks/circular-dep2/libraries/lib.rb +2 -0
  32. data/spec/data/run_context/cookbooks/circular-dep2/metadata.rb +2 -0
  33. data/spec/data/run_context/cookbooks/circular-dep2/providers/provider.rb +1 -0
  34. data/spec/data/run_context/cookbooks/circular-dep2/recipes/default.rb +0 -0
  35. data/spec/data/run_context/cookbooks/circular-dep2/resources/resource.rb +1 -0
  36. data/spec/data/run_context/cookbooks/dependency1/attributes/aa_first.rb +2 -0
  37. data/spec/data/run_context/cookbooks/dependency1/attributes/default.rb +2 -0
  38. data/spec/data/run_context/cookbooks/dependency1/attributes/zz_last.rb +3 -0
  39. data/spec/data/run_context/cookbooks/dependency1/definitions/dependency1_res.rb +1 -0
  40. data/spec/data/run_context/cookbooks/dependency1/libraries/lib.rb +2 -0
  41. data/spec/data/run_context/cookbooks/dependency1/providers/provider.rb +1 -0
  42. data/spec/data/run_context/cookbooks/dependency1/recipes/default.rb +0 -0
  43. data/spec/data/run_context/cookbooks/dependency1/resources/resource.rb +1 -0
  44. data/spec/data/run_context/cookbooks/dependency2/attributes/default.rb +3 -0
  45. data/spec/data/run_context/cookbooks/dependency2/definitions/dependency2_res.rb +1 -0
  46. data/spec/data/run_context/cookbooks/dependency2/libraries/lib.rb +2 -0
  47. data/spec/data/run_context/cookbooks/dependency2/providers/provider.rb +1 -0
  48. data/spec/data/run_context/cookbooks/dependency2/recipes/default.rb +0 -0
  49. data/spec/data/run_context/cookbooks/dependency2/resources/resource.rb +1 -0
  50. data/spec/data/run_context/cookbooks/no-default-attr/attributes/server.rb +3 -0
  51. data/spec/data/run_context/cookbooks/no-default-attr/definitions/no_default-attr_res.rb +1 -0
  52. data/spec/data/run_context/cookbooks/no-default-attr/providers/provider.rb +1 -0
  53. data/spec/data/run_context/cookbooks/no-default-attr/recipes/default.rb +0 -0
  54. data/spec/data/run_context/cookbooks/no-default-attr/resources/resource.rb +1 -0
  55. data/spec/data/run_context/cookbooks/test-with-circular-deps/attributes/default.rb +3 -0
  56. data/spec/data/run_context/cookbooks/test-with-circular-deps/definitions/test_with-circular-deps_res.rb +1 -0
  57. data/spec/data/run_context/cookbooks/test-with-circular-deps/libraries/lib.rb +2 -0
  58. data/spec/data/run_context/cookbooks/test-with-circular-deps/metadata.rb +2 -0
  59. data/spec/data/run_context/cookbooks/test-with-circular-deps/providers/provider.rb +1 -0
  60. data/spec/data/run_context/cookbooks/test-with-circular-deps/recipes/default.rb +0 -0
  61. data/spec/data/run_context/cookbooks/test-with-circular-deps/resources/resource.rb +1 -0
  62. data/spec/data/run_context/cookbooks/test-with-deps/attributes/default.rb +3 -0
  63. data/spec/data/run_context/cookbooks/test-with-deps/definitions/test_with-deps_res.rb +1 -0
  64. data/spec/data/run_context/cookbooks/test-with-deps/libraries/lib.rb +1 -0
  65. data/spec/data/run_context/cookbooks/test-with-deps/metadata.rb +3 -0
  66. data/spec/data/run_context/cookbooks/test-with-deps/providers/provider.rb +1 -0
  67. data/spec/data/run_context/cookbooks/test-with-deps/recipes/default.rb +0 -0
  68. data/spec/data/run_context/cookbooks/test-with-deps/recipes/server.rb +0 -0
  69. data/spec/data/run_context/cookbooks/test-with-deps/resources/resource.rb +1 -0
  70. data/spec/data/run_context/cookbooks/test/attributes/default.rb +0 -0
  71. data/spec/data/run_context/cookbooks/test/attributes/george.rb +1 -1
  72. data/spec/data/run_context/cookbooks/test/definitions/test_res.rb +1 -0
  73. data/spec/data/run_context/cookbooks/test/providers/provider.rb +1 -0
  74. data/spec/data/run_context/cookbooks/test/resources/resource.rb +1 -0
  75. data/spec/data/shef-config.rb +10 -0
  76. data/spec/functional/dsl/registry_helper_spec.rb +63 -0
  77. data/spec/functional/knife/cookbook_delete_spec.rb +0 -2
  78. data/spec/functional/knife/exec_spec.rb +4 -6
  79. data/spec/functional/knife/smoke_test.rb +34 -0
  80. data/spec/functional/knife/ssh_spec.rb +64 -3
  81. data/spec/functional/resource/cookbook_file_spec.rb +33 -2
  82. data/spec/functional/resource/deploy_revision_spec.rb +515 -0
  83. data/spec/functional/resource/directory_spec.rb +4 -0
  84. data/spec/functional/resource/file_spec.rb +56 -22
  85. data/spec/functional/resource/link_spec.rb +12 -10
  86. data/spec/functional/resource/registry_spec.rb +572 -0
  87. data/spec/functional/resource/remote_directory_spec.rb +142 -36
  88. data/spec/functional/resource/remote_file_spec.rb +28 -3
  89. data/spec/functional/resource/template_spec.rb +23 -2
  90. data/spec/functional/run_lock_spec.rb +238 -0
  91. data/spec/functional/shell_spec.rb +101 -0
  92. data/spec/functional/tiny_server_spec.rb +5 -4
  93. data/spec/functional/win32/registry_helper_spec.rb +632 -0
  94. data/spec/functional/win32/security_spec.rb +37 -0
  95. data/spec/spec_helper.rb +15 -3
  96. data/spec/stress/win32/security_spec.rb +5 -5
  97. data/spec/support/chef_helpers.rb +14 -3
  98. data/spec/support/lib/chef/resource/cat.rb +3 -5
  99. data/spec/support/lib/chef/resource/one_two_three_four.rb +8 -10
  100. data/spec/support/lib/chef/resource/zen_master.rb +8 -10
  101. data/spec/support/matchers/leak.rb +1 -1
  102. data/spec/support/platform_helpers.rb +18 -0
  103. data/spec/support/shared/functional/directory_resource.rb +85 -23
  104. data/spec/support/shared/functional/file_resource.rb +198 -53
  105. data/spec/support/shared/functional/securable_resource.rb +140 -105
  106. data/spec/support/shared/functional/securable_resource_with_reporting.rb +375 -0
  107. data/spec/support/shared/unit/file_system_support.rb +110 -0
  108. data/spec/support/shared/unit/platform_introspector.rb +162 -0
  109. data/spec/tiny_server.rb +29 -10
  110. data/spec/unit/api_client/registration_spec.rb +172 -0
  111. data/spec/unit/api_client_spec.rb +156 -103
  112. data/spec/unit/application/apply.rb +84 -0
  113. data/spec/unit/application/knife_spec.rb +5 -0
  114. data/spec/unit/application_spec.rb +57 -2
  115. data/spec/unit/chef_fs/diff_spec.rb +329 -0
  116. data/spec/unit/chef_fs/file_pattern_spec.rb +526 -0
  117. data/spec/unit/chef_fs/file_system/chef_server_root_dir_spec.rb +237 -0
  118. data/spec/unit/chef_fs/file_system/cookbooks_dir_spec.rb +568 -0
  119. data/spec/unit/chef_fs/file_system/data_bags_dir_spec.rb +220 -0
  120. data/spec/unit/chef_fs/file_system_spec.rb +136 -0
  121. data/spec/unit/client_spec.rb +188 -16
  122. data/spec/unit/config_spec.rb +54 -4
  123. data/spec/unit/cookbook/chefignore_spec.rb +2 -1
  124. data/spec/unit/cookbook/syntax_check_spec.rb +48 -109
  125. data/spec/unit/cookbook_loader_spec.rb +153 -91
  126. data/spec/unit/cookbook_manifest_spec.rb +81 -81
  127. data/spec/unit/cookbook_spec.rb +3 -20
  128. data/spec/unit/cookbook_version_spec.rb +23 -122
  129. data/spec/unit/digester_spec.rb +50 -0
  130. data/spec/unit/dsl/data_query_spec.rb +66 -0
  131. data/spec/unit/dsl/platform_introspection_spec.rb +130 -0
  132. data/spec/unit/dsl/regsitry_helper_spec.rb +55 -0
  133. data/spec/unit/encrypted_data_bag_item_spec.rb +126 -10
  134. data/spec/unit/environment_spec.rb +0 -130
  135. data/spec/unit/exceptions_spec.rb +2 -3
  136. data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +23 -3
  137. data/spec/unit/json_compat_spec.rb +69 -0
  138. data/spec/unit/knife/bootstrap_spec.rb +81 -28
  139. data/spec/unit/knife/client_reregister_spec.rb +23 -22
  140. data/spec/unit/knife/configure_spec.rb +29 -26
  141. data/spec/unit/knife/cookbook_metadata_spec.rb +11 -4
  142. data/spec/unit/knife/cookbook_site_install_spec.rb +12 -2
  143. data/spec/unit/knife/cookbook_test_spec.rb +1 -0
  144. data/spec/unit/knife/cookbook_upload_spec.rb +41 -2
  145. data/spec/unit/knife/core/bootstrap_context_spec.rb +8 -1
  146. data/spec/unit/knife/core/ui_spec.rb +156 -7
  147. data/spec/unit/knife/data_bag_create_spec.rb +14 -0
  148. data/spec/unit/knife/data_bag_edit_spec.rb +14 -4
  149. data/spec/unit/knife/data_bag_from_file_spec.rb +17 -5
  150. data/spec/unit/knife/data_bag_show_spec.rb +11 -4
  151. data/spec/unit/knife/index_rebuild_spec.rb +96 -33
  152. data/spec/unit/knife/knife_help.rb +7 -7
  153. data/spec/unit/knife/node_run_list_remove_spec.rb +2 -1
  154. data/spec/unit/knife/ssh_spec.rb +121 -15
  155. data/spec/unit/knife/status_spec.rb +2 -2
  156. data/spec/unit/knife/user_create_spec.rb +86 -0
  157. data/spec/unit/knife/user_delete_spec.rb +39 -0
  158. data/spec/unit/knife/user_edit_spec.rb +42 -0
  159. data/spec/unit/knife/user_list_spec.rb +32 -0
  160. data/spec/unit/knife/user_reregister_spec.rb +53 -0
  161. data/spec/unit/knife/user_show_spec.rb +41 -0
  162. data/spec/unit/knife_spec.rb +53 -0
  163. data/spec/unit/lwrp_spec.rb +59 -17
  164. data/spec/unit/mixin/checksum_spec.rb +2 -2
  165. data/spec/unit/mixin/deep_merge_spec.rb +56 -491
  166. data/spec/unit/mixin/deprecation_spec.rb +23 -0
  167. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +6 -1
  168. data/spec/unit/mixin/params_validate_spec.rb +4 -2
  169. data/spec/unit/mixin/securable_spec.rb +5 -3
  170. data/spec/unit/mixin/template_spec.rb +119 -0
  171. data/spec/unit/node/attribute_spec.rb +272 -137
  172. data/spec/unit/node/immutable_collections_spec.rb +139 -0
  173. data/spec/unit/node_spec.rb +411 -339
  174. data/spec/unit/platform_spec.rb +8 -8
  175. data/spec/unit/provider/breakpoint_spec.rb +8 -8
  176. data/spec/unit/provider/cookbook_file_spec.rb +4 -8
  177. data/spec/unit/provider/deploy/revision_spec.rb +2 -8
  178. data/spec/unit/provider/deploy_spec.rb +6 -40
  179. data/spec/unit/provider/directory_spec.rb +103 -68
  180. data/spec/unit/provider/erl_call_spec.rb +0 -2
  181. data/spec/unit/provider/file_spec.rb +69 -59
  182. data/spec/unit/provider/git_spec.rb +0 -10
  183. data/spec/unit/provider/group/groupadd_spec.rb +1 -1
  184. data/spec/unit/provider/group/usermod_spec.rb +2 -2
  185. data/spec/unit/provider/http_request_spec.rb +28 -69
  186. data/spec/unit/provider/ifconfig_spec.rb +2 -2
  187. data/spec/unit/provider/link_spec.rb +1 -1
  188. data/spec/unit/provider/ohai_spec.rb +4 -4
  189. data/spec/unit/provider/package/apt_spec.rb +0 -1
  190. data/spec/unit/provider/package/ips_spec.rb +0 -1
  191. data/spec/unit/provider/package/rubygems_spec.rb +0 -18
  192. data/spec/unit/provider/package/yum_spec.rb +79 -15
  193. data/spec/unit/provider/package_spec.rb +7 -5
  194. data/spec/unit/provider/registry_key_spec.rb +269 -0
  195. data/spec/unit/provider/remote_directory_spec.rb +24 -7
  196. data/spec/unit/provider/remote_file_spec.rb +36 -0
  197. data/spec/unit/provider/route_spec.rb +3 -6
  198. data/spec/unit/provider/ruby_block_spec.rb +8 -0
  199. data/spec/unit/provider/service/arch_service_spec.rb +4 -4
  200. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  201. data/spec/unit/provider/service/freebsd_service_spec.rb +4 -4
  202. data/spec/unit/provider/service/init_service_spec.rb +26 -3
  203. data/spec/unit/provider/service/insserv_service_spec.rb +1 -1
  204. data/spec/unit/provider/service/invokercd_service_spec.rb +3 -3
  205. data/spec/unit/provider/service/redhat_spec.rb +1 -1
  206. data/spec/unit/provider/service/simple_service_spec.rb +3 -3
  207. data/spec/unit/provider/service/upstart_service_spec.rb +7 -7
  208. data/spec/unit/provider/service_spec.rb +2 -2
  209. data/spec/unit/provider/subversion_spec.rb +1 -1
  210. data/spec/unit/provider/template_spec.rb +35 -11
  211. data/spec/unit/provider/user/dscl_spec.rb +57 -31
  212. data/spec/unit/provider/user_spec.rb +7 -16
  213. data/spec/unit/provider_spec.rb +4 -3
  214. data/spec/unit/recipe_spec.rb +10 -8
  215. data/spec/unit/registry_helper_spec.rb +376 -0
  216. data/spec/unit/resource/log_spec.rb +9 -0
  217. data/spec/unit/resource/registry_key_spec.rb +171 -0
  218. data/spec/unit/resource/remote_file_spec.rb +21 -23
  219. data/spec/unit/resource/ruby_block_spec.rb +7 -3
  220. data/spec/unit/resource/service_spec.rb +11 -0
  221. data/spec/unit/resource_spec.rb +27 -4
  222. data/spec/unit/rest/auth_credentials_spec.rb +2 -14
  223. data/spec/unit/rest_spec.rb +122 -187
  224. data/spec/unit/run_context/cookbook_compiler_spec.rb +181 -0
  225. data/spec/unit/run_context_spec.rb +18 -4
  226. data/spec/unit/run_list_spec.rb +0 -209
  227. data/spec/unit/run_lock_spec.rb +37 -0
  228. data/spec/unit/runner_spec.rb +101 -2
  229. data/spec/unit/scan_access_control_spec.rb +4 -4
  230. data/spec/unit/{shef → shell}/model_wrapper_spec.rb +5 -5
  231. data/spec/unit/{shef/shef_ext_spec.rb → shell/shell_ext_spec.rb} +21 -21
  232. data/spec/unit/{shef/shef_session_spec.rb → shell/shell_session_spec.rb} +12 -12
  233. data/spec/unit/shell_out_spec.rb +18 -0
  234. data/spec/unit/{shef_spec.rb → shell_spec.rb} +20 -20
  235. data/spec/unit/user_spec.rb +255 -0
  236. metadata +162 -157
  237. data/README.rdoc +0 -177
  238. data/spec/unit/certificate_spec.rb +0 -76
  239. data/spec/unit/checksum_cache_spec.rb +0 -209
  240. data/spec/unit/checksum_spec.rb +0 -94
  241. data/spec/unit/couchdb_spec.rb +0 -274
  242. data/spec/unit/index_queue_spec.rb +0 -391
  243. data/spec/unit/json_compat_spect.rb +0 -53
  244. data/spec/unit/mixin/language_spec.rb +0 -305
  245. data/spec/unit/openid_registration_spec.rb +0 -153
  246. data/spec/unit/solr_query/query_transform_spec.rb +0 -454
  247. data/spec/unit/solr_query/solr_http_request_spec.rb +0 -244
  248. data/spec/unit/solr_query_spec.rb +0 -203
  249. data/spec/unit/webui_user_spec.rb +0 -238
@@ -27,12 +27,12 @@ end
27
27
  describe Chef::Mixin::Checksum do
28
28
  before(:each) do
29
29
  @checksum_user = Chef::CMCCheck.new
30
- @cache = Chef::ChecksumCache.instance
30
+ @cache = Chef::Digester.instance
31
31
  @file = CHEF_SPEC_DATA + "/checksum/random.txt"
32
32
  @stat = mock("File::Stat", { :mtime => Time.at(0) })
33
33
  File.stub!(:stat).and_return(@stat)
34
34
  end
35
-
35
+
36
36
  it "gets the checksum of a file" do
37
37
  @checksum_user.checksum(@file).should == "09ee9c8cc70501763563bcf9c218d71b2fbf4186bf8e1e0da07f0f42c80a3394"
38
38
  end
@@ -36,14 +36,14 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do
36
36
  it "tests merging an hash w/array into blank hash" do
37
37
  hash_src = {'id' => '2'}
38
38
  hash_dst = {}
39
- @dm.deep_merge!(hash_src.dup, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
39
+ @dm.deep_merge!(hash_src.dup, hash_dst)
40
40
  hash_dst.should == hash_src
41
41
  end
42
42
 
43
43
  it "tests merging an hash w/array into blank hash" do
44
44
  hash_src = {'region' => {'id' => ['227', '2']}}
45
45
  hash_dst = {}
46
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
46
+ @dm.deep_merge!(hash_src, hash_dst)
47
47
  hash_dst.should == hash_src
48
48
  end
49
49
 
@@ -82,13 +82,6 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do
82
82
  hash_dst.should == {"property" => ["2","4","1","3"]}
83
83
  end
84
84
 
85
- it "tests hashes holding array (sorted)" do
86
- hash_src = {"property" => ["1","3"]}
87
- hash_dst = {"property" => ["2","4"]}
88
- @dm.deep_merge!(hash_src, hash_dst, {:sort_merged_arrays => true})
89
- hash_dst.should == {"property" => ["1","2","3","4"]}
90
- end
91
-
92
85
  it "tests hashes holding hashes holding arrays (array with duplicate elements is merged with dest then src" do
93
86
  hash_src = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["1", "4+"]}}
94
87
  hash_dst = {"property" => {"bedroom_count" => ["3", "2"], "bathroom_count" => ["2"]}}
@@ -103,13 +96,6 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do
103
96
  hash_dst.should == {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2","1","4+"]}}
104
97
  end
105
98
 
106
- it "tests hash holding hash holding array v string (string is NOT overwritten by array)" do
107
- hash_src = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["1", "4+"]}}
108
- hash_dst = {"property" => {"bedroom_count" => "3", "bathroom_count" => ["2"]}}
109
- @dm.deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true})
110
- hash_dst.should == {"property" => {"bedroom_count" => "3", "bathroom_count" => ["2","1","4+"]}}
111
- end
112
-
113
99
  it "tests hash holding hash holding string v array (array is overwritten by string)" do
114
100
  hash_src = {"property" => {"bedroom_count" => "3", "bathroom_count" => ["1", "4+"]}}
115
101
  hash_dst = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2"]}}
@@ -117,13 +103,6 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do
117
103
  hash_dst.should == {"property" => {"bedroom_count" => "3", "bathroom_count" => ["2","1","4+"]}}
118
104
  end
119
105
 
120
- it "tests hash holding hash holding string v array (array does NOT overwrite string)" do
121
- hash_src = {"property" => {"bedroom_count" => "3", "bathroom_count" => ["1", "4+"]}}
122
- hash_dst = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2"]}}
123
- @dm.deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true})
124
- hash_dst.should == {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2","1","4+"]}}
125
- end
126
-
127
106
  it "tests hash holding hash holding hash v array (array is overwritten by hash)" do
128
107
  hash_src = {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["1", "4+"]}}
129
108
  hash_dst = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2"]}}
@@ -131,13 +110,6 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do
131
110
  hash_dst.should == {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["2","1","4+"]}}
132
111
  end
133
112
 
134
- it "tests hash holding hash holding hash v array (array is NOT overwritten by hash)" do
135
- hash_src = {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["1", "4+"]}}
136
- hash_dst = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2"]}}
137
- @dm.deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true})
138
- hash_dst.should == {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2","1","4+"]}}
139
- end
140
-
141
113
  it "tests 3 hash layers holding integers (integers are overwritten by source)" do
142
114
  hash_src = {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["1", "4+"]}}
143
115
  hash_dst = {"property" => {"bedroom_count" => {"king_bed" => 2, "queen_bed" => 4}, "bathroom_count" => ["2"]}}
@@ -159,13 +131,6 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do
159
131
  hash_dst.should == {"property" => "1"}
160
132
  end
161
133
 
162
- it "tests 1 hash NOT overwriting 3 hash layers holding arrays of int" do
163
- hash_src = {"property" => "1"}
164
- hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
165
- @dm.deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true})
166
- hash_dst.should == {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
167
- end
168
-
169
134
  it "tests 3 hash layers holding arrays of int (arrays are merged) but second hash's array is overwritten" do
170
135
  hash_src = {"property" => {"bedroom_count" => {"king_bed" => [3], "queen_bed" => [1]}, "bathroom_count" => "1"}}
171
136
  hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
@@ -173,13 +138,6 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do
173
138
  hash_dst.should == {"property" => {"bedroom_count" => {"king_bed" => [2,3], "queen_bed" => [4,1]}, "bathroom_count" => "1"}}
174
139
  end
175
140
 
176
- it "tests 3 hash layers holding arrays of int (arrays are merged) but second hash's array is NOT overwritten" do
177
- hash_src = {"property" => {"bedroom_count" => {"king_bed" => [3], "queen_bed" => [1]}, "bathroom_count" => "1"}}
178
- hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
179
- @dm.deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true})
180
- hash_dst.should == {"property" => {"bedroom_count" => {"king_bed" => [2,3], "queen_bed" => [4,1]}, "bathroom_count" => ["2"]}}
181
- end
182
-
183
141
  it "tests 3 hash layers holding arrays of int, but one holds int. This one overwrites, but the rest merge" do
184
142
  hash_src = {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => [1]}, "bathroom_count" => ["1"]}}
185
143
  hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
@@ -215,31 +173,6 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do
215
173
  hash_dst.should == {"property" => {"bedroom_count" => {2=>3, "king_bed" => [3]}, "bathroom_count" => ["1"]}}
216
174
  end
217
175
 
218
- it "tests parameter management for knockout_prefix and overwrite unmergable" do
219
- hash_src = {"x" => 1}
220
- hash_dst = {"y" => 2}
221
-
222
- lambda {
223
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => ""})
224
- }.should raise_error(Chef::Mixin::DeepMerge::InvalidParameter)
225
-
226
- lambda {
227
- @dm.deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true, :knockout_prefix => ""})
228
- }.should raise_error(Chef::Mixin::DeepMerge::InvalidParameter)
229
-
230
- lambda {
231
- @dm.deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true, :knockout_prefix => @field_ko_prefix})
232
- }.should raise_error(Chef::Mixin::DeepMerge::InvalidParameter)
233
-
234
- lambda {
235
- @dm.deep_merge!(@dm.deep_merge!(hash_src, hash_dst))
236
- }.should_not raise_error(Chef::Mixin::DeepMerge::InvalidParameter)
237
-
238
- lambda {
239
- @dm.deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true})
240
- }.should_not raise_error(Chef::Mixin::DeepMerge::InvalidParameter)
241
- end
242
-
243
176
  it "tests hash holding arrays of arrays" do
244
177
  hash_src = {["1", "2", "3"] => ["1", "2"]}
245
178
  hash_dst = {["4", "5"] => ["3"]}
@@ -247,421 +180,27 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do
247
180
  hash_dst.should == {["1","2","3"] => ["1", "2"], ["4", "5"] => ["3"]}
248
181
  end
249
182
 
250
- it "tests merging of hash with blank hash, and make sure that source array split still functions" do
251
- hash_src = {'property' => {'bedroom_count' => ["1","2,3"]}}
252
- hash_dst = {}
253
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
254
- hash_dst.should == {'property' => {'bedroom_count' => ["1","2","3"]}}
255
- end
256
-
257
183
  it "tests merging of hash with blank hash, and make sure that source array split does not function when turned off" do
258
184
  hash_src = {'property' => {'bedroom_count' => ["1","2,3"]}}
259
185
  hash_dst = {}
260
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix})
186
+ @dm.deep_merge!(hash_src, hash_dst)
261
187
  hash_dst.should == {'property' => {'bedroom_count' => ["1","2,3"]}}
262
188
  end
263
189
 
264
- it "tests merging into a blank hash with overwrite_unmergeables turned on" do
190
+ it "tests merging into a blank hash" do
265
191
  hash_src = {"action"=>"browse", "controller"=>"results"}
266
192
  hash_dst = {}
267
- @dm.deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
268
- hash_dst.should == hash_src
269
- end
270
-
271
- # KNOCKOUT_PREFIX testing
272
- # the next few tests are looking for correct behavior from specific real-world params/session merges
273
- # using the custom modifiers built for param/session merges
274
-
275
- [nil, ","].each do |ko_split|
276
- it "tests typical params/session style hash with knockout_merge elements" do
277
- hash_src = {"property"=>{"bedroom_count"=>[@field_ko_prefix+":1", "2", "3"]}}
278
- hash_dst = {"property"=>{"bedroom_count"=>["1", "2", "3"]}}
279
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ko_split})
280
- hash_dst.should == {"property"=>{"bedroom_count"=>["2", "3"]}}
281
- end
282
-
283
- it "tests typical params/session style hash with knockout_merge elements" do
284
- hash_src = {"property"=>{"bedroom_count"=>[@field_ko_prefix+":1", "2", "3"]}}
285
- hash_dst = {"property"=>{"bedroom_count"=>["3"]}}
286
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ko_split})
287
- hash_dst.should == {"property"=>{"bedroom_count"=>["3","2"]}}
288
- end
289
-
290
- it "tests typical params/session style hash with knockout_merge elements" do
291
- hash_src = {"property"=>{"bedroom_count"=>[@field_ko_prefix+":1", "2", "3"]}}
292
- hash_dst = {"property"=>{"bedroom_count"=>["4"]}}
293
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ko_split})
294
- hash_dst.should == {"property"=>{"bedroom_count"=>["4","2","3"]}}
295
- end
296
-
297
- it "tests typical params/session style hash with knockout_merge elements" do
298
- hash_src = {"property"=>{"bedroom_count"=>[@field_ko_prefix+":1", "2", "3"]}}
299
- hash_dst = {"property"=>{"bedroom_count"=>[@field_ko_prefix+":1", "4"]}}
300
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ko_split})
301
- hash_dst.should == {"property"=>{"bedroom_count"=>["4","2","3"]}}
302
- end
303
-
304
- it "tests typical params/session style hash with knockout_merge elements" do
305
- hash_src = {"amenity"=>{"id"=>[@field_ko_prefix+":1", @field_ko_prefix+":2", "3", "4"]}}
306
- hash_dst = {"amenity"=>{"id"=>["1", "2"]}}
307
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ko_split})
308
- hash_dst.should == {"amenity"=>{"id"=>["3","4"]}}
309
- end
310
- end
311
-
312
- it "tests special params/session style hash with knockout_merge elements in form src: [\"1\",\"2\"] dest:[\"@ko:1,@ko:2\", \"3,4\"]" do
313
- hash_src = {"amenity"=>{"id"=>[@field_ko_prefix+":1,"+@field_ko_prefix+":2", "3,4"]}}
314
- hash_dst = {"amenity"=>{"id"=>["1", "2"]}}
315
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
316
- hash_dst.should == {"amenity"=>{"id"=>["3","4"]}}
317
- end
318
-
319
- it "tests same as previous but without ko_split value, this merge should fail" do
320
- hash_src = {"amenity"=>{"id"=>[@field_ko_prefix+":1,"+@field_ko_prefix+":2", "3,4"]}}
321
- hash_dst = {"amenity"=>{"id"=>["1", "2"]}}
322
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix})
323
- hash_dst.should == {"amenity"=>{"id"=>["1","2","3,4"]}}
324
- end
325
-
326
- it "tests special params/session style hash with knockout_merge elements in form src: [\"1\",\"2\"] dest:[\"@ko:1,@ko:2\", \"3,4\"]" do
327
- hash_src = {"amenity"=>{"id"=>[@field_ko_prefix+":1,2", "3,4", @field_ko_prefix+":5", "6"]}}
328
- hash_dst = {"amenity"=>{"id"=>["1", "2"]}}
329
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
330
- hash_dst.should == {"amenity"=>{"id"=>["2","3","4","6"]}}
331
- end
332
-
333
- it "tests special params/session style hash with knockout_merge elements in form src: [\"@ko:1,@ko:2\", \"3,4\", \"@ko:5\", \"6\"] dest:[\"1,2\", \"3,4\"]" do
334
- hash_src = {"amenity"=>{"id"=>["#{@field_ko_prefix}:1,#{@field_ko_prefix}:2", "3,4", "#{@field_ko_prefix}:5", "6"]}}
335
- hash_dst = {"amenity"=>{"id"=>["1", "2", "3", "4"]}}
336
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
337
- hash_dst.should == {"amenity"=>{"id"=>["3","4","6"]}}
338
- end
339
-
340
- it "unamed upstream - tbd" do
341
- hash_src = {"url_regions"=>[], "region"=>{"ids"=>["227,233"]}, "action"=>"browse", "task"=>"browse", "controller"=>"results"}
342
- hash_dst = {"region"=>{"ids"=>["227"]}}
343
- @dm.deep_merge!(hash_src.dup, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
344
- hash_dst.should == {"url_regions"=>[], "region"=>{"ids"=>["227","233"]}, "action"=>"browse", "task"=>"browse", "controller"=>"results"}
345
- end
346
-
347
- it "unamed upstream - tbd" do
348
- hash_src = {"region"=>{"ids"=>[@field_ko_prefix,"227"], "id"=>"230"}}
349
- hash_dst = {"region"=>{"ids"=>["227", "233", "324", "230", "230"], "id"=>"230"}}
350
- @dm.deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
351
- hash_dst.should == {"region"=>{"ids"=>["227"], "id"=>"230"}}
352
- end
353
-
354
- it "unamed upstream - tbd" do
355
- hash_src = {"region"=>{"ids"=>[@field_ko_prefix,"227", "232", "233"], "id"=>"232"}}
356
- hash_dst = {"region"=>{"ids"=>["227", "233", "324", "230", "230"], "id"=>"230"}}
357
- @dm.deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
358
- hash_dst.should == {"region"=>{"ids"=>["227", "232", "233"], "id"=>"232"}}
359
- end
360
-
361
- it "unamed upstream - tbd" do
362
- hash_src = {"region"=>{"ids"=>["#{@field_ko_prefix},227,232,233"], "id"=>"232"}}
363
- hash_dst = {"region"=>{"ids"=>["227", "233", "324", "230", "230"], "id"=>"230"}}
364
- @dm.deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
365
- hash_dst.should == {"region"=>{"ids"=>["227", "232", "233"], "id"=>"232"}}
366
- end
367
-
368
- it "unamed upstream - tbd" do
369
- hash_src = {"region"=>{"ids"=>["#{@field_ko_prefix},227,232","233"], "id"=>"232"}}
370
- hash_dst = {"region"=>{"ids"=>["227", "233", "324", "230", "230"], "id"=>"230"}}
371
- @dm.deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
372
- hash_dst.should == {"region"=>{"ids"=>["227", "232", "233"], "id"=>"232"}}
373
- end
374
-
375
- it "unamed upstream - tbd" do
376
- hash_src = {"region"=>{"ids"=>["#{@field_ko_prefix},227"], "id"=>"230"}}
377
- hash_dst = {"region"=>{"ids"=>["227", "233", "324", "230", "230"], "id"=>"230"}}
378
- @dm.deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
379
- hash_dst.should == {"region"=>{"ids"=>["227"], "id"=>"230"}}
380
- end
381
-
382
- it "unamed upstream - tbd" do
383
- hash_src = {"region"=>{"ids"=>["#{@field_ko_prefix},227"], "id"=>"230"}}
384
- hash_dst = {"region"=>{"ids"=>["227", "233", "324", "230", "230"], "id"=>"230"}, "action"=>"browse", "task"=>"browse", "controller"=>"results", "property_order_by"=>"property_type.descr"}
385
- @dm.deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
386
- hash_dst.should == {"region"=>{"ids"=>["227"], "id"=>"230"}, "action"=>"browse", "task"=>"browse",
387
- "controller"=>"results", "property_order_by"=>"property_type.descr"}
388
- end
389
-
390
- it "unamed upstream - tbd" do
391
- hash_src = {"query_uuid"=>"6386333d-389b-ab5c-8943-6f3a2aa914d7", "region"=>{"ids"=>["#{@field_ko_prefix},227"], "id"=>"230"}}
392
- hash_dst = {"query_uuid"=>"6386333d-389b-ab5c-8943-6f3a2aa914d7", "url_regions"=>[], "region"=>{"ids"=>["227", "233", "324", "230", "230"], "id"=>"230"}, "action"=>"browse", "task"=>"browse", "controller"=>"results", "property_order_by"=>"property_type.descr"}
393
- @dm.deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
394
- hash_dst.should == {"query_uuid" => "6386333d-389b-ab5c-8943-6f3a2aa914d7", "url_regions"=>[],
395
- "region"=>{"ids"=>["227"], "id"=>"230"}, "action"=>"browse", "task"=>"browse",
396
- "controller"=>"results", "property_order_by"=>"property_type.descr"}
397
- end
398
-
399
- it "tests knock out entire dest hash if \"@ko\" is passed for source" do
400
- hash_src = {'amenity' => @field_ko_prefix}
401
- hash_dst = {"amenity" => "1"}
402
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
403
- hash_dst.should == {'amenity' => ""}
404
- end
405
-
406
- it "tests knock out entire dest hash if \"@ko\" is passed for source" do
407
- hash_src = {'amenity' => [@field_ko_prefix]}
408
- hash_dst = {"amenity" => "1"}
409
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
410
- hash_dst.should == {'amenity' => []}
411
- end
412
-
413
- it "tests knock out entire dest hash if \"@ko\" is passed for source" do
414
- hash_src = {'amenity' => @field_ko_prefix}
415
- hash_dst = {"amenity" => ["1"]}
416
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
417
- hash_dst.should == {'amenity' => ""}
418
- end
419
-
420
- it "tests knock out entire dest hash if \"@ko\" is passed for source" do
421
- hash_src = {'amenity' => [@field_ko_prefix]}
422
- hash_dst = {"amenity" => ["1"]}
423
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
424
- hash_dst.should == {'amenity' => []}
425
- end
426
-
427
- it "tests knock out entire dest hash if \"@ko\" is passed for source" do
428
- hash_src = {'amenity' => [@field_ko_prefix]}
429
- hash_dst = {"amenity" => "1"}
430
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
431
- hash_dst.should == {'amenity' => []}
432
- end
433
-
434
- it "tests knock out entire dest hash if \"@ko\" is passed for source" do
435
- hash_src = {'amenity' => [@field_ko_prefix, "2"]}
436
- hash_dst = {'amenity' => ["1", "3", "7+"]}
437
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
438
- hash_dst.should == {'amenity' => ["2"]}
439
- end
440
-
441
- it "tests knock out entire dest hash if \"@ko\" is passed for source" do
442
- hash_src = {'amenity' => [@field_ko_prefix, "2"]}
443
- hash_dst = {'amenity' => "5"}
444
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
445
- hash_dst.should == {'amenity' => ['2']}
446
- end
447
-
448
- it "tests knock out entire dest hash if \"@ko\" is passed for source" do
449
- hash_src = {'amenity' => @field_ko_prefix}
450
- hash_dst = {"amenity"=>{"id"=>["1", "2", "3", "4"]}}
451
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
452
- hash_dst.should == {'amenity' => ""}
453
- end
454
-
455
- it "tests knock out entire dest hash if \"@ko\" is passed for source" do
456
- hash_src = {'amenity' => [@field_ko_prefix]}
457
- hash_dst = {"amenity"=>{"id"=>["1", "2", "3", "4"]}}
458
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
459
- hash_dst.should == {'amenity' => []}
460
- end
461
-
462
- it "tests knock out dest array if \"@ko\" is passed for source" do
463
- hash_src = {"region" => {'ids' => @field_ko_prefix}}
464
- hash_dst = {"region"=>{"ids"=>["1", "2", "3", "4"]}}
465
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
466
- hash_dst.should == {'region' => {'ids' => ""}}
467
- end
468
-
469
- it "tests knock out dest array but leave other elements of hash intact" do
470
- hash_src = {"region" => {'ids' => @field_ko_prefix}}
471
- hash_dst = {"region"=>{"ids"=>["1", "2", "3", "4"], 'id'=>'11'}}
472
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
473
- hash_dst.should == {'region' => {'ids' => "", 'id'=>'11'}}
474
- end
475
-
476
- it "tests knock out entire tree of dest hash" do
477
- hash_src = {"region" => @field_ko_prefix}
478
- hash_dst = {"region"=>{"ids"=>["1", "2", "3", "4"], 'id'=>'11'}}
479
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
480
- hash_dst.should == {'region' => ""}
481
- end
482
-
483
- it "tests knock out entire tree of dest hash - retaining array format" do
484
- hash_src = {"region" => {'ids' => [@field_ko_prefix]}}
485
- hash_dst = {"region"=>{"ids"=>["1", "2", "3", "4"], 'id'=>'11'}}
486
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
487
- hash_dst.should == {'region' => {'ids' => [], 'id'=>'11'}}
488
- end
489
-
490
- it "tests knock out entire tree of dest hash & replace with new content" do
491
- hash_src = {"region" => {'ids' => ["2", @field_ko_prefix, "6"]}}
492
- hash_dst = {"region"=>{"ids"=>["1", "2", "3", "4"], 'id'=>'11'}}
493
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
494
- hash_dst.should == {'region' => {'ids' => ["2", "6"], 'id'=>'11'}}
495
- end
496
-
497
- it "tests knock out entire tree of dest hash & replace with new content" do
498
- hash_src = {"region" => {'ids' => ["7", @field_ko_prefix, "6"]}}
499
- hash_dst = {"region"=>{"ids"=>["1", "2", "3", "4"], 'id'=>'11'}}
500
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
501
- hash_dst.should == {'region' => {'ids' => ["7", "6"], 'id'=>'11'}}
502
- end
503
-
504
- it "tests edge test: make sure that when we turn off knockout_prefix that all values are processed correctly" do
505
- hash_src = {"region" => {'ids' => ["7", @field_ko_prefix, "2", "6,8"]}}
506
- hash_dst = {"region"=>{"ids"=>["1", "2", "3", "4"], 'id'=>'11'}}
507
- @dm.deep_merge!(hash_src, hash_dst, {:unpack_arrays => ","})
508
- hash_dst.should == {'region' => {'ids' => ["1", "2", "3", "4", "7", @field_ko_prefix, "6", "8"], 'id'=>'11'}}
509
- end
510
-
511
- it "tests edge test 2: make sure that when we turn off source array split that all values are processed correctly" do
512
- hash_src = {"region" => {'ids' => ["7", "3", @field_ko_prefix, "6,8"]}}
513
- hash_dst = {"region"=>{"ids"=>["1", "2", "3", "4"], 'id'=>'11'}}
514
193
  @dm.deep_merge!(hash_src, hash_dst)
515
- hash_dst.should == {'region' => {'ids' => ["1", "2", "3", "4", "7", @field_ko_prefix, "6,8"], 'id'=>'11'}}
516
- end
517
-
518
- it "tests Example: src = {'key' => \"@ko:1\"}, dst = {'key' => \"1\"} -> merges to {'key' => \"\"}" do
519
- hash_src = {"amenity"=>@field_ko_prefix+":1"}
520
- hash_dst = {"amenity"=>"1"}
521
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix})
522
- hash_dst.should == {"amenity"=>""}
523
- end
524
-
525
- it "tests Example: src = {'key' => \"@ko:1\"}, dst = {'key' => \"2\"} -> merges to {'key' => \"\"}" do
526
- hash_src = {"amenity"=>@field_ko_prefix+":1"}
527
- hash_dst = {"amenity"=>"2"}
528
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix})
529
- hash_dst.should == {"amenity"=>""}
530
- end
531
-
532
- it "tests Example: src = {'key' => \"@ko:1\"}, dst = {'key' => \"1\"} -> merges to {'key' => \"\"}" do
533
- hash_src = {"amenity"=>[@field_ko_prefix+":1"]}
534
- hash_dst = {"amenity"=>"1"}
535
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix})
536
- hash_dst.should == {"amenity"=>[]}
537
- end
538
-
539
- it "tests Example: src = {'key' => \"@ko:1\"}, dst = {'key' => \"1\"} -> merges to {'key' => \"\"}" do
540
- hash_src = {"amenity"=>[@field_ko_prefix+":1"]}
541
- hash_dst = {"amenity"=>["1"]}
542
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix})
543
- hash_dst.should == {"amenity"=>[]}
544
- end
545
-
546
- it "tests Example: src = {'key' => \"@ko:1\"}, dst = {'key' => \"1\"} -> merges to {'key' => \"\"}" do
547
- hash_src = {"amenity"=>@field_ko_prefix+":1"}
548
- hash_dst = {}
549
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix})
550
- hash_dst.should == {"amenity"=>""}
551
- end
552
-
553
- it "tests Example: src = {'key' => \"@ko:1\"}, dst = {'key' => \"1\"} -> merges to {'key' => \"\"}" do
554
- hash_src = {"amenity"=>@field_ko_prefix+":1"}
555
- hash_dst = {"amenity"=>["1"]}
556
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix})
557
- hash_dst.should == {"amenity"=>""}
194
+ hash_dst.should == hash_src
558
195
  end
559
196
 
560
197
  it "tests are unmerged hashes passed unmodified w/out :unpack_arrays?" do
561
198
  hash_src = {"amenity"=>{"id"=>["26,27"]}}
562
199
  hash_dst = {}
563
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix})
200
+ @dm.deep_merge!(hash_src, hash_dst)
564
201
  hash_dst.should == {"amenity"=>{"id"=>["26,27"]}}
565
202
  end
566
203
 
567
- it "tests hash should be merged" do
568
- hash_src = {"amenity"=>{"id"=>["26,27"]}}
569
- hash_dst = {}
570
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
571
- hash_dst.should == {"amenity"=>{"id"=>["26","27"]}}
572
- end
573
-
574
- it "tests second merge of same values should result in no change in output" do
575
- hash_src = {"amenity"=>{"id"=>["26,27"]}}
576
- hash_dst = {}
577
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
578
- hash_dst.should == {"amenity"=>{"id"=>["26","27"]}}
579
- end
580
-
581
- it "tests hashes with knockout values are suppressed" do
582
- hash_src = {"amenity"=>{"id"=>["#{@field_ko_prefix}:26,#{@field_ko_prefix}:27,28"]}}
583
- hash_dst = {}
584
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
585
- hash_dst.should == {"amenity"=>{"id"=>["28"]}}
586
- end
587
-
588
- it "unamed upstream - tbd" do
589
- hash_src= {'region' =>{'ids'=>[@field_ko_prefix]}, 'query_uuid' => 'zzz'}
590
- hash_dst= {'region' =>{'ids'=>['227','2','3','3']}, 'query_uuid' => 'zzz'}
591
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
592
- hash_dst.should == {'region' =>{'ids'=>[]}, 'query_uuid' => 'zzz'}
593
- end
594
-
595
- it "unamed upstream - tbd" do
596
- hash_src= {'region' =>{'ids'=>[@field_ko_prefix]}, 'query_uuid' => 'zzz'}
597
- hash_dst= {'region' =>{'ids'=>['227','2','3','3'], 'id' => '3'}, 'query_uuid' => 'zzz'}
598
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
599
- hash_dst.should == {'region' =>{'ids'=>[], 'id'=>'3'}, 'query_uuid' => 'zzz'}
600
- end
601
-
602
- it "unamed upstream - tbd" do
603
- hash_src= {'region' =>{'ids'=>[@field_ko_prefix]}, 'query_uuid' => 'zzz'}
604
- hash_dst= {'region' =>{'muni_city_id' => '2244', 'ids'=>['227','2','3','3'], 'id'=>'3'}, 'query_uuid' => 'zzz'}
605
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
606
- hash_dst.should == {'region' =>{'muni_city_id' => '2244', 'ids'=>[], 'id'=>'3'}, 'query_uuid' => 'zzz'}
607
- end
608
-
609
- it "unamed upstream - tbd" do
610
- hash_src= {'region' =>{'ids'=>[@field_ko_prefix], 'id' => '5'}, 'query_uuid' => 'zzz'}
611
- hash_dst= {'region' =>{'muni_city_id' => '2244', 'ids'=>['227','2','3','3'], 'id'=>'3'}, 'query_uuid' => 'zzz'}
612
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
613
- hash_dst.should == {'region' =>{'muni_city_id' => '2244', 'ids'=>[], 'id'=>'5'}, 'query_uuid' => 'zzz'}
614
- end
615
-
616
- it "unamed upstream - tbd" do
617
- hash_src= {'region' =>{'ids'=>[@field_ko_prefix, '227'], 'id' => '5'}, 'query_uuid' => 'zzz'}
618
- hash_dst= {'region' =>{'muni_city_id' => '2244', 'ids'=>['227','2','3','3'], 'id'=>'3'}, 'query_uuid' => 'zzz'}
619
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
620
- hash_dst.should == {'region' =>{'muni_city_id' => '2244', 'ids'=>['227'], 'id'=>'5'}, 'query_uuid' => 'zzz'}
621
- end
622
-
623
- it "unamed upstream - tbd" do
624
- hash_src= {'region' =>{'muni_city_id' => @field_ko_prefix, 'ids'=>@field_ko_prefix, 'id'=>'5'}, 'query_uuid' => 'zzz'}
625
- hash_dst= {'region' =>{'muni_city_id' => '2244', 'ids'=>['227','2','3','3'], 'id'=>'3'}, 'query_uuid' => 'zzz'}
626
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
627
- hash_dst.should == {'region' =>{'muni_city_id' => '', 'ids'=>'', 'id'=>'5'}, 'query_uuid' => 'zzz'}
628
- end
629
-
630
- it "unamed upstream - tbd" do
631
- hash_src= {'region' =>{'muni_city_id' => @field_ko_prefix, 'ids'=>[@field_ko_prefix], 'id'=>'5'}, 'query_uuid' => 'zzz'}
632
- hash_dst= {'region' =>{'muni_city_id' => '2244', 'ids'=>['227','2','3','3'], 'id'=>'3'}, 'query_uuid' => 'zzz'}
633
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
634
- hash_dst.should == {'region' =>{'muni_city_id' => '', 'ids'=>[], 'id'=>'5'}, 'query_uuid' => 'zzz'}
635
- end
636
-
637
- it "unamed upstream - tbd" do
638
- hash_src= {'region' =>{'muni_city_id' => @field_ko_prefix, 'ids'=>[@field_ko_prefix,'227'], 'id'=>'5'}, 'query_uuid' => 'zzz'}
639
- hash_dst= {'region' =>{'muni_city_id' => '2244', 'ids'=>['227','2','3','3'], 'id'=>'3'}, 'query_uuid' => 'zzz'}
640
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
641
- hash_dst.should == {'region' =>{'muni_city_id' => '', 'ids'=>['227'], 'id'=>'5'}, 'query_uuid' => 'zzz'}
642
- end
643
-
644
- it "unamed upstream - tbd" do
645
- hash_src = {"muni_city_id"=>@field_ko_prefix, "id"=>""}
646
- hash_dst = {"muni_city_id"=>"", "id"=>""}
647
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
648
- hash_dst.should == {"muni_city_id"=>"", "id"=>""}
649
- end
650
-
651
- it "unamed upstream - tbd" do
652
- hash_src = {"region"=>{"muni_city_id"=>@field_ko_prefix, "id"=>""}}
653
- hash_dst = {"region"=>{"muni_city_id"=>"", "id"=>""}}
654
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
655
- hash_dst.should == {"region"=>{"muni_city_id"=>"", "id"=>""}}
656
- end
657
-
658
- it "unamed upstream - tbd" do
659
- hash_src = {"query_uuid"=>"a0dc3c84-ec7f-6756-bdb0-fff9157438ab", "url_regions"=>[], "region"=>{"muni_city_id"=>@field_ko_prefix, "id"=>""}, "property"=>{"property_type_id"=>"", "search_rate_min"=>"", "search_rate_max"=>""}, "task"=>"search", "run_query"=>"Search"}
660
- hash_dst = {"query_uuid"=>"a0dc3c84-ec7f-6756-bdb0-fff9157438ab", "url_regions"=>[], "region"=>{"muni_city_id"=>"", "id"=>""}, "property"=>{"property_type_id"=>"", "search_rate_min"=>"", "search_rate_max"=>""}, "task"=>"search", "run_query"=>"Search"}
661
- @dm.deep_merge!(hash_src, hash_dst, {:knockout_prefix => @field_ko_prefix, :unpack_arrays => ","})
662
- hash_dst.should == {"query_uuid"=>"a0dc3c84-ec7f-6756-bdb0-fff9157438ab", "url_regions"=>[], "region"=>{"muni_city_id"=>"", "id"=>""}, "property"=>{"property_type_id"=>"", "search_rate_min"=>"", "search_rate_max"=>""}, "task"=>"search", "run_query"=>"Search"}
663
- end
664
-
665
204
  it "tests hash of array of hashes" do
666
205
  hash_src = {"item" => [{"1" => "3"}, {"2" => "4"}]}
667
206
  hash_dst = {"item" => [{"3" => "5"}]}
@@ -745,42 +284,68 @@ describe Chef::Mixin::DeepMerge do
745
284
  ret.should == {"property" => ["1","2","3","4","5","6"]}
746
285
  end
747
286
 
748
- it "should not knockout matching array value when merging arrays within hashes" do
749
- hash_dst = {"property" => ["2","4"]}
750
- hash_src = {"property" => ["1","!merge:4"]}
751
- hash_src_no_colon = {"property" => ["1","!merge"]}
752
- @dm.merge(hash_dst, hash_src).should == {"property" => ["2", "4", "1", "!merge:4"]}
753
- @dm.merge(hash_dst, hash_src_no_colon).should == {"property" => ["2", "4", "1", "!merge"]}
754
- end
755
287
  end
756
288
 
757
289
  describe "role_merge" do
758
- it "should knockout matching array value when merging arrays within hashes" do
290
+ it "errors out if knockout merge use is detected in an array" do
759
291
  hash_dst = {"property" => ["2","4"]}
760
292
  hash_src = {"property" => ["1","!merge:4"]}
761
- @dm.role_merge(hash_dst, hash_src).should == {"property" => ["2","1"]}
293
+ lambda {@dm.role_merge(hash_dst, hash_src)}.should raise_error(Chef::Mixin::DeepMerge::InvalidSubtractiveMerge)
762
294
  end
763
295
 
764
- it "should knockout all array values when merging arrays within hashes, leaving 2" do
765
- hash_dst = {"property" => ["2","4"]}
766
- hash_src = {"property" => ["!merge:","1","2"]}
767
- hash_src_no_colon = {"property" => ["!merge","1","2"]}
768
- @dm.role_merge(hash_dst, hash_src).should == {"property" => ["1","2"]}
769
- @dm.role_merge(hash_dst, hash_src_no_colon).should == {"property" => ["1","2"]}
296
+ it "errors out if knockout merge use is detected in an array (reversed merge order)" do
297
+ hash_dst = {"property" => ["1","!merge:4"]}
298
+ hash_src = {"property" => ["2","4"]}
299
+ lambda {@dm.role_merge(hash_dst, hash_src)}.should raise_error(Chef::Mixin::DeepMerge::InvalidSubtractiveMerge)
770
300
  end
771
301
 
772
- it "should knockout all array values when merging arrays within hashes, leaving 0" do
302
+ it "errors out if knockout merge use is detected in a string" do
773
303
  hash_dst = {"property" => ["2","4"]}
774
- hash_src = {"property" => ["!merge:"]}
775
- hash_src_no_colon = {"property" => ["!merge"]}
776
- @dm.role_merge(hash_dst, hash_src).should == {"property" => []}
777
- @dm.role_merge(hash_dst, hash_src_no_colon).should == {"property" => []}
304
+ hash_src = {"property" => "!merge"}
305
+ lambda {@dm.role_merge(hash_dst, hash_src)}.should raise_error(Chef::Mixin::DeepMerge::InvalidSubtractiveMerge)
778
306
  end
779
307
 
780
- it "should knockout matching array value when merging arrays within hashes" do
781
- hash_dst = {"property" => ["2","4"]}
782
- hash_src = {"property" => ["1","!merge:4"]}
783
- @dm.role_merge(hash_dst, hash_src).should == {"property" => ["2","1"]}
308
+ it "errors out if knockout merge use is detected in a string (reversed merge order)" do
309
+ hash_dst = {"property" => "!merge"}
310
+ hash_src= {"property" => ["2","4"]}
311
+ lambda {@dm.role_merge(hash_dst, hash_src)}.should raise_error(Chef::Mixin::DeepMerge::InvalidSubtractiveMerge)
312
+ end
313
+ end
314
+
315
+ describe "hash-only merging" do
316
+ it "merges Hashes like normal deep merge" do
317
+ merge_ee_hash = {"top_level_a" => {"1_deep_a" => "1-a-merge-ee", "1_deep_b" => "1-deep-b-merge-ee"}, "top_level_b" => "top-level-b-merge-ee"}
318
+ merge_with_hash = {"top_level_a" => {"1_deep_b" => "1-deep-b-merged-onto", "1_deep_c" => "1-deep-c-merged-onto"}, "top_level_b" => "top-level-b-merged-onto" }
319
+
320
+ merged_result = @dm.hash_only_merge(merge_ee_hash, merge_with_hash)
321
+
322
+ merged_result["top_level_b"].should == "top-level-b-merged-onto"
323
+ merged_result["top_level_a"]["1_deep_a"].should == "1-a-merge-ee"
324
+ merged_result["top_level_a"]["1_deep_b"].should == "1-deep-b-merged-onto"
325
+ merged_result["top_level_a"]["1_deep_c"].should == "1-deep-c-merged-onto"
326
+ end
327
+
328
+ it "replaces arrays rather than merging them" do
329
+ merge_ee_hash = {"top_level_a" => {"1_deep_a" => "1-a-merge-ee", "1_deep_b" => %w[A A A]}, "top_level_b" => "top-level-b-merge-ee"}
330
+ merge_with_hash = {"top_level_a" => {"1_deep_b" => %w[B B B], "1_deep_c" => "1-deep-c-merged-onto"}, "top_level_b" => "top-level-b-merged-onto" }
331
+
332
+ merged_result = @dm.hash_only_merge(merge_ee_hash, merge_with_hash)
333
+
334
+ merged_result["top_level_b"].should == "top-level-b-merged-onto"
335
+ merged_result["top_level_a"]["1_deep_a"].should == "1-a-merge-ee"
336
+ merged_result["top_level_a"]["1_deep_b"].should == %w[B B B]
784
337
  end
338
+
339
+ it "replaces non-hash items with hashes when there's a conflict" do
340
+ merge_ee_hash = {"top_level_a" => "top-level-a-mergee", "top_level_b" => "top-level-b-merge-ee"}
341
+ merge_with_hash = {"top_level_a" => {"1_deep_b" => %w[B B B], "1_deep_c" => "1-deep-c-merged-onto"}, "top_level_b" => "top-level-b-merged-onto" }
342
+
343
+ merged_result = @dm.hash_only_merge(merge_ee_hash, merge_with_hash)
344
+
345
+ merged_result["top_level_a"].should be_a(Hash)
346
+ merged_result["top_level_a"]["1_deep_a"].should be_nil
347
+ merged_result["top_level_a"]["1_deep_b"].should == %w[B B B]
348
+ end
349
+
785
350
  end
786
351
  end