hammer_cli 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/config/cli_config.template.yml +4 -1
  3. data/doc/development_tips.md +2 -2
  4. data/doc/release_notes.md +13 -1
  5. data/lib/hammer_cli/apipie/option_definition.rb +3 -0
  6. data/lib/hammer_cli/defaults.rb +35 -16
  7. data/lib/hammer_cli/defaults_commands.rb +2 -2
  8. data/lib/hammer_cli/logger.rb +1 -1
  9. data/lib/hammer_cli/options/normalizers.rb +22 -10
  10. data/lib/hammer_cli/output/adapter/abstract.rb +5 -0
  11. data/lib/hammer_cli/output/adapter/csv.rb +5 -0
  12. data/lib/hammer_cli/output/adapter/table.rb +5 -0
  13. data/lib/hammer_cli/output/adapter/tree_structure.rb +5 -0
  14. data/lib/hammer_cli/output/output.rb +1 -1
  15. data/lib/hammer_cli/output/record_collection.rb +8 -4
  16. data/lib/hammer_cli/settings.rb +2 -0
  17. data/lib/hammer_cli/validator.rb +49 -1
  18. data/lib/hammer_cli/version.rb +1 -1
  19. data/locale/ca/LC_MESSAGES/hammer-cli.mo +0 -0
  20. data/locale/ca/hammer-cli.edit.po +411 -0
  21. data/locale/ca/hammer-cli.po +338 -0
  22. data/locale/ca/hammer-cli.po.time_stamp +0 -0
  23. data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
  24. data/locale/de/hammer-cli.edit.po +16 -16
  25. data/locale/de/hammer-cli.po +25 -5
  26. data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
  27. data/locale/en/hammer-cli.edit.po +46 -26
  28. data/locale/en/hammer-cli.po +20 -3
  29. data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
  30. data/locale/en_GB/hammer-cli.edit.po +25 -25
  31. data/locale/en_GB/hammer-cli.po +25 -5
  32. data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
  33. data/locale/es/hammer-cli.po +24 -6
  34. data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
  35. data/locale/fr/hammer-cli.edit.po +26 -26
  36. data/locale/fr/hammer-cli.po +24 -6
  37. data/locale/hammer-cli.pot +50 -28
  38. data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
  39. data/locale/it/hammer-cli.edit.po +9 -9
  40. data/locale/it/hammer-cli.po +25 -5
  41. data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
  42. data/locale/ja/hammer-cli.edit.po +9 -9
  43. data/locale/ja/hammer-cli.po +25 -5
  44. data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
  45. data/locale/ko/hammer-cli.edit.po +9 -9
  46. data/locale/ko/hammer-cli.po +25 -5
  47. data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
  48. data/locale/pt_BR/hammer-cli.edit.po +6 -6
  49. data/locale/pt_BR/hammer-cli.po +25 -5
  50. data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
  51. data/locale/ru/hammer-cli.edit.po +31 -30
  52. data/locale/ru/hammer-cli.po +25 -5
  53. data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
  54. data/locale/zh_CN/hammer-cli.edit.po +9 -9
  55. data/locale/zh_CN/hammer-cli.po +26 -6
  56. data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
  57. data/locale/zh_TW/hammer-cli.edit.po +9 -9
  58. data/locale/zh_TW/hammer-cli.po +25 -5
  59. data/test/functional/defaults_test.rb +12 -0
  60. data/test/reports/TEST-Fields-ContainerField-display-.xml +1 -1
  61. data/test/reports/TEST-Fields-ContainerField-display-blank-is-allowed.xml +5 -5
  62. data/test/reports/TEST-Fields-ContainerField-display-blank-is-not-allowed.xml +5 -5
  63. data/test/reports/TEST-Fields-ContainerField.xml +1 -1
  64. data/test/reports/TEST-Fields-Field-display-.xml +1 -1
  65. data/test/reports/TEST-Fields-Field-display-blank-is-allowed.xml +3 -3
  66. data/test/reports/TEST-Fields-Field-display-blank-is-not-allowed.xml +3 -3
  67. data/test/reports/TEST-Fields-Field-hide-blank-.xml +3 -3
  68. data/test/reports/TEST-Fields-Field-parameters.xml +2 -2
  69. data/test/reports/TEST-Fields-Field.xml +4 -4
  70. data/test/reports/TEST-HammerCLI-AbstractCommand-build-options.xml +5 -5
  71. data/test/reports/TEST-HammerCLI-AbstractCommand-exception-handler.xml +4 -4
  72. data/test/reports/TEST-HammerCLI-AbstractCommand-logging.xml +8 -10
  73. data/test/reports/TEST-HammerCLI-AbstractCommand-option-builder.xml +3 -3
  74. data/test/reports/TEST-HammerCLI-AbstractCommand-options.xml +3 -3
  75. data/test/reports/TEST-HammerCLI-AbstractCommand-output.xml +7 -7
  76. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-remove-subcommand.xml +3 -3
  77. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand-.xml +4 -4
  78. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand.xml +3 -3
  79. data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior.xml +1 -1
  80. data/test/reports/TEST-HammerCLI-AbstractCommand.xml +3 -3
  81. data/test/reports/TEST-HammerCLI-Apipie-Command-options.xml +3 -3
  82. data/test/reports/TEST-HammerCLI-Apipie-Command-resource-defined.xml +2 -2
  83. data/test/reports/TEST-HammerCLI-Apipie-Command-setting-resources.xml +7 -7
  84. data/test/reports/TEST-HammerCLI-Apipie-Command.xml +2 -2
  85. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-aliasing-resources.xml +4 -4
  86. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-filtering-options.xml +5 -5
  87. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-required-options.xml +3 -3
  88. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-setting-correct-normalizers.xml +2 -8
  89. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-hash-params.xml +3 -3
  90. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-one-simple-param.xml +5 -5
  91. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder.xml +1 -1
  92. data/test/reports/TEST-HammerCLI-Completer-command-completion.xml +12 -12
  93. data/test/reports/TEST-HammerCLI-Completer-option-value-completion.xml +6 -6
  94. data/test/reports/TEST-HammerCLI-Completer-subcommand-completion.xml +7 -7
  95. data/test/reports/TEST-HammerCLI-Completer.xml +1 -1
  96. data/test/reports/TEST-HammerCLI-CompleterLine-line-complete.xml +10 -10
  97. data/test/reports/TEST-HammerCLI-CompleterLine-splitting-words.xml +12 -12
  98. data/test/reports/TEST-HammerCLI-CompleterLine.xml +1 -1
  99. data/test/reports/TEST-HammerCLI-CompleterWord-complete-.xml +9 -9
  100. data/test/reports/TEST-HammerCLI-CompleterWord-quote.xml +5 -5
  101. data/test/reports/TEST-HammerCLI-CompleterWord-quoted-.xml +4 -4
  102. data/test/reports/TEST-HammerCLI-CompleterWord.xml +1 -1
  103. data/test/reports/TEST-HammerCLI-Connection.xml +8 -8
  104. data/test/reports/TEST-HammerCLI-ExceptionHandler.xml +8 -8
  105. data/test/reports/TEST-HammerCLI-I18n.xml +3 -3
  106. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-password.xml +3 -3
  107. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-username.xml +3 -3
  108. data/test/reports/TEST-HammerCLI-MainCommand-loading-context-verbose.xml +2 -2
  109. data/test/reports/TEST-HammerCLI-MainCommand-loading-context.xml +1 -1
  110. data/test/reports/TEST-HammerCLI-MainCommand.xml +1 -1
  111. data/test/reports/TEST-HammerCLI-Modules-find-by-name.xml +4 -4
  112. data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-not-found.xml +4 -4
  113. data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-runtime-exception.xml +4 -4
  114. data/test/reports/TEST-HammerCLI-Modules-load-a-module-success.xml +5 -5
  115. data/test/reports/TEST-HammerCLI-Modules-load-a-module.xml +1 -1
  116. data/test/reports/TEST-HammerCLI-Modules-load-all-modules.xml +2 -4
  117. data/test/reports/TEST-HammerCLI-Modules-names.xml +4 -4
  118. data/test/reports/TEST-HammerCLI-Modules.xml +1 -1
  119. data/test/reports/TEST-HammerCLI-OptionBuilderContainer.0.xml +1 -5
  120. data/test/reports/TEST-HammerCLI-OptionBuilderContainer.xml +5 -1
  121. data/test/reports/TEST-HammerCLI-Options-Normalizers-abstract.xml +2 -2
  122. data/test/reports/TEST-HammerCLI-Options-Normalizers-bool.xml +13 -13
  123. data/test/reports/TEST-HammerCLI-Options-Normalizers-datetime.xml +6 -6
  124. data/test/reports/TEST-HammerCLI-Options-Normalizers-enum.xml +5 -5
  125. data/test/reports/TEST-HammerCLI-Options-Normalizers-enumlist.xml +8 -8
  126. data/test/reports/TEST-HammerCLI-Options-Normalizers-json-input.xml +5 -5
  127. data/test/reports/TEST-HammerCLI-Options-Normalizers-key-value-list.xml +6 -26
  128. data/test/reports/TEST-HammerCLI-Options-Normalizers-list.xml +5 -5
  129. data/test/reports/TEST-HammerCLI-Options-Normalizers.xml +1 -1
  130. data/test/reports/TEST-HammerCLI-Options-OptionDefinition-context.xml +2 -2
  131. data/test/reports/TEST-HammerCLI-Options-OptionDefinition-formatters.xml +3 -3
  132. data/test/reports/TEST-HammerCLI-Options-OptionDefinition.xml +1 -1
  133. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-error-messages.xml +5 -5
  134. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-messages.xml +3 -3
  135. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-test-data-for-field.xml +5 -5
  136. data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract.xml +6 -6
  137. data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection-show-ids.xml +2 -2
  138. data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection.xml +11 -11
  139. data/test/reports/TEST-HammerCLI-Output-Adapter-Base.xml +1 -1
  140. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-formatters.xml +3 -3
  141. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-collections.xml +4 -4
  142. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-containers.xml +3 -3
  143. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-ids.xml +3 -3
  144. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection.xml +3 -3
  145. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-message.xml +3 -3
  146. data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues.xml +1 -1
  147. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-column-width.xml +5 -11
  148. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-formatters.xml +3 -3
  149. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-handle-ids.xml +3 -7
  150. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-sort-columns.xml +2 -2
  151. data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection.xml +3 -3
  152. data/test/reports/TEST-HammerCLI-Output-Adapter-Table.xml +1 -1
  153. data/test/reports/TEST-HammerCLI-Output-Definition-empty-.xml +3 -3
  154. data/test/reports/TEST-HammerCLI-Output-Definition.xml +3 -3
  155. data/test/reports/TEST-HammerCLI-Output-Dsl-collection.xml +4 -4
  156. data/test/reports/TEST-HammerCLI-Output-Dsl-custom-fields.xml +3 -3
  157. data/test/reports/TEST-HammerCLI-Output-Dsl-fields.xml +5 -5
  158. data/test/reports/TEST-HammerCLI-Output-Dsl-label.xml +4 -4
  159. data/test/reports/TEST-HammerCLI-Output-Dsl-path-definition.xml +4 -4
  160. data/test/reports/TEST-HammerCLI-Output-Dsl.xml +2 -2
  161. data/test/reports/TEST-HammerCLI-Output-FieldFilter.xml +4 -4
  162. data/test/reports/TEST-HammerCLI-Output-Formatters-BooleanFormatter.xml +3 -3
  163. data/test/reports/TEST-HammerCLI-Output-Formatters-ColorFormatter.xml +2 -2
  164. data/test/reports/TEST-HammerCLI-Output-Formatters-DateFormatter.xml +3 -3
  165. data/test/reports/TEST-HammerCLI-Output-Formatters-FieldFormatter.xml +4 -4
  166. data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterContainer.xml +4 -4
  167. data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterLibrary.xml +3 -3
  168. data/test/reports/TEST-HammerCLI-Output-Formatters-KeyValueFormatter.xml +4 -4
  169. data/test/reports/TEST-HammerCLI-Output-Formatters-ListFormatter.xml +4 -4
  170. data/test/reports/TEST-HammerCLI-Output-Formatters-LongTextFormatter.xml +4 -4
  171. data/test/reports/TEST-HammerCLI-Output-Output-adapters.xml +6 -6
  172. data/test/reports/TEST-HammerCLI-Output-Output-data.xml +5 -5
  173. data/test/reports/TEST-HammerCLI-Output-Output-formatters.xml +2 -2
  174. data/test/reports/TEST-HammerCLI-Output-Output-messages.xml +7 -7
  175. data/test/reports/TEST-HammerCLI-Output-Output.xml +1 -1
  176. data/test/reports/TEST-HammerCLI-Output-RecordCollection.xml +4 -4
  177. data/test/reports/TEST-HammerCLI-Settings-load-from-paths.xml +5 -5
  178. data/test/reports/TEST-HammerCLI-Settings.xml +10 -10
  179. data/test/reports/TEST-HammerCLI-ShellHistory-loading-old-history.xml +3 -3
  180. data/test/reports/TEST-HammerCLI-ShellHistory-saving-history.xml +5 -5
  181. data/test/reports/TEST-HammerCLI-ShellHistory.xml +1 -1
  182. data/test/reports/TEST-MiniTest-Spec.xml +1 -1
  183. data/test/reports/TEST-String-camelize.xml +3 -3
  184. data/test/reports/TEST-String-formatting.xml +6 -6
  185. data/test/reports/TEST-String-indent.xml +3 -3
  186. data/test/reports/{TEST-HammerCLI-interactive-.xml → TEST-String-interactive-.xml} +4 -4
  187. data/test/reports/TEST-String.xml +1 -1
  188. data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint-exist-.xml +4 -4
  189. data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint.xml +1 -1
  190. data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint-exist-.xml +4 -4
  191. data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint.xml +1 -1
  192. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-exist-.xml +2 -2
  193. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-rejected.xml +4 -4
  194. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-required.xml +4 -4
  195. data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint.xml +1 -1
  196. data/test/reports/TEST-constraints.xml +1 -1
  197. data/test/unit/apipie/option_definition_test.rb +9 -0
  198. data/test/unit/defaults_test.rb +84 -22
  199. data/test/unit/fixtures/defaults/defaults_dashed.yml +6 -0
  200. data/test/unit/options/normalizers_test.rb +46 -34
  201. data/test/unit/output/adapter/abstract_test.rb +4 -0
  202. data/test/unit/output/adapter/base_test.rb +4 -0
  203. data/test/unit/output/adapter/csv_test.rb +4 -0
  204. data/test/unit/output/adapter/json_test.rb +4 -0
  205. data/test/unit/output/adapter/table_test.rb +19 -3
  206. data/test/unit/output/adapter/yaml_test.rb +4 -0
  207. data/test/unit/output/record_collection_test.rb +26 -0
  208. data/test/unit/settings_test.rb +11 -1
  209. data/test/unit/validator_test.rb +111 -6
  210. metadata +192 -247
  211. data/test/reports/TEST-Fields-Label-display-.xml +0 -7
  212. data/test/reports/TEST-Fields-Label-display-blank-is-allowed.xml +0 -15
  213. data/test/reports/TEST-Fields-Label-display-blank-is-not-allowed.xml +0 -15
  214. data/test/reports/TEST-Fields-Label.xml +0 -7
  215. data/test/reports/TEST-HammerCLI-Apipie-Command-reload-apipie-cache.xml +0 -11
  216. data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-setting-referenced-resources.xml +0 -9
  217. data/test/reports/TEST-HammerCLI-Apipie-OptionDefinition-referenced-resource.xml +0 -13
  218. data/test/reports/TEST-HammerCLI-Apipie-OptionDefinition.xml +0 -7
  219. data/test/reports/TEST-HammerCLI-Defaults.xml +0 -19
  220. data/test/reports/TEST-HammerCLI-Options-Matcher.xml +0 -17
  221. data/test/reports/TEST-HammerCLI-Options-Normalizers-number.xml +0 -11
  222. data/test/reports/TEST-HammerCLI-Options-OptionDefinition-deprecated-options.xml +0 -11
  223. data/test/reports/TEST-HammerCLI-Output-Adapter-Json-print-collection-show-ids.xml +0 -9
  224. data/test/reports/TEST-HammerCLI-Output-Adapter-Json-print-collection.xml +0 -27
  225. data/test/reports/TEST-HammerCLI-Output-Adapter-Json-print-message.xml +0 -11
  226. data/test/reports/TEST-HammerCLI-Output-Adapter-Json.xml +0 -7
  227. data/test/reports/TEST-HammerCLI-Output-Adapter-Yaml-print-collection-show-ids.xml +0 -9
  228. data/test/reports/TEST-HammerCLI-Output-Adapter-Yaml-print-collection.xml +0 -27
  229. data/test/reports/TEST-HammerCLI-Output-Adapter-Yaml-print-message.xml +0 -11
  230. data/test/reports/TEST-HammerCLI-Output-Adapter-Yaml.xml +0 -7
  231. data/test/reports/TEST-HammerCLI-constant-path.xml +0 -15
  232. data/test/reports/TEST-HammerCLI.xml +0 -7
  233. data/test/reports/TEST-Logging-LogEvent-filtering.xml +0 -9
  234. data/test/reports/TEST-Logging-LogEvent.xml +0 -7
  235. data/test/reports/TEST-String-constantize.xml +0 -15
  236. data/test/reports/TEST-String-underscore.xml +0 -13
  237. data/test/reports/TEST-commands-defaults-add.xml +0 -21
  238. data/test/reports/TEST-commands-defaults-delete.xml +0 -11
  239. data/test/reports/TEST-commands-defaults-list.xml +0 -11
  240. data/test/reports/TEST-commands-defaults-providers.xml +0 -11
  241. data/test/reports/TEST-commands.xml +0 -7
