puppet 6.10.1-x86-mingw32 → 6.11.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (242) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -4
  3. data/Gemfile.lock +20 -12
  4. data/ext/project_data.yaml +3 -2
  5. data/ext/regexp_nodes/regexp_nodes.rb +4 -4
  6. data/ext/windows/service/daemon.rb +33 -8
  7. data/install.rb +6 -6
  8. data/lib/puppet.rb +8 -0
  9. data/lib/puppet/application.rb +1 -1
  10. data/lib/puppet/application/agent.rb +3 -0
  11. data/lib/puppet/application/apply.rb +2 -2
  12. data/lib/puppet/application/describe.rb +3 -9
  13. data/lib/puppet/application/device.rb +3 -0
  14. data/lib/puppet/application/doc.rb +1 -1
  15. data/lib/puppet/application/lookup.rb +1 -1
  16. data/lib/puppet/application/script.rb +2 -2
  17. data/lib/puppet/application/ssl.rb +25 -21
  18. data/lib/puppet/configurer.rb +42 -0
  19. data/lib/puppet/configurer/downloader.rb +2 -6
  20. data/lib/puppet/context/trusted_information.rb +42 -4
  21. data/lib/puppet/defaults.rb +19 -4
  22. data/lib/puppet/face/module/list.rb +5 -5
  23. data/lib/puppet/face/module/search.rb +1 -1
  24. data/lib/puppet/face/module/uninstall.rb +1 -1
  25. data/lib/puppet/face/module/upgrade.rb +1 -1
  26. data/lib/puppet/file_serving/http_metadata.rb +1 -1
  27. data/lib/puppet/file_system.rb +0 -8
  28. data/lib/puppet/file_system/memory_file.rb +1 -1
  29. data/lib/puppet/file_system/posix.rb +3 -2
  30. data/lib/puppet/forge.rb +3 -3
  31. data/lib/puppet/functions.rb +1 -2
  32. data/lib/puppet/gettext/module_translations.rb +1 -1
  33. data/lib/puppet/graph/rb_tree_map.rb +2 -2
  34. data/lib/puppet/graph/simple_graph.rb +4 -3
  35. data/lib/puppet/http.rb +29 -0
  36. data/lib/puppet/http/client.rb +156 -0
  37. data/lib/puppet/http/errors.rb +30 -0
  38. data/lib/puppet/http/redirector.rb +48 -0
  39. data/lib/puppet/http/resolver.rb +5 -0
  40. data/lib/puppet/http/resolver/settings.rb +5 -0
  41. data/lib/puppet/http/resolver/srv.rb +13 -0
  42. data/lib/puppet/http/response.rb +34 -0
  43. data/lib/puppet/http/retry_after_handler.rb +47 -0
  44. data/lib/puppet/http/service.rb +18 -0
  45. data/lib/puppet/http/service/ca.rb +49 -0
  46. data/lib/puppet/http/session.rb +55 -0
  47. data/lib/puppet/indirector/file_bucket_file/file.rb +1 -1
  48. data/lib/puppet/indirector/hiera.rb +2 -0
  49. data/lib/puppet/indirector/request.rb +1 -1
  50. data/lib/puppet/indirector/resource/ral.rb +1 -3
  51. data/lib/puppet/indirector/resource/validator.rb +1 -1
  52. data/lib/puppet/interface.rb +2 -1
  53. data/lib/puppet/interface/documentation.rb +1 -1
  54. data/lib/puppet/loaders.rb +0 -1
  55. data/lib/puppet/metatype/manager.rb +1 -1
  56. data/lib/puppet/module.rb +1 -1
  57. data/lib/puppet/module/task.rb +20 -4
  58. data/lib/puppet/module_tool/applications/installer.rb +1 -1
  59. data/lib/puppet/module_tool/applications/uninstaller.rb +3 -3
  60. data/lib/puppet/module_tool/metadata.rb +1 -1
  61. data/lib/puppet/module_tool/shared_behaviors.rb +4 -4
  62. data/lib/puppet/module_tool/tar/mini.rb +1 -1
  63. data/lib/puppet/network/http.rb +2 -6
  64. data/lib/puppet/network/http/api/indirected_routes.rb +12 -11
  65. data/lib/puppet/network/http/connection.rb +10 -12
  66. data/lib/puppet/network/http/pool.rb +2 -0
  67. data/lib/puppet/network/http/site.rb +5 -1
  68. data/lib/puppet/network/resolver.rb +4 -4
  69. data/lib/puppet/node/environment.rb +4 -2
  70. data/lib/puppet/pal/pal_impl.rb +2 -2
  71. data/lib/puppet/parser/ast.rb +1 -1
  72. data/lib/puppet/parser/ast/resourceparam.rb +1 -1
  73. data/lib/puppet/parser/functions.rb +1 -1
  74. data/lib/puppet/parser/scope.rb +8 -7
  75. data/lib/puppet/pops/evaluator/collectors/catalog_collector.rb +1 -1
  76. data/lib/puppet/pops/evaluator/collectors/exported_collector.rb +1 -1
  77. data/lib/puppet/pops/evaluator/external_syntax_support.rb +3 -2
  78. data/lib/puppet/pops/evaluator/runtime3_support.rb +4 -7
  79. data/lib/puppet/pops/loader/module_loaders.rb +1 -1
  80. data/lib/puppet/pops/loader/task_instantiator.rb +4 -0
  81. data/lib/puppet/pops/loaders.rb +1 -1
  82. data/lib/puppet/pops/lookup/hiera_config.rb +1 -0
  83. data/lib/puppet/pops/lookup/sub_lookup.rb +1 -1
  84. data/lib/puppet/pops/merge_strategy.rb +22 -18
  85. data/lib/puppet/pops/parser/heredoc_support.rb +1 -1
  86. data/lib/puppet/pops/parser/interpolation_support.rb +4 -4
  87. data/lib/puppet/pops/parser/locator.rb +1 -1
  88. data/lib/puppet/pops/parser/pn_parser.rb +17 -16
  89. data/lib/puppet/pops/puppet_stack.rb +52 -48
  90. data/lib/puppet/pops/types/p_sensitive_type.rb +1 -1
  91. data/lib/puppet/pops/types/p_uri_type.rb +1 -1
  92. data/lib/puppet/pops/types/string_converter.rb +10 -10
  93. data/lib/puppet/pops/types/types.rb +3 -3
  94. data/lib/puppet/property.rb +1 -1
  95. data/lib/puppet/property/ensure.rb +1 -1
  96. data/lib/puppet/provider/exec.rb +6 -2
  97. data/lib/puppet/provider/nameservice/directoryservice.rb +1 -1
  98. data/lib/puppet/provider/nameservice/pw.rb +2 -2
  99. data/lib/puppet/provider/package/apt.rb +5 -1
  100. data/lib/puppet/provider/package/dnfmodule.rb +87 -0
  101. data/lib/puppet/provider/package/dpkg.rb +31 -17
  102. data/lib/puppet/provider/package/openbsd.rb +1 -1
  103. data/lib/puppet/provider/package/pip.rb +34 -9
  104. data/lib/puppet/provider/package/portage.rb +1 -1
  105. data/lib/puppet/provider/package/rpm.rb +5 -5
  106. data/lib/puppet/provider/package/windows/package.rb +1 -1
  107. data/lib/puppet/provider/package/yum.rb +1 -1
  108. data/lib/puppet/provider/parsedfile.rb +1 -1
  109. data/lib/puppet/provider/service/daemontools.rb +9 -9
  110. data/lib/puppet/provider/service/openbsd.rb +1 -1
  111. data/lib/puppet/provider/service/rcng.rb +2 -2
  112. data/lib/puppet/provider/service/runit.rb +2 -8
  113. data/lib/puppet/provider/service/systemd.rb +10 -10
  114. data/lib/puppet/provider/user/directoryservice.rb +1 -1
  115. data/lib/puppet/provider/user/user_role_add.rb +1 -1
  116. data/lib/puppet/provider/user/useradd.rb +22 -13
  117. data/lib/puppet/provider/user/windows_adsi.rb +4 -5
  118. data/lib/puppet/reference/indirection.rb +2 -2
  119. data/lib/puppet/reference/metaparameter.rb +1 -3
  120. data/lib/puppet/reference/providers.rb +1 -1
  121. data/lib/puppet/reference/type.rb +3 -9
  122. data/lib/puppet/reports.rb +1 -1
  123. data/lib/puppet/resource.rb +1 -1
  124. data/lib/puppet/resource/catalog.rb +1 -1
  125. data/lib/puppet/rest/errors.rb +1 -0
  126. data/lib/puppet/rest/response.rb +1 -0
  127. data/lib/puppet/rest/route.rb +1 -0
  128. data/lib/puppet/rest/routes.rb +3 -0
  129. data/lib/puppet/runtime.rb +25 -0
  130. data/lib/puppet/settings.rb +3 -3
  131. data/lib/puppet/settings/environment_conf.rb +1 -0
  132. data/lib/puppet/ssl/host.rb +1 -1
  133. data/lib/puppet/ssl/oids.rb +1 -1
  134. data/lib/puppet/ssl/state_machine.rb +23 -15
  135. data/lib/puppet/test/test_helper.rb +1 -1
  136. data/lib/puppet/transaction/report.rb +1 -1
  137. data/lib/puppet/trusted_external.rb +13 -0
  138. data/lib/puppet/type.rb +1 -3
  139. data/lib/puppet/type/exec.rb +7 -3
  140. data/lib/puppet/type/file.rb +1 -2
  141. data/lib/puppet/type/file/source.rb +2 -2
  142. data/lib/puppet/type/package.rb +10 -3
  143. data/lib/puppet/type/schedule.rb +1 -1
  144. data/lib/puppet/type/service.rb +1 -1
  145. data/lib/puppet/util.rb +2 -2
  146. data/lib/puppet/util/command_line/trollop.rb +1 -1
  147. data/lib/puppet/util/http_proxy.rb +2 -10
  148. data/lib/puppet/util/log.rb +2 -2
  149. data/lib/puppet/util/log/destinations.rb +2 -2
  150. data/lib/puppet/util/logging.rb +2 -2
  151. data/lib/puppet/util/metric.rb +2 -2
  152. data/lib/puppet/util/platform.rb +15 -4
  153. data/lib/puppet/util/provider_features.rb +2 -4
  154. data/lib/puppet/util/rdoc.rb +1 -1
  155. data/lib/puppet/util/reference.rb +1 -1
  156. data/lib/puppet/util/resource_template.rb +1 -1
  157. data/lib/puppet/util/selinux.rb +3 -1
  158. data/lib/puppet/util/windows/registry.rb +7 -5
  159. data/lib/puppet/vendor.rb +1 -1
  160. data/lib/puppet/vendor/require_vendored.rb +0 -1
  161. data/lib/puppet/version.rb +1 -1
  162. data/lib/puppet/x509/cert_provider.rb +4 -1
  163. data/locales/puppet.pot +279 -203
  164. data/man/man5/puppet.conf.5 +30 -8
  165. data/man/man8/puppet-agent.8 +4 -1
  166. data/man/man8/puppet-apply.8 +1 -1
  167. data/man/man8/puppet-catalog.8 +1 -1
  168. data/man/man8/puppet-config.8 +1 -1
  169. data/man/man8/puppet-describe.8 +1 -1
  170. data/man/man8/puppet-device.8 +1 -1
  171. data/man/man8/puppet-doc.8 +1 -1
  172. data/man/man8/puppet-epp.8 +1 -1
  173. data/man/man8/puppet-facts.8 +1 -1
  174. data/man/man8/puppet-filebucket.8 +1 -1
  175. data/man/man8/puppet-generate.8 +1 -1
  176. data/man/man8/puppet-help.8 +1 -1
  177. data/man/man8/puppet-key.8 +1 -1
  178. data/man/man8/puppet-lookup.8 +1 -1
  179. data/man/man8/puppet-man.8 +1 -1
  180. data/man/man8/puppet-module.8 +1 -1
  181. data/man/man8/puppet-node.8 +1 -1
  182. data/man/man8/puppet-parser.8 +1 -1
  183. data/man/man8/puppet-plugin.8 +1 -1
  184. data/man/man8/puppet-report.8 +1 -1
  185. data/man/man8/puppet-resource.8 +1 -1
  186. data/man/man8/puppet-script.8 +1 -1
  187. data/man/man8/puppet-ssl.8 +1 -1
  188. data/man/man8/puppet-status.8 +1 -1
  189. data/man/man8/puppet.8 +2 -2
  190. data/spec/fixtures/unit/provider/package/dnfmodule/dnf-module-list-installed.txt +11 -0
  191. data/spec/integration/configurer_spec.rb +52 -0
  192. data/spec/lib/puppet/certificate_factory.rb +2 -2
  193. data/spec/spec_helper.rb +24 -0
  194. data/spec/unit/application/device_spec.rb +6 -0
  195. data/spec/unit/application/ssl_spec.rb +4 -7
  196. data/spec/unit/configurer_spec.rb +1 -0
  197. data/spec/unit/context/trusted_information_spec.rb +41 -2
  198. data/spec/unit/http/client_spec.rb +440 -0
  199. data/spec/unit/http/resolver_spec.rb +45 -0
  200. data/spec/unit/http/service/ca_spec.rb +106 -0
  201. data/spec/unit/http/service_spec.rb +32 -0
  202. data/spec/unit/http/session_spec.rb +102 -0
  203. data/spec/unit/indirector/resource/ral_spec.rb +4 -4
  204. data/spec/unit/network/http/connection_spec.rb +119 -145
  205. data/spec/unit/network/http/site_spec.rb +7 -0
  206. data/spec/unit/parser/scope_spec.rb +10 -0
  207. data/spec/unit/pops/loaders/loaders_spec.rb +13 -2
  208. data/spec/unit/pops/loaders/module_loaders_spec.rb +37 -0
  209. data/spec/unit/provider/exec_spec.rb +209 -0
  210. data/spec/unit/provider/package/dnfmodule_spec.rb +186 -0
  211. data/spec/unit/provider/package/dpkg_spec.rb +238 -78
  212. data/spec/unit/provider/package/pip_spec.rb +51 -6
  213. data/spec/unit/provider/service/daemontools_spec.rb +24 -0
  214. data/spec/unit/provider/service/runit_spec.rb +24 -0
  215. data/spec/unit/provider/service/systemd_spec.rb +25 -25
  216. data/spec/unit/provider/user/useradd_spec.rb +46 -0
  217. data/spec/unit/ssl/host_spec.rb +0 -5
  218. data/spec/unit/ssl/state_machine_spec.rb +16 -10
  219. data/spec/unit/type/exec_spec.rb +6 -12
  220. data/spec/unit/type/file_spec.rb +9 -4
  221. data/spec/unit/type/package_spec.rb +5 -0
  222. data/spec/unit/util/execution_spec.rb +16 -0
  223. data/spec/unit/util/http_proxy_spec.rb +79 -27
  224. data/spec/unit/util/log/destinations_spec.rb +7 -3
  225. metadata +54 -25
  226. data/lib/puppet/pops/loader/null_loader.rb +0 -60
  227. data/lib/puppet/vendor/deep_merge/CHANGELOG +0 -45
  228. data/lib/puppet/vendor/deep_merge/Gemfile +0 -3
  229. data/lib/puppet/vendor/deep_merge/LICENSE +0 -21
  230. data/lib/puppet/vendor/deep_merge/PUPPET_README.md +0 -6
  231. data/lib/puppet/vendor/deep_merge/README.md +0 -113
  232. data/lib/puppet/vendor/deep_merge/Rakefile +0 -19
  233. data/lib/puppet/vendor/deep_merge/deep_merge.gemspec +0 -35
  234. data/lib/puppet/vendor/deep_merge/lib/deep_merge.rb +0 -2
  235. data/lib/puppet/vendor/deep_merge/lib/deep_merge/core.rb +0 -210
  236. data/lib/puppet/vendor/deep_merge/lib/deep_merge/deep_merge_hash.rb +0 -28
  237. data/lib/puppet/vendor/deep_merge/lib/deep_merge/rails_compat.rb +0 -27
  238. data/lib/puppet/vendor/deep_merge/test/test_deep_merge.rb +0 -608
  239. data/lib/puppet/vendor/load_deep_merge.rb +0 -1
  240. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_get/should_yield_to_the_block.yml +0 -24
  241. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_head/should_yield_to_the_block.yml +0 -24
  242. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_post/should_yield_to_the_block.yml +0 -24