@@ -1,44 +1,106 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
  describe HammerCLI::Defaults do
3
3
 
4
- FILEPATH = File.join(File.dirname(__FILE__), '/fixtures/defaults/defaults.yml')
4
+ let(:filepath) { File.join(File.dirname(__FILE__), '/fixtures/defaults/defaults.yml') }
5
5
 
6
6
  before(:all) do
7
- settings = YAML::load(File.open(FILEPATH))
7
+ settings = YAML::load(File.open(filepath))
8
8
 
9
- @defaults = HammerCLI::Defaults.new(settings[:defaults], FILEPATH)
9
+ @defaults = HammerCLI::Defaults.new(settings[:defaults], filepath)
10
10
  @defaults.stubs(:write_to_file).returns true
11
11
  end
12
12
 
13
- it "Should add a default param to defaults file, without a provider" do
14
- defaults_result = @defaults.add_defaults_to_conf({"organization_id"=> 3}, nil)
15
- assert_equal 3, defaults_result[:defaults][:organization_id][:value]
16
- end
13
+ describe '#add_defaults_to_conf' do
14
+ it "Should add a default param to defaults file, without a provider" do
15
+ defaults_result = @defaults.add_defaults_to_conf({"organization_id"=> 3}, nil)
16
+ assert_equal 3, defaults_result[:defaults][:organization_id][:value]
17
+ end
18
+
19
+ it "Should update dashed default when underscored default is set" do
20
+ defaults_result = @defaults.add_defaults_to_conf({"location-id"=> 3}, nil)
21
+ assert_equal 3, defaults_result[:defaults][:'location-id'][:value]
22
+ assert_equal nil, defaults_result[:defaults][:location_id]
23
+ end
24
+
25
+ context "dashed" do
26
+ let(:filepath) { File.join(File.dirname(__FILE__), '/fixtures/defaults/defaults_dashed.yml') }
27
+ it "Should update underscored default when dashed default is set" do
28
+ defaults_result = @defaults.add_defaults_to_conf({"location_id"=> 3}, nil)
29
+ assert_equal 3, defaults_result[:defaults][:location_id][:value]
30
+ assert_equal nil, defaults_result[:defaults][:'location-id']
31
+ end
32
+ end
17
33
 
18
- it "Should add a default param to defaults file, with provider" do
19
- defaults_result = @defaults.add_defaults_to_conf({"location_id"=>nil}, :foreman)
20
- assert_equal :foreman, defaults_result[:defaults][:location_id][:provider]
34
+ it "Should add a default param to defaults file, with provider" do
35
+ defaults_result = @defaults.add_defaults_to_conf({"location_id"=>nil}, :foreman)
36
+ assert_equal :foreman, defaults_result[:defaults][:location_id][:provider]
37
+ end
21
38
  end
22
39
 
23
- it "Should remove default param from defaults file" do
24
- defaults_result = @defaults.delete_default_from_conf(:organization_id)
25
- assert_nil defaults_result[:defaults][:organization_id]
40
+ describe '#delete_default_from_conf' do
41
+ it "Should remove default param from defaults file" do
42
+ defaults_result = @defaults.delete_default_from_conf(:organization_id)
43
+ assert_nil defaults_result[:defaults][:organization_id]
44
+ end
45
+
46
+ it "Should remove dashed default param from defaults file" do
47
+ defaults_result = @defaults.delete_default_from_conf(:"organization-id")
48
+ assert_nil defaults_result[:defaults][:organization_id]
49
+ end
50
+
51
+ context "dashed" do
52
+ let(:filepath) { File.join(File.dirname(__FILE__), '/fixtures/defaults/defaults_dashed.yml') }
53
+ it "Should remove default param from defaults file" do
54
+ defaults_result = @defaults.delete_default_from_conf(:organization_id)
55
+ assert_nil defaults_result[:defaults][:'organization-id']
56
+ end
57
+
58
+ it "Should remove dashed default param from defaults file" do
59
+ defaults_result = @defaults.delete_default_from_conf(:"organization-id")
60
+ assert_nil defaults_result[:defaults][:'organization-id']
61
+ end
62
+ end
26
63
  end