@@ -1,28 +0,0 @@
1
- require 'deep_merge/core'
2
-
3
- module DeepMerge
4
- module DeepMergeHash
5
- # ko_hash_merge! will merge and knockout elements prefixed with DEFAULT_FIELD_KNOCKOUT_PREFIX
6
- def ko_deep_merge!(source, options = {})
7
- default_opts = {:knockout_prefix => "--", :preserve_unmergeables => false}
8
- DeepMerge::deep_merge!(source, self, default_opts.merge(options))
9
- end
10
-
11
- # deep_merge! will merge and overwrite any unmergeables in destination hash
12
- def deep_merge!(source, options = {})
13
- default_opts = {:preserve_unmergeables => false}
14
- DeepMerge::deep_merge!(source, self, default_opts.merge(options))
15
- end
16
-
17
- # deep_merge will merge and skip any unmergeables in destination hash
18
- def deep_merge(source, options = {})
19
- default_opts = {:preserve_unmergeables => true}
20
- DeepMerge::deep_merge!(source, self, default_opts.merge(options))
21
- end
22
-
23
- end # DeepMergeHashExt
24
- end
25
-
26
- class Hash
27
- include DeepMerge::DeepMergeHash
28
- end
@@ -1,27 +0,0 @@
1
- require 'deep_merge/core'
2
-
3
- module DeepMerge
4
- module RailsCompat
5
- # ko_hash_merge! will merge and knockout elements prefixed with DEFAULT_FIELD_KNOCKOUT_PREFIX
6
- def ko_deeper_merge!(source, options = {})
7
- default_opts = {:knockout_prefix => "--", :preserve_unmergeables => false}
8
- DeepMerge::deep_merge!(source, self, default_opts.merge(options))
9
- end
10
-
11
- # deep_merge! will merge and overwrite any unmergeables in destination hash
12
- def deeper_merge!(source, options = {})
13
- default_opts = {:preserve_unmergeables => false}
14
- DeepMerge::deep_merge!(source, self, default_opts.merge(options))
15
- end
16
-
17
- # deep_merge will merge and skip any unmergeables in destination hash
18
- def deeper_merge(source, options = {})
19
- default_opts = {:preserve_unmergeables => true}
20
- DeepMerge::deep_merge!(source, self, default_opts.merge(options))
21
- end
22
- end
23
- end
24
-
25
- class Hash
26
- include ::DeepMerge::RailsCompat
27
- end
@@ -1,608 +0,0 @@
1
- require 'test/unit'
2
-
3
- $:.unshift(File.dirname(__FILE__) + '/../lib/')
4
- require 'deep_merge'
5
-
6
- # Assume strings have a blank? method
7
- # as they do when ActiveSupport is included.
8
- module StringBlank
9
- def blank?
10
- size == 0
11
- end
12
- end
13
-
14
- class TestDeepMerge < Test::Unit::TestCase
15
-
16
- def setup
17
- end
18
-
19
- # show that Hash object has deep merge capabilities in form of three methods:
20
- # ko_deep_merge! # uses '--' knockout and overwrites unmergeable
21
- # deep_merge! # overwrites unmergeable
22
- # deep_merge # skips unmergeable
23
- def test_hash_deep_merge
24
- x = {}
25
- assert x.respond_to?('deep_merge!'.to_sym)
26
- hash_src = {'id' => [3,4,5]}
27
- hash_dest = {'id' => [1,2,3]}
28
- assert hash_dest.ko_deep_merge!(hash_src)
29
- assert_equal({'id' => [1,2,3,4,5]}, hash_dest)
30
-
31
- hash_src = {'id' => [3,4,5]}
32
- hash_dest = {'id' => [1,2,3]}
33
- assert hash_dest.deep_merge!(hash_src)
34
- assert_equal({'id' => [1,2,3,4,5]}, hash_dest)
35
-
36
- hash_src = {'id' => 'xxx'}
37
- hash_dest = {'id' => [1,2,3]}
38
- assert hash_dest.deep_merge(hash_src)
39
- assert_equal({'id' => [1,2,3]}, hash_dest)
40
- end
41
-
42
- FIELD_KNOCKOUT_PREFIX = DeepMerge::DEFAULT_FIELD_KNOCKOUT_PREFIX
43
-
44
- # tests DeepMerge::deep_merge! function
45
- def test_deep_merge
46
- # merge tests (moving from basic to more complex)
47
-
48
- # test merging an hash w/array into blank hash
49
- hash_src = {'id' => '2'}
50
- hash_dst = {}
51
- DeepMerge::deep_merge!(hash_src.dup, hash_dst, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
52
- assert_equal hash_src, hash_dst
53
-
54
- # test merging an hash w/array into blank hash
55
- hash_src = {'region' => {'id' => ['227', '2']}}
56
- hash_dst = {}
57
- DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
58
- assert_equal hash_src, hash_dst
59
-
60
- # merge from empty hash
61
- hash_src = {}
62
- hash_dst = {"property" => ["2","4"]}
63
- DeepMerge::deep_merge!(hash_src, hash_dst)
64
- assert_equal({"property" => ["2","4"]}, hash_dst)
65
-
66
- # merge to empty hash
67
- hash_src = {"property" => ["2","4"]}
68
- hash_dst = {}
69
- DeepMerge::deep_merge!(hash_src, hash_dst)
70
- assert_equal({"property" => ["2","4"]}, hash_dst)
71
-
72
- # simple string overwrite
73
- hash_src = {"name" => "value"}
74
- hash_dst = {"name" => "value1"}
75
- DeepMerge::deep_merge!(hash_src, hash_dst)
76
- assert_equal({"name" => "value"}, hash_dst)
77
-
78
- # simple string overwrite of empty hash
79
- hash_src = {"name" => "value"}
80
- hash_dst = {}
81
- DeepMerge::deep_merge!(hash_src, hash_dst)
82
- assert_equal(hash_src, hash_dst)
83
-
84
- # hashes holding array
85
- hash_src = {"property" => ["1","3"]}
86
- hash_dst = {"property" => ["2","4"]}
87
- DeepMerge::deep_merge!(hash_src, hash_dst)
88
- assert_equal(["2","4","1","3"], hash_dst['property'])
89
-
90
- # hashes holding array (sorted)
91
- hash_src = {"property" => ["1","3"]}
92
- hash_dst = {"property" => ["2","4"]}
93
- DeepMerge::deep_merge!(hash_src, hash_dst, {:sort_merged_arrays => true})
94
- assert_equal(["1","2","3","4"].sort, hash_dst['property'])
95
-
96
- # hashes holding hashes holding arrays (array with duplicate elements is merged with dest then src
97
- hash_src = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["1", "4+"]}}
98
- hash_dst = {"property" => {"bedroom_count" => ["3", "2"], "bathroom_count" => ["2"]}}
99
- DeepMerge::deep_merge!(hash_src, hash_dst)
100
- assert_equal({"property" => {"bedroom_count" => ["3","2","1"], "bathroom_count" => ["2", "1", "4+"]}}, hash_dst)
101
-
102
- # hash holding hash holding array v string (string is overwritten by array)
103
- hash_src = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["1", "4+"]}}
104
- hash_dst = {"property" => {"bedroom_count" => "3", "bathroom_count" => ["2"]}}
105
- DeepMerge::deep_merge!(hash_src, hash_dst)
106
- assert_equal({"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2","1","4+"]}}, hash_dst)
107
-
108
- # hash holding hash holding array v string (string is NOT overwritten by array)
109
- hash_src = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["1", "4+"]}}
110
- hash_dst = {"property" => {"bedroom_count" => "3", "bathroom_count" => ["2"]}}
111
- DeepMerge::deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true})
112
- assert_equal({"property" => {"bedroom_count" => "3", "bathroom_count" => ["2","1","4+"]}}, hash_dst)
113
-
114
- # hash holding hash holding string v array (array is overwritten by string)
115
- hash_src = {"property" => {"bedroom_count" => "3", "bathroom_count" => ["1", "4+"]}}
116
- hash_dst = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2"]}}
117
- DeepMerge::deep_merge!(hash_src, hash_dst)
118
- assert_equal({"property" => {"bedroom_count" => "3", "bathroom_count" => ["2","1","4+"]}}, hash_dst)
119
-
120
- # hash holding hash holding string v array (array does NOT overwrite string)
121
- hash_src = {"property" => {"bedroom_count" => "3", "bathroom_count" => ["1", "4+"]}}
122
- hash_dst = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2"]}}
123
- DeepMerge::deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true})
124
- assert_equal({"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2","1","4+"]}}, hash_dst)
125
-
126
- # hash holding hash holding hash v array (array is overwritten by hash)
127
- hash_src = {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["1", "4+"]}}
128
- hash_dst = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2"]}}
129
- DeepMerge::deep_merge!(hash_src, hash_dst)
130
- assert_equal({"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["2","1","4+"]}}, hash_dst)
131
-
132
- # hash holding hash holding hash v array (array is NOT overwritten by hash)
133
- hash_src = {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["1", "4+"]}}
134
- hash_dst = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2"]}}
135
- DeepMerge::deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true})
136
- assert_equal({"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2","1","4+"]}}, hash_dst)
137
-
138
- # 3 hash layers holding integers (integers are overwritten by source)
139
- hash_src = {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["1", "4+"]}}
140
- hash_dst = {"property" => {"bedroom_count" => {"king_bed" => 2, "queen_bed" => 4}, "bathroom_count" => ["2"]}}
141
- DeepMerge::deep_merge!(hash_src, hash_dst)
142
- assert_equal({"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["2","1","4+"]}}, hash_dst)
143
-
144
- # 3 hash layers holding arrays of int (arrays are merged)
145
- hash_src = {"property" => {"bedroom_count" => {"king_bed" => [3], "queen_bed" => [1]}, "bathroom_count" => ["1", "4+"]}}
146
- hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
147
- DeepMerge::deep_merge!(hash_src, hash_dst)
148
- assert_equal({"property" => {"bedroom_count" => {"king_bed" => [2,3], "queen_bed" => [4,1]}, "bathroom_count" => ["2","1","4+"]}}, hash_dst)
149
-
150
- # 1 hash overwriting 3 hash layers holding arrays of int
151
- hash_src = {"property" => "1"}
152
- hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
153
- DeepMerge::deep_merge!(hash_src, hash_dst)
154
- assert_equal({"property" => "1"}, hash_dst)
155
-
156
- # 1 hash NOT overwriting 3 hash layers holding arrays of int
157
- hash_src = {"property" => "1"}
158
- hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
159
- DeepMerge::deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true})
160
- assert_equal({"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}, hash_dst)
161
-
162
- # 3 hash layers holding arrays of int (arrays are merged) but second hash's array is overwritten
163
- hash_src = {"property" => {"bedroom_count" => {"king_bed" => [3], "queen_bed" => [1]}, "bathroom_count" => "1"}}
164
- hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
165
- DeepMerge::deep_merge!(hash_src, hash_dst)
166
- assert_equal({"property" => {"bedroom_count" => {"king_bed" => [2,3], "queen_bed" => [4,1]}, "bathroom_count" => "1"}}, hash_dst)
167
-
168
- # 3 hash layers holding arrays of int (arrays are merged) but second hash's array is NOT overwritten
169
- hash_src = {"property" => {"bedroom_count" => {"king_bed" => [3], "queen_bed" => [1]}, "bathroom_count" => "1"}}
170
- hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
171
- DeepMerge::deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true})
172
- assert_equal({"property" => {"bedroom_count" => {"king_bed" => [2,3], "queen_bed" => [4,1]}, "bathroom_count" => ["2"]}}, hash_dst)
173
-
174
- # 3 hash layers holding arrays of int, but one holds int. This one overwrites, but the rest merge
175
- hash_src = {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => [1]}, "bathroom_count" => ["1"]}}
176
- hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
177
- DeepMerge::deep_merge!(hash_src, hash_dst)
178
- assert_equal({"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => [4,1]}, "bathroom_count" => ["2","1"]}}, hash_dst)
179
-
180
- # 3 hash layers holding arrays of int, but source is incomplete.
181
- hash_src = {"property" => {"bedroom_count" => {"king_bed" => [3]}, "bathroom_count" => ["1"]}}
182
- hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
183
- DeepMerge::deep_merge!(hash_src, hash_dst)
184
- assert_equal({"property" => {"bedroom_count" => {"king_bed" => [2,3], "queen_bed" => [4]}, "bathroom_count" => ["2","1"]}}, hash_dst)
185
-
186
- # 3 hash layers holding arrays of int, but source is shorter and has new 2nd level ints.
187
- hash_src = {"property" => {"bedroom_count" => {2=>3, "king_bed" => [3]}, "bathroom_count" => ["1"]}}
188
- hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
189
- DeepMerge::deep_merge!(hash_src, hash_dst)
190
- assert_equal({"property" => {"bedroom_count" => {2=>3, "king_bed" => [2,3], "queen_bed" => [4]}, "bathroom_count" => ["2","1"]}}, hash_dst)
191
-
192
- # 3 hash layers holding arrays of int, but source is empty
193
- hash_src = {}
194
- hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
195
- DeepMerge::deep_merge!(hash_src, hash_dst)
196
- assert_equal({"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}, hash_dst)
197
-
198
- # 3 hash layers holding arrays of int, but dest is empty
199
- hash_src = {"property" => {"bedroom_count" => {2=>3, "king_bed" => [3]}, "bathroom_count" => ["1"]}}
200
- hash_dst = {}
201
- DeepMerge::deep_merge!(hash_src, hash_dst)
202
- assert_equal({"property" => {"bedroom_count" => {2=>3, "king_bed" => [3]}, "bathroom_count" => ["1"]}}, hash_dst)
203
-
204
- # 3 hash layers holding arrays of int, but source includes a nil in the array
205
- hash_src = {"property" => {"bedroom_count" => {"king_bed" => [nil], "queen_bed" => [1, nil]}, "bathroom_count" => [nil, "1"]}}
206
- hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}
207
- DeepMerge::deep_merge!(hash_src, hash_dst)
208
- assert_equal({"property" => {"bedroom_count" => {"king_bed" => [2,nil], "queen_bed" => [4, 1, nil]}, "bathroom_count" => ["2", nil, "1"]}}, hash_dst)
209
-
210
- # 3 hash layers holding arrays of int, but destination includes a nil in the array
211
- hash_src = {"property" => {"bedroom_count" => {"king_bed" => [3], "queen_bed" => [1]}, "bathroom_count" => ["1"]}}
212
- hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [nil], "queen_bed" => [4, nil]}, "bathroom_count" => [nil,"2"]}}
213
- DeepMerge::deep_merge!(hash_src, hash_dst)
214
- assert_equal({"property" => {"bedroom_count" => {"king_bed" => [nil, 3], "queen_bed" => [4, nil, 1]}, "bathroom_count" => [nil, "2", "1"]}}, hash_dst)
215
-
216
- # test parameter management for knockout_prefix and overwrite unmergeable
217
- assert_raise(DeepMerge::InvalidParameter) {DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => ""})}
218
- assert_raise(DeepMerge::InvalidParameter) {DeepMerge::deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true, :knockout_prefix => ""})}
219
- assert_raise(DeepMerge::InvalidParameter) {DeepMerge::deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true, :knockout_prefix => "--"})}
220
- assert_nothing_raised(DeepMerge::InvalidParameter) {DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => "--"})}
221
- assert_nothing_raised(DeepMerge::InvalidParameter) {DeepMerge::deep_merge!(hash_src, hash_dst)}
222
- assert_nothing_raised(DeepMerge::InvalidParameter) {DeepMerge::deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true})}
223
-
224
- # hash holding arrays of arrays
225
- hash_src = {["1", "2", "3"] => ["1", "2"]}
226
- hash_dst = {["4", "5"] => ["3"]}
227
- DeepMerge::deep_merge!(hash_src, hash_dst)
228
- assert_equal({["1","2","3"] => ["1", "2"], ["4", "5"] => ["3"]}, hash_dst)
229
-
230
- # test merging of hash with blank hash, and make sure that source array split still functions
231
- hash_src = {'property' => {'bedroom_count' => ["1","2,3"]}}
232
- hash_dst = {}
233
- DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
234
- assert_equal({'property' => {'bedroom_count' => ["1","2","3"]}}, hash_dst)
235
-
236
- # test merging of hash with blank hash, and make sure that source array split does not function when turned off
237
- hash_src = {'property' => {'bedroom_count' => ["1","2,3"]}}
238
- hash_dst = {}
239
- DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX})
240
- assert_equal({'property' => {'bedroom_count' => ["1","2,3"]}}, hash_dst)
241
-
242
- # test merging into a blank hash with overwrite_unmergeables turned on
243
- hash_src = {"action"=>"browse", "controller"=>"results"}
244
- hash_dst = {}
245
- DeepMerge::deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
246
- assert_equal hash_src, hash_dst
247
-
248
- # KNOCKOUT_PREFIX testing
249
- # the next few tests are looking for correct behavior from specific real-world params/session merges
250
- # using the custom modifiers built for param/session merges
251
-
252
- [nil, ","].each do |ko_split|
253
- # typical params/session style hash with knockout_merge elements
254
- hash_params = {"property"=>{"bedroom_count"=>[FIELD_KNOCKOUT_PREFIX+"1", "2", "3"]}}
255
- hash_session = {"property"=>{"bedroom_count"=>["1", "2", "3"]}}
256
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ko_split})
257
- assert_equal({"property"=>{"bedroom_count"=>["2", "3"]}}, hash_session)
258
-
259
- # typical params/session style hash with knockout_merge elements
260
- hash_params = {"property"=>{"bedroom_count"=>[FIELD_KNOCKOUT_PREFIX+"1", "2", "3"]}}
261
- hash_session = {"property"=>{"bedroom_count"=>["3"]}}
262
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ko_split})
263
- assert_equal({"property"=>{"bedroom_count"=>["3","2"]}}, hash_session)
264
-
265
- # typical params/session style hash with knockout_merge elements
266
- hash_params = {"property"=>{"bedroom_count"=>[FIELD_KNOCKOUT_PREFIX+"1", "2", "3"]}}
267
- hash_session = {"property"=>{"bedroom_count"=>["4"]}}
268
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ko_split})
269
- assert_equal({"property"=>{"bedroom_count"=>["4","2","3"]}}, hash_session)
270
-
271
- # typical params/session style hash with knockout_merge elements
272
- hash_params = {"property"=>{"bedroom_count"=>[FIELD_KNOCKOUT_PREFIX+"1", "2", "3"]}}
273
- hash_session = {"property"=>{"bedroom_count"=>[FIELD_KNOCKOUT_PREFIX+"1", "4"]}}
274
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ko_split})
275
- assert_equal({"property"=>{"bedroom_count"=>["4","2","3"]}}, hash_session)
276
-
277
- # typical params/session style hash with knockout_merge elements
278
- hash_params = {"amenity"=>{"id"=>[FIELD_KNOCKOUT_PREFIX+"1", FIELD_KNOCKOUT_PREFIX+"2", "3", "4"]}}
279
- hash_session = {"amenity"=>{"id"=>["1", "2"]}}
280
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ko_split})
281
- assert_equal({"amenity"=>{"id"=>["3","4"]}}, hash_session)
282
- end
283
-
284
- # special params/session style hash with knockout_merge elements in form src: ["1","2"] dest:["--1,--2", "3,4"]
285
- hash_params = {"amenity"=>{"id"=>[FIELD_KNOCKOUT_PREFIX+"1,"+FIELD_KNOCKOUT_PREFIX+"2", "3,4"]}}
286
- hash_session = {"amenity"=>{"id"=>["1", "2"]}}
287
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
288
- assert_equal({"amenity"=>{"id"=>["3","4"]}}, hash_session)
289
-
290
- # same as previous but without ko_split value, this merge should fail
291
- hash_params = {"amenity"=>{"id"=>[FIELD_KNOCKOUT_PREFIX+"1,"+FIELD_KNOCKOUT_PREFIX+"2", "3,4"]}}
292
- hash_session = {"amenity"=>{"id"=>["1", "2"]}}
293
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX})
294
- assert_equal({"amenity"=>{"id"=>["1","2","3,4"]}}, hash_session)
295
-
296
- # special params/session style hash with knockout_merge elements in form src: ["1","2"] dest:["--1,--2", "3,4"]
297
- hash_params = {"amenity"=>{"id"=>[FIELD_KNOCKOUT_PREFIX+"1,2", "3,4", "--5", "6"]}}
298
- hash_session = {"amenity"=>{"id"=>["1", "2"]}}
299
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
300
- assert_equal({"amenity"=>{"id"=>["2","3","4","6"]}}, hash_session)
301
-
302
- # special params/session style hash with knockout_merge elements in form src: ["--1,--2", "3,4", "--5", "6"] dest:["1,2", "3,4"]
303
- hash_params = {"amenity"=>{"id"=>["#{FIELD_KNOCKOUT_PREFIX}1,#{FIELD_KNOCKOUT_PREFIX}2", "3,4", "#{FIELD_KNOCKOUT_PREFIX}5", "6"]}}
304
- hash_session = {"amenity"=>{"id"=>["1", "2", "3", "4"]}}
305
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
306
- assert_equal({"amenity"=>{"id"=>["3","4","6"]}}, hash_session)
307
-
308
-
309
- hash_src = {"url_regions"=>[], "region"=>{"ids"=>["227,233"]}, "action"=>"browse", "task"=>"browse", "controller"=>"results"}
310
- hash_dst = {"region"=>{"ids"=>["227"]}}
311
- DeepMerge::deep_merge!(hash_src.dup, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
312
- assert_equal({"url_regions"=>[], "region"=>{"ids"=>["227","233"]}, "action"=>"browse", "task"=>"browse", "controller"=>"results"}, hash_dst)
313
-
314
- hash_src = {"region"=>{"ids"=>["--","227"], "id"=>"230"}}
315
- hash_dst = {"region"=>{"ids"=>["227", "233", "324", "230", "230"], "id"=>"230"}}
316
- DeepMerge::deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
317
- assert_equal({"region"=>{"ids"=>["227"], "id"=>"230"}}, hash_dst)
318
-
319
- hash_src = {"region"=>{"ids"=>["--","227", "232", "233"], "id"=>"232"}}
320
- hash_dst = {"region"=>{"ids"=>["227", "233", "324", "230", "230"], "id"=>"230"}}
321
- DeepMerge::deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
322
- assert_equal({"region"=>{"ids"=>["227", "232", "233"], "id"=>"232"}}, hash_dst)
323
-
324
- hash_src = {"region"=>{"ids"=>["--,227,232,233"], "id"=>"232"}}
325
- hash_dst = {"region"=>{"ids"=>["227", "233", "324", "230", "230"], "id"=>"230"}}
326
- DeepMerge::deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
327
- assert_equal({"region"=>{"ids"=>["227", "232", "233"], "id"=>"232"}}, hash_dst)
328
-
329
- hash_src = {"region"=>{"ids"=>["--,227,232","233"], "id"=>"232"}}
330
- hash_dst = {"region"=>{"ids"=>["227", "233", "324", "230", "230"], "id"=>"230"}}
331
- DeepMerge::deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
332
- assert_equal({"region"=>{"ids"=>["227", "232", "233"], "id"=>"232"}}, hash_dst)
333
-
334
- hash_src = {"region"=>{"ids"=>["--,227"], "id"=>"230"}}
335
- hash_dst = {"region"=>{"ids"=>["227", "233", "324", "230", "230"], "id"=>"230"}}
336
- DeepMerge::deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
337
- assert_equal({"region"=>{"ids"=>["227"], "id"=>"230"}}, hash_dst)
338
-
339
- hash_src = {"region"=>{"ids"=>["--,227"], "id"=>"230"}}
340
- hash_dst = {"region"=>{"ids"=>["227", "233", "324", "230", "230"], "id"=>"230"}, "action"=>"browse", "task"=>"browse", "controller"=>"results", "property_order_by"=>"property_type.descr"}
341
- DeepMerge::deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
342
- assert_equal({"region"=>{"ids"=>["227"], "id"=>"230"}, "action"=>"browse", "task"=>"browse",
343
- "controller"=>"results", "property_order_by"=>"property_type.descr"}, hash_dst)
344
-
345
- hash_src = {"query_uuid"=>"6386333d-389b-ab5c-8943-6f3a2aa914d7", "region"=>{"ids"=>["--,227"], "id"=>"230"}}
346
- 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"}
347
- DeepMerge::deep_merge!(hash_src, hash_dst, {:overwrite_unmergeables => true, :knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
348
- assert_equal({"query_uuid" => "6386333d-389b-ab5c-8943-6f3a2aa914d7", "url_regions"=>[],
349
- "region"=>{"ids"=>["227"], "id"=>"230"}, "action"=>"browse", "task"=>"browse",
350
- "controller"=>"results", "property_order_by"=>"property_type.descr"}, hash_dst)
351
-
352
- # knock out entire dest hash if "--" is passed for source
353
- hash_params = {'amenity' => "--"}
354
- hash_session = {"amenity" => "1"}
355
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => "--", :unpack_arrays => ","})
356
- assert_equal({'amenity' => ""}, hash_session)
357
-
358
- # knock out entire dest hash if "--" is passed for source
359
- hash_params = {'amenity' => ["--"]}
360
- hash_session = {"amenity" => "1"}
361
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => "--", :unpack_arrays => ","})
362
- assert_equal({'amenity' => []}, hash_session)
363
-
364
- # knock out entire dest hash if "--" is passed for source
365
- hash_params = {'amenity' => "--"}
366
- hash_session = {"amenity" => ["1"]}
367
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => "--", :unpack_arrays => ","})
368
- assert_equal({'amenity' => ""}, hash_session)
369
-
370
- # knock out entire dest hash if "--" is passed for source
371
- hash_params = {'amenity' => ["--"]}
372
- hash_session = {"amenity" => ["1"]}
373
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => "--", :unpack_arrays => ","})
374
- assert_equal({'amenity' => []}, hash_session)
375
-
376
- # knock out entire dest hash if "--" is passed for source
377
- hash_params = {'amenity' => ["--"]}
378
- hash_session = {"amenity" => "1"}
379
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => "--", :unpack_arrays => ","})
380
- assert_equal({'amenity' => []}, hash_session)
381
-
382
- # knock out entire dest hash if "--" is passed for source
383
- hash_params = {'amenity' => ["--", "2"]}
384
- hash_session = {'amenity' => ["1", "3", "7+"]}
385
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => "--", :unpack_arrays => ","})
386
- assert_equal({'amenity' => ["2"]}, hash_session)
387
-
388
- # knock out entire dest hash if "--" is passed for source
389
- hash_params = {'amenity' => ["--", "2"]}
390
- hash_session = {'amenity' => "5"}
391
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => "--", :unpack_arrays => ","})
392
- assert_equal({'amenity' => ['2']}, hash_session)
393
-
394
- # knock out entire dest hash if "--" is passed for source
395
- hash_params = {'amenity' => "--"}
396
- hash_session = {"amenity"=>{"id"=>["1", "2", "3", "4"]}}
397
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => "--", :unpack_arrays => ","})
398
- assert_equal({'amenity' => ""}, hash_session)
399
-
400
- # knock out entire dest hash if "--" is passed for source
401
- hash_params = {'amenity' => ["--"]}
402
- hash_session = {"amenity"=>{"id"=>["1", "2", "3", "4"]}}
403
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => "--", :unpack_arrays => ","})
404
- assert_equal({'amenity' => []}, hash_session)
405
-
406
- # knock out dest array if "--" is passed for source
407
- hash_params = {"region" => {'ids' => FIELD_KNOCKOUT_PREFIX}}
408
- hash_session = {"region"=>{"ids"=>["1", "2", "3", "4"]}}
409
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
410
- assert_equal({'region' => {'ids' => ""}}, hash_session)
411
-
412
- # knock out dest array but leave other elements of hash intact
413
- hash_params = {"region" => {'ids' => FIELD_KNOCKOUT_PREFIX}}
414
- hash_session = {"region"=>{"ids"=>["1", "2", "3", "4"], 'id'=>'11'}}
415
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
416
- assert_equal({'region' => {'ids' => "", 'id'=>'11'}}, hash_session)
417
-
418
- # knock out entire tree of dest hash
419
- hash_params = {"region" => FIELD_KNOCKOUT_PREFIX}
420
- hash_session = {"region"=>{"ids"=>["1", "2", "3", "4"], 'id'=>'11'}}
421
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
422
- assert_equal({'region' => ""}, hash_session)
423
-
424
- # knock out entire tree of dest hash - retaining array format
425
- hash_params = {"region" => {'ids' => [FIELD_KNOCKOUT_PREFIX]}}
426
- hash_session = {"region"=>{"ids"=>["1", "2", "3", "4"], 'id'=>'11'}}
427
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
428
- assert_equal({'region' => {'ids' => [], 'id'=>'11'}}, hash_session)
429
-
430
- # knock out entire tree of dest hash & replace with new content
431
- hash_params = {"region" => {'ids' => ["2", FIELD_KNOCKOUT_PREFIX, "6"]}}
432
- hash_session = {"region"=>{"ids"=>["1", "2", "3", "4"], 'id'=>'11'}}
433
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
434
- assert_equal({'region' => {'ids' => ["2", "6"], 'id'=>'11'}}, hash_session)
435
-
436
- # knock out entire tree of dest hash & replace with new content
437
- hash_params = {"region" => {'ids' => ["7", FIELD_KNOCKOUT_PREFIX, "6"]}}
438
- hash_session = {"region"=>{"ids"=>["1", "2", "3", "4"], 'id'=>'11'}}
439
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
440
- assert_equal({'region' => {'ids' => ["7", "6"], 'id'=>'11'}}, hash_session)
441
-
442
- # edge test: make sure that when we turn off knockout_prefix that all values are processed correctly
443
- hash_params = {"region" => {'ids' => ["7", "--", "2", "6,8"]}}
444
- hash_session = {"region"=>{"ids"=>["1", "2", "3", "4"], 'id'=>'11'}}
445
- DeepMerge::deep_merge!(hash_params, hash_session, {:unpack_arrays => ","})
446
- assert_equal({'region' => {'ids' => ["1", "2", "3", "4", "7", "--", "6", "8"], 'id'=>'11'}}, hash_session)
447
-
448
- # edge test 2: make sure that when we turn off source array split that all values are processed correctly
449
- hash_params = {"region" => {'ids' => ["7", "3", "--", "6,8"]}}
450
- hash_session = {"region"=>{"ids"=>["1", "2", "3", "4"], 'id'=>'11'}}
451
- DeepMerge::deep_merge!(hash_params, hash_session)
452
- assert_equal({'region' => {'ids' => ["1", "2", "3", "4", "7", "--", "6,8"], 'id'=>'11'}}, hash_session)
453
-
454
- # Example: src = {'key' => "--1"}, dst = {'key' => "1"} -> merges to {'key' => ""}
455
- hash_params = {"amenity"=>"--1"}
456
- hash_session = {"amenity"=>"1"}
457
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX})
458
- assert_equal({"amenity"=>""}, hash_session)
459
-
460
- # Example: src = {'key' => "--1"}, dst = {'key' => "2"} -> merges to {'key' => ""}
461
- hash_params = {"amenity"=>"--1"}
462
- hash_session = {"amenity"=>"2"}
463
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX})
464
- assert_equal({"amenity"=>""}, hash_session)
465
-
466
- # Example: src = {'key' => "--1"}, dst = {'key' => "1"} -> merges to {'key' => ""}
467
- hash_params = {"amenity"=>["--1"]}
468
- hash_session = {"amenity"=>"1"}
469
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX})
470
- assert_equal({"amenity"=>[]}, hash_session)
471
-
472
- # Example: src = {'key' => "--1"}, dst = {'key' => "1"} -> merges to {'key' => ""}
473
- hash_params = {"amenity"=>["--1"]}
474
- hash_session = {"amenity"=>["1"]}
475
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX})
476
- assert_equal({"amenity"=>[]}, hash_session)
477
-
478
- # Example: src = {'key' => "--1"}, dst = {'key' => "1"} -> merges to {'key' => ""}
479
- hash_params = {"amenity"=>"--1"}
480
- hash_session = {}
481
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX})
482
- assert_equal({"amenity"=>""}, hash_session)
483
-
484
-
485
- # Example: src = {'key' => "--1"}, dst = {'key' => "1"} -> merges to {'key' => ""}
486
- hash_params = {"amenity"=>"--1"}
487
- hash_session = {"amenity"=>["1"]}
488
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX})
489
- assert_equal({"amenity"=>""}, hash_session)
490
-
491
- #are unmerged hashes passed unmodified w/out :unpack_arrays?
492
- hash_params = {"amenity"=>{"id"=>["26,27"]}}
493
- hash_session = {}
494
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX})
495
- assert_equal({"amenity"=>{"id"=>["26,27"]}}, hash_session)
496
-
497
- #hash should be merged
498
- hash_params = {"amenity"=>{"id"=>["26,27"]}}
499
- hash_session = {}
500
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
501
- assert_equal({"amenity"=>{"id"=>["26","27"]}}, hash_session)
502
-
503
- # second merge of same values should result in no change in output
504
- hash_params = {"amenity"=>{"id"=>["26,27"]}}
505
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
506
- assert_equal({"amenity"=>{"id"=>["26","27"]}}, hash_session)
507
-
508
- #hashes with knockout values are suppressed
509
- hash_params = {"amenity"=>{"id"=>["#{FIELD_KNOCKOUT_PREFIX}26,#{FIELD_KNOCKOUT_PREFIX}27,28"]}}
510
- hash_session = {}
511
- DeepMerge::deep_merge!(hash_params, hash_session, {:knockout_prefix => FIELD_KNOCKOUT_PREFIX, :unpack_arrays => ","})
512
- assert_equal({"amenity"=>{"id"=>["28"]}}, hash_session)
513
-
514
- hash_src= {'region' =>{'ids'=>['--']}, 'query_uuid' => 'zzz'}
515
- hash_dst= {'region' =>{'ids'=>['227','2','3','3']}, 'query_uuid' => 'zzz'}
516
- DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => '--', :unpack_arrays => ","})
517
- assert_equal({'region' =>{'ids'=>[]}, 'query_uuid' => 'zzz'}, hash_dst)
518
-
519
- hash_src= {'region' =>{'ids'=>['--']}, 'query_uuid' => 'zzz'}
520
- hash_dst= {'region' =>{'ids'=>['227','2','3','3'], 'id' => '3'}, 'query_uuid' => 'zzz'}
521
- DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => '--', :unpack_arrays => ","})
522
- assert_equal({'region' =>{'ids'=>[], 'id'=>'3'}, 'query_uuid' => 'zzz'}, hash_dst)
523
-
524
- hash_src= {'region' =>{'ids'=>['--']}, 'query_uuid' => 'zzz'}
525
- hash_dst= {'region' =>{'muni_city_id' => '2244', 'ids'=>['227','2','3','3'], 'id'=>'3'}, 'query_uuid' => 'zzz'}
526
- DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => '--', :unpack_arrays => ","})
527
- assert_equal({'region' =>{'muni_city_id' => '2244', 'ids'=>[], 'id'=>'3'}, 'query_uuid' => 'zzz'}, hash_dst)
528
-
529
- hash_src= {'region' =>{'ids'=>['--'], 'id' => '5'}, 'query_uuid' => 'zzz'}
530
- hash_dst= {'region' =>{'muni_city_id' => '2244', 'ids'=>['227','2','3','3'], 'id'=>'3'}, 'query_uuid' => 'zzz'}
531
- DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => '--', :unpack_arrays => ","})
532
- assert_equal({'region' =>{'muni_city_id' => '2244', 'ids'=>[], 'id'=>'5'}, 'query_uuid' => 'zzz'}, hash_dst)
533
-
534
- hash_src= {'region' =>{'ids'=>['--', '227'], 'id' => '5'}, 'query_uuid' => 'zzz'}
535
- hash_dst= {'region' =>{'muni_city_id' => '2244', 'ids'=>['227','2','3','3'], 'id'=>'3'}, 'query_uuid' => 'zzz'}
536
- DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => '--', :unpack_arrays => ","})
537
- assert_equal({'region' =>{'muni_city_id' => '2244', 'ids'=>['227'], 'id'=>'5'}, 'query_uuid' => 'zzz'}, hash_dst)
538
-
539
- hash_src= {'region' =>{'muni_city_id' => '--', 'ids'=>'--', 'id'=>'5'}, 'query_uuid' => 'zzz'}
540
- hash_dst= {'region' =>{'muni_city_id' => '2244', 'ids'=>['227','2','3','3'], 'id'=>'3'}, 'query_uuid' => 'zzz'}
541
- DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => '--', :unpack_arrays => ","})
542
- assert_equal({'region' =>{'muni_city_id' => '', 'ids'=>'', 'id'=>'5'}, 'query_uuid' => 'zzz'}, hash_dst)
543
-
544
- hash_src= {'region' =>{'muni_city_id' => '--', 'ids'=>['--'], 'id'=>'5'}, 'query_uuid' => 'zzz'}
545
- hash_dst= {'region' =>{'muni_city_id' => '2244', 'ids'=>['227','2','3','3'], 'id'=>'3'}, 'query_uuid' => 'zzz'}
546
- DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => '--', :unpack_arrays => ","})
547
- assert_equal({'region' =>{'muni_city_id' => '', 'ids'=>[], 'id'=>'5'}, 'query_uuid' => 'zzz'}, hash_dst)
548
-
549
- hash_src= {'region' =>{'muni_city_id' => '--', 'ids'=>['--','227'], 'id'=>'5'}, 'query_uuid' => 'zzz'}
550
- hash_dst= {'region' =>{'muni_city_id' => '2244', 'ids'=>['227','2','3','3'], 'id'=>'3'}, 'query_uuid' => 'zzz'}
551
- DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => '--', :unpack_arrays => ","})
552
- assert_equal({'region' =>{'muni_city_id' => '', 'ids'=>['227'], 'id'=>'5'}, 'query_uuid' => 'zzz'}, hash_dst)
553
-
554
- hash_src = {"muni_city_id"=>"--", "id"=>""}
555
- hash_dst = {"muni_city_id"=>"", "id"=>""}
556
- DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => '--', :unpack_arrays => ","})
557
- assert_equal({"muni_city_id"=>"", "id"=>""}, hash_dst)
558
-
559
- hash_src = {"region"=>{"muni_city_id"=>"--", "id"=>""}}
560
- hash_dst = {"region"=>{"muni_city_id"=>"", "id"=>""}}
561
- DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => '--', :unpack_arrays => ","})
562
- assert_equal({"region"=>{"muni_city_id"=>"", "id"=>""}}, hash_dst)
563
-
564
- hash_src = {"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"}
565
- 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"}
566
- DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => '--', :unpack_arrays => ","})
567
- assert_equal({"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"}, hash_dst)
568
-
569
- # hash of array of hashes
570
- hash_src = {"item" => [{"1" => "3"}, {"2" => "4"}]}
571
- hash_dst = {"item" => [{"3" => "5"}]}
572
- DeepMerge::deep_merge!(hash_src, hash_dst)
573
- assert_equal({"item" => [{"3" => "5"}, {"1" => "3"}, {"2" => "4"}]}, hash_dst)
574
-
575
- ######################################
576
- # tests for "merge_hash_arrays" option
577
-
578
- hash_src = {"item" => [{"1" => "3"}]}
579
- hash_dst = {"item" => [{"3" => "5"}]}
580
- DeepMerge::deep_merge!(hash_src, hash_dst, {:merge_hash_arrays => true})
581
- assert_equal({"item" => [{"3" => "5", "1" => "3"}]}, hash_dst)
582
-
583
- hash_src = {"item" => [{"1" => "3"}, {"2" => "4"}]}
584
- hash_dst = {"item" => [{"3" => "5"}]}
585
- DeepMerge::deep_merge!(hash_src, hash_dst, {:merge_hash_arrays => true})
586
- assert_equal({"item" => [{"3" => "5", "1" => "3"}, {"2" => "4"}]}, hash_dst)
587
-
588
- hash_src = {"item" => [{"1" => "3"}]}
589
- hash_dst = {"item" => [{"3" => "5"}, {"2" => "4"}]}
590
- DeepMerge::deep_merge!(hash_src, hash_dst, {:merge_hash_arrays => true})
591
- assert_equal({"item" => [{"3" => "5", "1" => "3"}, {"2" => "4"}]}, hash_dst)
592
-
593
- # if arrays contain non-hash objects, the :merge_hash_arrays option has
594
- # no effect.
595
- hash_src = {"item" => [{"1" => "3"}, "str"]} # contains "str", non-hash
596
- hash_dst = {"item" => [{"3" => "5"}]}
597
- DeepMerge::deep_merge!(hash_src, hash_dst, {:merge_hash_arrays => true})
598
- assert_equal({"item" => [{"3" => "5"}, {"1" => "3"}, "str"]}, hash_dst)
599
-
600
- # Merging empty strings
601
- s1, s2 = "hello", ""
602
- [s1, s2].each { |s| s.extend StringBlank }
603
- hash_dst = {"item" => s1 }
604
- hash_src = {"item" => s2 }
605
- DeepMerge::deep_merge!(hash_src, hash_dst)
606
- assert_equal({"item" => ""}, hash_dst)
607
- end # test_deep_merge
608
- end