27
64
 
28
- it "should get the default param, without provider" do
29
- assert_equal 2, @defaults.get_defaults("location_id")
65
+ describe '#defaults_set' do
66
+ it "should check if the defaults is set" do
67
+ assert_equal true, @defaults.defaults_set?("location_id")
68
+ end
30
69
  end
31
70
 
32
- it "should get the default param, with provider" do
33
- fake_provider = mock()
34
- fake_provider.stubs(:provider_name).returns(:foreman)
35
- fake_provider.expects(:get_defaults).with(:organization_id).returns(3)
36
- @defaults.register_provider(fake_provider)
37
- assert_equal 3, @defaults.get_defaults("organization_id")
71
+
72
+ describe '#get_defaults' do
73
+ it "should get the default param, without provider" do
74
+ assert_equal 2, @defaults.get_defaults("location_id")
75
+ end
76
+
77
+ it "should get the default param, with provider" do
78
+ fake_provider = mock()
79
+ fake_provider.stubs(:provider_name).returns(:foreman)
80
+ fake_provider.expects(:get_defaults).with(:organization_id).returns(3)
81
+ @defaults.register_provider(fake_provider)
82
+ assert_equal 3, @defaults.get_defaults("organization_id")
83
+ end
84
+
85
+ context 'dashed params' do
86
+ let(:filepath) { File.join(File.dirname(__FILE__), '/fixtures/defaults/defaults_dashed.yml') }
87
+
88
+ it "should get the default param, without provider" do
89
+ assert_equal 2, @defaults.get_defaults("location_id")
90
+ end
91
+
92
+ it "should get the default param, with provider" do
93
+ fake_provider = mock()
94
+ fake_provider.stubs(:provider_name).returns(:foreman)
95
+ fake_provider.expects(:get_defaults).with(:organization_id).returns(3)
96
+ @defaults.register_provider(fake_provider)
97
+ assert_equal 3, @defaults.get_defaults("organization_id")
98
+ end
99
+ end
38
100
  end
39
101
 
40
102
  it "should return empty defaults when the settings file is not present" do
41
- defaults = HammerCLI::Defaults.new(nil, FILEPATH)
103
+ defaults = HammerCLI::Defaults.new(nil, filepath)
42
104
  assert_equal({}, defaults.defaults_settings)
43
105
  end
44
106
 
@@ -0,0 +1,6 @@
1
+ ---
2
+ :defaults:
3
+ :organization-id:
4
+ :provider: 'foreman'
5
+ :location-id:
6
+ :value: 2
@@ -52,52 +52,64 @@ describe HammerCLI::Options::Normalizers do
52
52
  proc { formatter.format("a") }.must_raise ArgumentError
53
53
  end
54
54
 
55
- it "should parse a comma separated string" do
56
- formatter.format("a=1,b=2,c=3").must_equal({'a' => '1', 'b' => '2', 'c' => '3'})
57
- end
55
+ describe 'key=value format' do
56
+ it "should parse a comma separated string" do
57
+ formatter.format("a=1,b=2,c=3").must_equal({'a' => '1', 'b' => '2', 'c' => '3'})
58
+ end
58
59
 
59
- it "should parse a comma separated string with spaces" do
60
- formatter.format("a= 1 , b = 2 ,c =3").must_equal({'a' => '1', 'b' => '2', 'c' => '3'})
61
- end
60
+ it "should parse a comma separated string with spaces" do
61
+ formatter.format("a= 1 , b = 2 ,c =3").must_equal({'a' => '1', 'b' => '2', 'c' => '3'})
62
+ end
62
63
 
63
- it "should parse a comma separated string with spaces using single quotes" do
64
- formatter.format("a= ' 1 ' , b =' 2',c ='3'").must_equal({'a' => ' 1 ', 'b' => ' 2', 'c' => '3'})
65
- end
64
+ it "should parse a comma separated string with spaces using single quotes" do
65
+ formatter.format("a= ' 1 ' , b =' 2',c ='3'").must_equal({'a' => ' 1 ', 'b' => ' 2', 'c' => '3'})
66
+ end
66
67
 
67
- it "should parse a comma separated string with spaces using double quotes" do
68
- formatter.format("a= \" 1 \" , b =\" 2\",c =\"3\"").must_equal({'a' => ' 1 ', 'b' => ' 2', 'c' => '3'})
69
- end
68
+ it "should parse a comma separated string with spaces using double quotes" do
69
+ formatter.format("a= \" 1 \" , b =\" 2\",c =\"3\"").must_equal({'a' => ' 1 ', 'b' => ' 2', 'c' => '3'})
70
+ end
70
71
 
71
- it "should deal with equal sign in value" do
72
- formatter.format("a=1,b='2=2',c=3").must_equal({'a' => '1', 'b' => '2=2', 'c' => '3'})
73
- end
72
+ it "should deal with equal sign in value" do
73
+ formatter.format("a=1,b='2=2',c=3").must_equal({'a' => '1', 'b' => '2=2', 'c' => '3'})
74
+ end
74
75
 
75
- it "should parse arrays" do
76
- formatter.format("a=1,b=[1,2,3],c=3").must_equal({'a' => '1', 'b' => ['1', '2', '3'], 'c' => '3'})
77
- end
76
+ it "should parse arrays" do
77
+ formatter.format("a=1,b=[1,2,3],c=3").must_equal({'a' => '1', 'b' => ['1', '2', '3'], 'c' => '3'})
78
+ end
78
79
 
79
- it "should parse arrays with spaces" do
80
- formatter.format("a=1,b=[1, 2, 3],c=3").must_equal({'a' => '1', 'b' => ['1', '2', '3'], 'c' => '3'})
81
- end
80
+ it "should parse arrays with spaces" do
81
+ formatter.format("a=1,b=[1, 2, 3],c=3").must_equal({'a' => '1', 'b' => ['1', '2', '3'], 'c' => '3'})
82
+ end
82
83
 
83
- it "should parse arrays with spaces using by single quotes" do
84
- formatter.format("a=1,b=['1 1', ' 2 ', ' 3 3'],c=3").must_equal({'a' => '1', 'b' => ['1 1', ' 2 ', ' 3 3'], 'c' => '3'})
85
- end
84
+ it "should parse arrays with spaces using by single quotes" do
85
+ formatter.format("a=1,b=['1 1', ' 2 ', ' 3 3'],c=3").must_equal({'a' => '1', 'b' => ['1 1', ' 2 ', ' 3 3'], 'c' => '3'})
86
+ end
86
87
 
87
- it "should parse arrays with spaces using by double quotes" do
88
- formatter.format("a=1,b=[\"1 1\", \" 2 \", \" 3 3\"],c=3").must_equal({'a' => '1', 'b' => ['1 1', ' 2 ', ' 3 3'], 'c' => '3'})
89
- end
88
+ it "should parse arrays with spaces using by double quotes" do
89
+ formatter.format("a=1,b=[\"1 1\", \" 2 \", \" 3 3\"],c=3").must_equal({'a' => '1', 'b' => ['1 1', ' 2 ', ' 3 3'], 'c' => '3'})
90
+ end
90
91
 
91
- it "should parse array with one item" do
92
- formatter.format("a=1,b=[abc],c=3").must_equal({'a' => '1', 'b' => ['abc'], 'c' => '3'})
93
- end
92
+ it "should parse array with one item" do
93
+ formatter.format("a=1,b=[abc],c=3").must_equal({'a' => '1', 'b' => ['abc'], 'c' => '3'})
94
+ end
95
+
96
+ it "should parse empty array" do
97
+ formatter.format("a=1,b=[],c=3").must_equal({'a' => '1', 'b' => [], 'c' => '3'})
98
+ end
94
99
 
95
- it "should parse empty array" do
96
- formatter.format("a=1,b=[],c=3").must_equal({'a' => '1', 'b' => [], 'c' => '3'})
100
+ it "should parse a comma separated string 2" do
101
+ proc { formatter.format("a=1,b,c=3") }.must_raise ArgumentError
102
+ end
97
103
  end
98
104
 
99
- it "should parse a comma separated string 2" do
100
- proc { formatter.format("a=1,b,c=3") }.must_raise ArgumentError
105
+ describe 'json format' do
106
+ it 'parses arrays' do
107
+ formatter.format('["a", "b", 1]').must_equal(['a', 'b', 1])
108
+ end
109
+
110
+ it 'parses objects' do
111
+ formatter.format('{"a": ["b", 1]}').must_equal({'a' => ['b', 1]})
112
+ end
101
113
  end
102
114
  end
103
115
 
@@ -20,6 +20,10 @@ describe HammerCLI::Output::Adapter::Abstract do
20
20
  end
21
21
  end
22
22
 
23
+ it "allows default pagination" do
24
+ adapter.paginate_by_default?.must_equal true
25
+ end
26
+
23
27
  it "should filter formatters with incompatible tags" do
24
28
 
25
29
  HammerCLI::Output::Formatters::FormatterLibrary.expects(:new).with({ :type => [] })
@@ -5,6 +5,10 @@ describe HammerCLI::Output::Adapter::Base do
5
5
  let(:context) {{}}
6
6
  let(:adapter) { HammerCLI::Output::Adapter::Base.new(context, HammerCLI::Output::Output.formatters) }
7
7
 
8
+ it "allows default pagination" do
9
+ adapter.paginate_by_default?.must_equal true
10
+ end
11
+
8
12
  context "print_collection" do
9
13
 
10
14
  let(:id) { Fields::Id.new(:path => [:id], :label => "Id") }
@@ -4,6 +4,10 @@ describe HammerCLI::Output::Adapter::CSValues do
4
4
 
5
5
  let(:adapter) { HammerCLI::Output::Adapter::CSValues.new }
6
6
 
7
+ it "forbids default pagination" do
8
+ adapter.paginate_by_default?.must_equal false
9
+ end
10
+
7
11
  context "print_collection" do
8
12
 
9
13
  let(:field_name) { Fields::Field.new(:path => [:name], :label => "Name") }
@@ -5,6 +5,10 @@ describe HammerCLI::Output::Adapter::Json do
5
5
  let(:context) {{}}
6
6
  let(:adapter) { HammerCLI::Output::Adapter::Json.new(context, HammerCLI::Output::Output.formatters) }
7
7
 
8
+ it "forbids default pagination" do
9
+ adapter.paginate_by_default?.must_equal false
10
+ end
11
+
8
12
  context "print_message" do
9
13
  it "prints the message" do
10
14
  params = { :a => 'Test', :b => 83 }
@@ -4,6 +4,10 @@ describe HammerCLI::Output::Adapter::Table do
4
4
 
5
5
  let(:adapter) { HammerCLI::Output::Adapter::Table.new }
6
6
 
7
+ it "allows default pagination" do
8
+ adapter.paginate_by_default?.must_equal true
9
+ end
10
+
7
11
  context "print_collection" do
8
12
 
9
13
  let(:field_name) { Fields::Field.new(:path => [:fullname], :label => "Name") }
@@ -15,14 +19,14 @@ describe HammerCLI::Output::Adapter::Table do
15
19
  [field_name]
16
20
  }
17
21
 
18
- let(:data) { HammerCLI::Output::RecordCollection.new [{
22
+ let(:record) { {
19
23
  :id => 1,
20
24
  :firstname => "John",
21
25
  :lastname => "Doe",
22
26
  :fullname => "John Doe",
23
27
  :long => "SomeVeryLongString"
24
- }]}
25
-
28
+ } }
29
+ let(:data) { HammerCLI::Output::RecordCollection.new [record] }
26
30
  let(:empty_data) { HammerCLI::Output::RecordCollection.new [] }
27
31
 
28
32
  it "should print column name " do
@@ -33,6 +37,18 @@ describe HammerCLI::Output::Adapter::Table do
33
37
  proc { adapter.print_collection(fields, data) }.must_output(/.*John Doe.*/, "")
34
38
  end
35
39
 
40
+ context "pagination" do
41
+ it "should print pagination info if data are not complete" do
42
+ data = HammerCLI::Output::RecordCollection.new([record], { :total => 2, :page => 1, :per_page => 1, :subtotal => 2 })
43
+ proc { adapter.print_collection(fields, data) }.must_output(/.*Page 1 of 2 (use --page and --per-page for navigation)*/, "")
44
+ end
45
+
46
+ it "should print pagination info if data are complete" do
47
+ data = HammerCLI::Output::RecordCollection.new([record], { :total => 1, :page => 1, :per_page => 1, :subtotal => 1 })
48
+ proc { adapter.print_collection(fields, data) }.must_output("--------\nNAME \n--------\nJohn Doe\n--------\n", "")
49
+ end
50
+ end
51
+
36
52
  context "handle ids" do
37
53
  let(:field_id) { Fields::Id.new(:path => [:some_id], :label => "Id") }
38
54
  let(:fields) {
@@ -5,6 +5,10 @@ describe HammerCLI::Output::Adapter::Yaml do
5
5
  let(:context) {{}}
6
6
  let(:adapter) { HammerCLI::Output::Adapter::Yaml.new(context, HammerCLI::Output::Output.formatters) }
7
7
 
8
+ it "forbids default pagination" do
9
+ adapter.paginate_by_default?.must_equal false
10
+ end
11
+
8
12
  context "print_message" do
9
13
  it "prints the message" do
10
14
  params = { :a => 'Test', :b => 83 }
@@ -30,5 +30,31 @@ describe HammerCLI::Output::RecordCollection do
30
30
  set.meta.must_equal metadata
31
31
  set.meta.total.must_equal 6
32
32
  end
33
+ end
34
+
35
+ describe HammerCLI::Output::MetaData do
36
+
37
+ let(:meta) { HammerCLI::Output::MetaData.new(:total => "6", :page => "2", :per_page => "3", :subtotal => "5") }
38
+
39
+ it "converts numeric metadata to numbers" do
40
+ meta.total.must_equal 6
41
+ meta.page.must_equal 2
42
+ meta.per_page.must_equal 3
43
+ meta.subtotal.must_equal 5
44
+ end
45
+
46
+ describe "pagination_set?" do
47
+ let(:pagination_data) { { :total => 6, :page => 2, :per_page => 3, :subtotal => 5 } }
33
48
 
49
+ it "can tell if pagination data are set" do
50
+ meta.pagination_set?.must_equal true
51
+ end
52
+
53
+ it "can tell if pagination data are not set" do
54
+ pagination_data.keys.each do |key|
55
+ meta = HammerCLI::Output::MetaData.new(pagination_data.clone.reject { |k| k == key })
56
+ meta.pagination_set?.must_equal false
57
+ end
58
+ end
59
+ end
34
60
  end
@@ -49,7 +49,7 @@ describe HammerCLI::Settings do
49
49
  settings.dump.must_equal data
50
50
  end
51
51
 
52
- it "merges settings on second load" do
52
+ it "merges hash settings on second load" do
53
53
  settings.load({:a => 1, :b => 2, :d => {:e => 4, :f => 5}})
54
54
  settings.load({:b => 'B', :c => 'C', :d => {:e => 'E'}})
55
55
  settings.get(:a).must_equal 1
@@ -59,6 +59,16 @@ describe HammerCLI::Settings do
59
59
  settings.get(:d, :f).must_equal 5
60
60
  end
61
61
 
62
+ it "merges array settings on second load" do
63
+ settings.load({:x => [:a, :b]})
64
+ settings.load({:x => [:c, :d]})
65
+ settings.get(:x)[0].must_equal :a
66
+ settings.get(:x)[1].must_equal :b
67
+ settings.get(:x)[2].must_equal :c
68
+ settings.get(:x)[3].must_equal :d
69
+ settings.get(:x).size.must_equal 4
70
+ end
71
+
62
72
  it "clear wipes all settings" do
63
73
  settings.load({:a => 1, :b => 2})
64
74
  settings.clear
@@ -14,8 +14,8 @@ describe "constraints" do
14
14
  @option_a = 1
15
15
  @option_b = 1
16
16
  @option_c = 1
17
- @option_d = nil
18
- @option_e = nil
17
+ @option_unset_d = nil
18
+ @option_unset_e = nil
19
19
  end
20
20
  end
21
21
 
@@ -23,7 +23,7 @@ describe "constraints" do
23
23
  FakeCmd.new
24
24
  }
25
25
 
26
- let(:option_names) { ["a", "b", "c", "d", "e"] }
26
+ let(:option_names) { ["a", "b", "c", "unset-d", "unset-e"] }
27
27
  let(:options_def) {
28
28
  option_names.collect{ |n| Clamp::Option::Definition.new(["-"+n, "--option-"+n], n.upcase, "Option "+n.upcase) }
29
29
  }
@@ -107,13 +107,66 @@ describe "constraints" do
107
107
  end
108
108
 
109
109
  it "should return false when one of the options is missing" do
110
- constraint = cls.new(options, [:option_a, :option_b, :option_c, :option_d])
110
+ constraint = cls.new(options, [:option_a, :option_b, :option_c, :option_unset_d])
111
111
  constraint.exist?.must_equal false
112
112
  end
113
113
  end
114
114
 
115
115
  end
116
116
 
117
+ describe HammerCLI::Validator::OneOptionConstraint do
118
+ let(:cls) { HammerCLI::Validator::OneOptionConstraint }
119
+
120
+ describe "exist?" do
121
+ it "should return true when the option exist" do
122
+ constraint = cls.new(options, :option_a)
123
+ constraint.exist?.must_equal true
124
+ end
125
+
126
+ it "should return false when the option is missing" do
127
+ constraint = cls.new(options, :option_unset_d)
128
+ constraint.exist?.must_equal false
129
+ end
130
+ end
131
+
132
+ describe "#rejected" do
133
+ it "returns nil when the option is missing" do
134
+ constraint = cls.new(options, :option_unset_d)
135
+ constraint.rejected.must_equal nil
136
+ end
137
+
138
+ it "raises exception when the option is present" do
139
+ constraint = cls.new(options, :option_a)
140
+ e = proc{ constraint.rejected }.must_raise HammerCLI::Validator::ValidationError
141
+ e.message.must_equal "You can't set option --option-a"
142
+ end
143
+ end
144
+
145
+ describe "#required" do
146
+ it "returns nil when the option exist" do
147
+ constraint = cls.new(options, :option_a)
148
+ constraint.required.must_equal nil
149
+ end
150
+
151
+ it "raises exception when the option is present" do
152
+ constraint = cls.new(options, :option_unset_d)
153
+ e = proc{ constraint.required }.must_raise HammerCLI::Validator::ValidationError
154
+ e.message.must_equal 'Option --option-unset-d is required'
155
+ end
156
+ end
157
+
158
+ describe "#value" do
159
+ it "returns value of the option" do
160
+ constraint = cls.new(options, :option_a)
161
+ constraint.value.must_equal 1
162
+ end
163
+ it "returns nil when the option is missing" do
164
+ constraint = cls.new(options, :option_unset_d)
165
+ constraint.value.must_equal nil
166
+ end
167
+ end
168
+ end
169
+
117
170
  describe HammerCLI::Validator::AnyConstraint do
118
171
 
119
172
  let(:cls) { HammerCLI::Validator::AnyConstraint }
@@ -126,17 +179,69 @@ describe "constraints" do
126
179
  end
127
180
 
128
181
  it "should return true when one of the options exist" do
129
- constraint = cls.new(options, [:option_a, :option_d, :option_e])
182
+ constraint = cls.new(options, [:option_a, :option_unset_d, :option_unset_e])
130
183
  constraint.exist?.must_equal true
131
184
  end
132
185
 
133
186
  it "should return false when all the options are missing" do
134
- constraint = cls.new(options, [:option_d, :option_e])
187
+ constraint = cls.new(options, [:option_unset_d, :option_unset_e])
135
188
  constraint.exist?.must_equal false
136
189
  end
137
190
  end
138
191
 
139
192
  end
140
193
 
194
+ describe HammerCLI::Validator::OneOfConstraint do
141
195
 
196
+ let(:cls) { HammerCLI::Validator::OneOfConstraint }
197
+
198
+ it "raises exception when nothing to check is set" do
199
+ e = proc{ cls.new(options, []) }.must_raise RuntimeError
200
+ e.message.must_equal 'Set at least one expected option'
201
+ end
202
+
203
+ describe "#exist?" do
204
+ it "should return true when one of the options exist" do
205
+ constraint = cls.new(options, [:option_a, :option_unset_d, :option_unset_e])
206
+ constraint.exist?.must_equal true
207
+ end
208
+
209
+ it "should return false when the option isn't present" do
210
+ constraint = cls.new(options, [:option_unset_d, :option_unset_e])
211
+ constraint.exist?.must_equal false
212
+ end
213
+
214
+ it "should return false when more than one of the options is present" do
215
+ constraint = cls.new(options, [:option_a, :option_b])
216
+ constraint.exist?.must_equal false
217
+ end
218
+ end
219
+
220
+ describe "#rejected" do
221
+ it "raises not implemented exception" do
222
+ constraint = cls.new(options, [:option_a, :option_unset_d])
223
+ e = proc{ constraint.rejected }.must_raise NotImplementedError
224
+ e.message.must_equal '#rejected is unsupported for OneOfConstraint'
225
+ end
226
+ end
227
+
228
+ describe "#required" do
229
+ it "returns nil when one of the options exist" do
230
+ constraint = cls.new(options, [:option_a, :option_unset_d, :option_unset_e])
231
+ constraint.required.must_equal nil
232
+ end
233
+
234
+ it "raises exception when none of the options is present" do
235
+ constraint = cls.new(options, [:option_unset_d, :option_unset_e])
236
+ e = proc{ constraint.required }.must_raise HammerCLI::Validator::ValidationError
237
+ e.message.must_equal 'One of options --option-unset-d, --option-unset-e is required'
238
+ end
239
+
240
+ it "raises exception when more than one of the options is present" do
241
+ constraint = cls.new(options, [:option_a, :option_b])
242
+ e = proc{ constraint.required }.must_raise HammerCLI::Validator::ValidationError
243
+ e.message.must_equal 'Only one of options --option-a, --option-b can be set'
244
+ end
245
+ end
246
+ end
142
247
  end