hammer_cli_foreman 2.4.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +40 -0
  3. data/lib/hammer_cli_foreman/architecture.rb +5 -5
  4. data/lib/hammer_cli_foreman/associating_commands.rb +0 -24
  5. data/lib/hammer_cli_foreman/bookmark.rb +5 -5
  6. data/lib/hammer_cli_foreman/combination.rb +3 -13
  7. data/lib/hammer_cli_foreman/command_extensions/ping.rb +21 -2
  8. data/lib/hammer_cli_foreman/command_extensions/subnet.rb +25 -10
  9. data/lib/hammer_cli_foreman/command_extensions/update_common.rb +14 -0
  10. data/lib/hammer_cli_foreman/command_extensions/user.rb +9 -5
  11. data/lib/hammer_cli_foreman/command_extensions.rb +1 -2
  12. data/lib/hammer_cli_foreman/commands.rb +17 -11
  13. data/lib/hammer_cli_foreman/compute_attribute.rb +1 -1
  14. data/lib/hammer_cli_foreman/compute_profile.rb +5 -5
  15. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +2 -1
  16. data/lib/hammer_cli_foreman/compute_resource.rb +23 -0
  17. data/lib/hammer_cli_foreman/config_report.rb +2 -0
  18. data/lib/hammer_cli_foreman/filter.rb +2 -2
  19. data/lib/hammer_cli_foreman/host.rb +1 -47
  20. data/lib/hammer_cli_foreman/hostgroup.rb +14 -58
  21. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +10 -31
  22. data/lib/hammer_cli_foreman/id_resolver.rb +7 -68
  23. data/lib/hammer_cli_foreman/location.rb +0 -6
  24. data/lib/hammer_cli_foreman/mail_notification.rb +2 -2
  25. data/lib/hammer_cli_foreman/model.rb +5 -5
  26. data/lib/hammer_cli_foreman/operating_system.rb +10 -10
  27. data/lib/hammer_cli_foreman/option_builders.rb +84 -52
  28. data/lib/hammer_cli_foreman/option_sources/id_params.rb +41 -11
  29. data/lib/hammer_cli_foreman/option_sources/ids_params.rb +39 -7
  30. data/lib/hammer_cli_foreman/option_sources.rb +0 -1
  31. data/lib/hammer_cli_foreman/organization.rb +0 -6
  32. data/lib/hammer_cli_foreman/ping.rb +6 -1
  33. data/lib/hammer_cli_foreman/references.rb +0 -16
  34. data/lib/hammer_cli_foreman/registration.rb +18 -0
  35. data/lib/hammer_cli_foreman/settings.rb +3 -3
  36. data/lib/hammer_cli_foreman/smart_proxy.rb +7 -57
  37. data/lib/hammer_cli_foreman/template.rb +3 -15
  38. data/lib/hammer_cli_foreman/user.rb +4 -4
  39. data/lib/hammer_cli_foreman/usergroup.rb +5 -5
  40. data/lib/hammer_cli_foreman/version.rb +1 -1
  41. data/lib/hammer_cli_foreman.rb +3 -21
  42. data/lib/minitest/coverage_reporter.rb +1 -1
  43. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  44. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  45. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  46. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  47. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  48. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  49. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  50. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  51. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  52. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  53. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  54. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  55. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  56. data/test/data/2.4/foreman_api.json +1 -0
  57. data/test/data/2.5/foreman_api.json +1 -0
  58. data/test/data/3.1/foreman_api.json +1 -0
  59. data/test/functional/architecture_test.rb +37 -5
  60. data/test/functional/bookmark_test.rb +5 -2
  61. data/test/functional/compute_attribute_test.rb +20 -20
  62. data/test/functional/compute_profile_test.rb +14 -1
  63. data/test/functional/compute_resource_test.rb +37 -0
  64. data/test/functional/filter_test.rb +2 -1
  65. data/test/functional/host_test.rb +65 -11
  66. data/test/functional/hostgroup/create_test.rb +11 -117
  67. data/test/functional/hostgroup/update_test.rb +11 -79
  68. data/test/functional/http_proxy_test.rb +12 -0
  69. data/test/functional/location_test.rb +13 -3
  70. data/test/functional/mail_notification_test.rb +3 -1
  71. data/test/functional/media_test.rb +11 -0
  72. data/test/functional/model_test.rb +3 -1
  73. data/test/functional/operating_system_test.rb +3 -1
  74. data/test/functional/personal_access_token_test.rb +4 -4
  75. data/test/functional/ping_test.rb +33 -0
  76. data/test/functional/realm_test.rb +11 -0
  77. data/test/functional/registration_test.rb +8 -0
  78. data/test/functional/report_template_test.rb +11 -0
  79. data/test/functional/settings_test.rb +4 -4
  80. data/test/functional/template_test.rb +87 -48
  81. data/test/functional/user_mail_notification_test.rb +3 -3
  82. data/test/functional/user_test.rb +11 -0
  83. data/test/functional/usergroup_test.rb +3 -1
  84. data/test/test_helper.rb +1 -1
  85. data/test/unit/apipie_resource_mock.rb +1 -39
  86. data/test/unit/architecture_test.rb +10 -10
  87. data/test/unit/bookmark_test.rb +10 -14
  88. data/test/unit/commands_test.rb +1 -2
  89. data/test/unit/compute_profile_test.rb +10 -10
  90. data/test/unit/config_report_test.rb +1 -0
  91. data/test/unit/helpers/command.rb +0 -8
  92. data/test/unit/host_test.rb +14 -61
  93. data/test/unit/hostgroup_test.rb +7 -26
  94. data/test/unit/id_resolver_test.rb +0 -28
  95. data/test/unit/mail_notification_test.rb +4 -4
  96. data/test/unit/model_test.rb +47 -47
  97. data/test/unit/operating_system_test.rb +10 -16
  98. data/test/unit/option_builders_test.rb +88 -83
  99. data/test/unit/settings_test.rb +4 -4
  100. data/test/unit/smart_proxy_test.rb +0 -12
  101. data/test/unit/usergroup_test.rb +10 -10
  102. metadata +115 -128
  103. data/lib/hammer_cli_foreman/command_extensions/puppet_environment.rb +0 -29
  104. data/lib/hammer_cli_foreman/command_extensions/puppet_environments.rb +0 -29
  105. data/lib/hammer_cli_foreman/config_group.rb +0 -45
  106. data/lib/hammer_cli_foreman/option_sources/puppet_environment_params.rb +0 -59
  107. data/lib/hammer_cli_foreman/puppet_class.rb +0 -61
  108. data/lib/hammer_cli_foreman/puppet_environment.rb +0 -65
  109. data/lib/hammer_cli_foreman/smart_class_parameter.rb +0 -189
  110. data/test/functional/config_group_test.rb +0 -50
  111. data/test/functional/proxy_test.rb +0 -86
  112. data/test/functional/smart_class_parameter_test.rb +0 -97
  113. data/test/reports/TEST-Minitest-Result.xml +0 -4344
  114. data/test/unit/config_group_test.rb +0 -82
  115. data/test/unit/puppet_class_test.rb +0 -72
  116. data/test/unit/puppet_environment_test.rb +0 -114
  117. data/test/unit/smart_class_parameter_test.rb +0 -113
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require File.join(File.dirname(__FILE__), 'test_helper')
2
3
  require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
4
 
@@ -7,68 +8,67 @@ describe HammerCLIForeman::Model do
7
8
 
8
9
  include CommandTestHelper
9
10
 
10
- context "ListCommand" do
11
+ context 'ListCommand' do
11
12
  before do
12
13
  ResourceMocks.mock_action_call(:models, :index, [])
13
14
  end
14
15
 
15
- let(:cmd) { HammerCLIForeman::Model::ListCommand.new("", ctx) }
16
+ let(:cmd) { HammerCLIForeman::Model::ListCommand.new('', ctx) }
16
17
 
17
- context "parameters" do
18
- it_should_accept "no arguments"
18
+ context 'parameters' do
19
+ it_should_accept 'no arguments'
19
20
  it_should_accept_search_params
20
- it_should_fail_with 'organization param', ['--organization-id=1']
21
- it_should_fail_with 'location param', ['--location-id=1']
21
+ it_should_accept 'organization', ['--organization-id=1']
22
+ it_should_accept 'location', ['--location-id=1']
22
23
  end
23
24
 
24
- context "output" do
25
+ context 'output' do
25
26
  let(:expected_record_count) { count_records(cmd.resource.call(:index)) }
26
27
 
27
28
  it_should_print_n_records
28
- it_should_print_column "Name"
29
- it_should_print_column "Id"
30
- it_should_print_column "Vendor class"
31
- it_should_print_column "HW model"
29
+ it_should_print_column 'Name'
30
+ it_should_print_column 'Id'
31
+ it_should_print_column 'Vendor class'
32
+ it_should_print_column 'HW model'
32
33
  end
33
34
  end
34
35
 
35
36
 
36
- context "InfoCommand" do
37
+ context 'InfoCommand' do
37
38
 
38
- let(:cmd) { HammerCLIForeman::Model::InfoCommand.new("", ctx) }
39
+ let(:cmd) { HammerCLIForeman::Model::InfoCommand.new('', ctx) }
39
40
 
40
- context "parameters" do
41
- it_should_accept "id", ["--id=1"]
42
- it_should_accept "name", ["--name=model"]
43
- it_should_fail_with 'organization param', ['--organization-id=1']
44
- it_should_fail_with 'location param', ['--location-id=1']
41
+ context 'parameters' do
42
+ it_should_accept 'id', ['--id=1']
43
+ it_should_accept 'name', ['--name=model']
44
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
45
+ it_should_accept 'location', %w[--id=1 --location-id=1]
45
46
  # it_should_fail_with "no arguments" # TODO: temporarily disabled, parameters are checked in the id resolver
46
47
  end
47
48
 
48
- context "output" do
49
- with_params ["--id=1"] do
49
+ context 'output' do
50
+ with_params ['--id=1'] do
50
51
  it_should_print_n_records 1
51
- it_should_print_column "Name"
52
- it_should_print_column "Id"
53
- it_should_print_column "Vendor class"
54
- it_should_print_column "HW model"
55
- it_should_print_column "Info"
56
- it_should_print_column "Created at"
57
- it_should_print_column "Updated at"
52
+ it_should_print_column 'Name'
53
+ it_should_print_column 'Id'
54
+ it_should_print_column 'Vendor class'
55
+ it_should_print_column 'HW model'
56
+ it_should_print_column 'Info'
57
+ it_should_print_column 'Created at'
58
+ it_should_print_column 'Updated at'
58
59
  end
59
60
  end
60
61
 
61
62
  end
62
63
 
63
64
 
64
- context "CreateCommand" do
65
+ context 'CreateCommand' do
65
66
 
66
- let(:cmd) { HammerCLIForeman::Model::CreateCommand.new("", ctx) }
67
+ let(:cmd) { HammerCLIForeman::Model::CreateCommand.new('', ctx) }
67
68
 
68
- context "parameters" do
69
- it_should_accept "name", ["--name=model", "--info=description", "--vendor-class=class", "--hardware-model=model"]
70
- it_should_fail_with 'organization param', ['--organization-id=1']
71
- it_should_fail_with 'location param', ['--location-id=1']
69
+ context 'parameters' do
70
+ it_should_accept 'name, info, vendor-class, hardware-model, organization, location',
71
+ %w[--name=model --info=description --vendor-class=class --hardware-model=model --organization-id=1 --location-id=1]
72
72
  # it_should_fail_with "name missing", ["--info=description", "--vendor-class=class", "--hardware-model=model"]
73
73
  # TODO: temporarily disabled, parameters are checked in the api
74
74
  end
@@ -76,30 +76,30 @@ describe HammerCLIForeman::Model do
76
76
  end
77
77
 
78
78
 
79
- context "DeleteCommand" do
79
+ context 'DeleteCommand' do
80
80
 
81
- let(:cmd) { HammerCLIForeman::Model::DeleteCommand.new("", ctx) }
81
+ let(:cmd) { HammerCLIForeman::Model::DeleteCommand.new('', ctx) }
82
82
 
83
- context "parameters" do
84
- it_should_accept "name", ["--name=model"]
85
- it_should_accept "id", ["--id=1"]
86
- it_should_fail_with 'organization param', ['--organization-id=1']
87
- it_should_fail_with 'location param', ['--location-id=1']
83
+ context 'parameters' do
84
+ it_should_accept 'name', ['--name=model']
85
+ it_should_accept 'id', ['--id=1']
86
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
87
+ it_should_accept 'location', %w[--id=1 --location-id=1]
88
88
  # it_should_fail_with "name or id missing", [] # TODO: temporarily disabled, parameters are checked in the id resolver
89
89
  end
90
90
 
91
91
  end
92
92
 
93
93
 
94
- context "UpdateCommand" do
94
+ context 'UpdateCommand' do
95
95
 
96
- let(:cmd) { HammerCLIForeman::Model::UpdateCommand.new("", ctx) }
96
+ let(:cmd) { HammerCLIForeman::Model::UpdateCommand.new('', ctx) }
97
97
 
98
- context "parameters" do
99
- it_should_accept "name", ["--name=model", "--new-name=model2", "--info=description", "--vendor-class=class", "--hardware-model=model"]
100
- it_should_accept "id", ["--id=1", "--new-name=model2", "--info=description", "--vendor-class=class", "--hardware-model=model"]
101
- it_should_fail_with 'organization param', ['--organization-id=1']
102
- it_should_fail_with 'location param', ['--location-id=1']
98
+ context 'parameters' do
99
+ it_should_accept 'name', ['--name=model', '--new-name=model2', '--info=description', '--vendor-class=class', '--hardware-model=model']
100
+ it_should_accept 'id', ['--id=1', '--new-name=model2', '--info=description', '--vendor-class=class', '--hardware-model=model']
101
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
102
+ it_should_accept 'location', %w[--id=1 --location-id=1]
103
103
  # it_should_fail_with "no params", []
104
104
  # it_should_fail_with "name or id missing", ["--new-name=model2", "--info=description", "--vendor-class=class", "--hardware-model=model"]
105
105
  # TODO: temporarily disabled, parameters are checked in the id resolver
@@ -18,8 +18,8 @@ describe HammerCLIForeman::OperatingSystem do
18
18
  context "parameters" do
19
19
  it_should_accept "no arguments"
20
20
  it_should_accept_search_params
21
- it_should_fail_with 'organization param', ['--organization-id=1']
22
- it_should_fail_with 'location param', ['--location-id=1']
21
+ it_should_accept 'organization', ['--organization-id=1']
22
+ it_should_accept 'location', ['--location-id=1']
23
23
  end
24
24
 
25
25
  context "output" do
@@ -42,8 +42,8 @@ describe HammerCLIForeman::OperatingSystem do
42
42
  context "parameters" do
43
43
  it_should_accept "id", ["--id=1"]
44
44
  it_should_accept "title", ["--title=Rhel 6.5"]
45
- it_should_fail_with 'organization param', ['--organization-id=1']
46
- it_should_fail_with 'location param', ['--location-id=1']
45
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
46
+ it_should_accept 'location', %w[--id=1 --location-id=1]
47
47
  # it_should_fail_with "no arguments" # TODO: temporarily disabled, parameters are checked in the id resolver
48
48
  end
49
49
 
@@ -73,9 +73,8 @@ describe HammerCLIForeman::OperatingSystem do
73
73
  let(:cmd) { HammerCLIForeman::OperatingSystem::CreateCommand.new("", ctx) }
74
74
 
75
75
  context "parameters" do
76
- it_should_accept "name, major, minor, family, release name", ["--name=media", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
77
- it_should_fail_with 'organization param', ['--organization-id=1']
78
- it_should_fail_with 'location param', ['--location-id=1']
76
+ it_should_accept "name, major, minor, family, release name, organization, location",
77
+ ["--name=media", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome", "--organization-id=1", "--location-id=1"]
79
78
  # it_should_fail_with "name missing", ["--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
80
79
  # TODO: temporarily disabled, parameters are checked in the api
81
80
  end
@@ -93,8 +92,8 @@ describe HammerCLIForeman::OperatingSystem do
93
92
  context "parameters" do
94
93
  it_should_accept "id", ["--id=1"]
95
94
  it_should_accept "title", ["--title=Rhel 6.5"]
96
- it_should_fail_with 'organization param', ['--organization-id=1']
97
- it_should_fail_with 'location param', ['--location-id=1']
95
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
96
+ it_should_accept 'location', %w[--id=1 --location-id=1]
98
97
  # it_should_fail_with "name or id missing", [] # TODO: temporarily disabled, parameters are checked in the id resolver
99
98
  # TODO: temporarily disabled, parameters are checked in the id resolver
100
99
  end
@@ -109,9 +108,8 @@ describe HammerCLIForeman::OperatingSystem do
109
108
  context "parameters" do
110
109
  it_should_accept "id", ["--id=1"]
111
110
  it_should_accept "title", ["--title=Rhel 6.5"]
112
- it_should_accept "name, major, minor, family, release name", ["--id=83", "--name=os", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
113
- it_should_fail_with 'organization param', ['--organization-id=1']
114
- it_should_fail_with 'location param', ['--location-id=1']
111
+ it_should_accept "name, major, minor, family, release name, organization, location",
112
+ ["--id=83", "--name=os", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome", "--organization-id=1", "--location-id=1"]
115
113
  # it_should_fail_with "no params", []
116
114
  # it_should_fail_with "label or id missing", ["--name=os", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
117
115
  # TODO: temporarily disabled, parameters are checked in the id resolver
@@ -136,8 +134,6 @@ describe HammerCLIForeman::OperatingSystem do
136
134
  it_should_accept "name, value and os id", ["--name=domain", "--value=val", "--operatingsystem-id=1"]
137
135
  it_should_accept "name, value and os title", ["--name=domain", "--value=val", "--operatingsystem=Rhel 6.5"]
138
136
  it_should_accept "name, value, type and os id", ["--name=domain", "--value=val", "--parameter-type=string", "--operatingsystem-id=1"]
139
- it_should_fail_with 'organization param', ['--organization-id=1']
140
- it_should_fail_with 'location param', ['--location-id=1']
141
137
  # it_should_fail_with "name missing", ["--value=val", "--operatingsystem-id=id"]
142
138
  # it_should_fail_with "value missing", ["--name=name", "--operatingsystem-id=id"]
143
139
  # it_should_fail_with "os id missing", ["--name=name", "--value=val"]
@@ -154,8 +150,6 @@ describe HammerCLIForeman::OperatingSystem do
154
150
  context "parameters" do
155
151
  it_should_accept "name and os id", ["--name=domain", "--operatingsystem-id=1"]
156
152
  it_should_accept "name and os title", ["--name=domain", "--operatingsystem=Rhel 6.5"]
157
- it_should_fail_with 'organization param', ['--organization-id=1']
158
- it_should_fail_with 'location param', ['--location-id=1']
159
153
  # it_should_fail_with "name missing", ["--operatingsystem-id=id"]
160
154
  # it_should_fail_with "os id missing", ["--name=name"]
161
155
  # TODO: temporarily disabled, parameters are checked in the id resolver
@@ -209,7 +209,9 @@ describe HammerCLIForeman::ForemanOptionBuilder do
209
209
  end
210
210
 
211
211
  context "dependent searchables options expansion" do
212
- let(:option_switches) { container.build(@build_options).map(&:switches) }
212
+ let(:option_switches) do
213
+ container.build(@build_options.merge(command: Class.new(HammerCLIForeman::Command))).map(&:switches)
214
+ end
213
215
 
214
216
  before :each do
215
217
  container.builders = [
@@ -218,51 +220,51 @@ describe HammerCLIForeman::ForemanOptionBuilder do
218
220
  ]
219
221
  end
220
222
 
221
- it "does not filter searchable builders by default" do
222
- @build_options = {:expand => {}}
223
+ it 'does not filter searchable builders by default' do
224
+ @build_options = { expand: {} }
223
225
  _(option_switches).must_equal [
224
- ["--user"],
225
- ["--user-label"],
226
- ["--user-id"],
227
- ["--post"],
228
- ["--post-label"],
229
- ["--post-id"]
226
+ ['--user-id'],
227
+ ['--user'],
228
+ ['--user-label'],
229
+ ['--post-id'],
230
+ ['--post'],
231
+ ['--post-label']
230
232
  ]
231
233
  end
232
234
 
233
- it "adds dependent searchable builders on explicit requirement" do
234
- @build_options = {:expand => {:including => [:posts, :comments]}}
235
+ it 'adds dependent searchable builders on explicit requirement' do
236
+ @build_options = { expand: { including: %i[posts comments] } }
235
237
  _(option_switches).must_equal [
236
- ["--user"],
237
- ["--user-label"],
238
- ["--user-id"],
239
- ["--post"],
240
- ["--post-label"],
241
- ["--post-id"],
242
- ["--comment"],
243
- ["--comment-label"],
244
- ["--comment-id"]
238
+ ['--user-id'],
239
+ ['--user'],
240
+ ['--user-label'],
241
+ ['--post-id'],
242
+ ['--post'],
243
+ ['--post-label'],
244
+ ['--comment-id'],
245
+ ['--comment'],
246
+ ['--comment-label']
245
247
  ]
246
248
  end
247
249
 
248
- it "filters dependent searchable builders on explicit requirement" do
249
- @build_options = {:expand => {:except => [:users]}}
250
+ it 'filters dependent searchable builders on explicit requirement' do
251
+ @build_options = { expand: { except: [:users] } }
250
252
  _(option_switches).must_equal [
251
- ["--post"],
252
- ["--post-label"],
253
- ["--post-id"]
253
+ ['--post-id'],
254
+ ['--post'],
255
+ ['--post-label']
254
256
  ]
255
257
  end
256
258
 
257
- it "specifies custom set of dependent searchable builders on explicit requirement" do
258
- @build_options = {:expand => {:only => [:comments, :users]}}
259
+ it 'specifies custom set of dependent searchable builders on explicit requirement' do
260
+ @build_options = { expand: { only: %i[comments users] } }
259
261
  _(option_switches).must_equal [
260
- ["--user"],
261
- ["--user-label"],
262
- ["--user-id"],
263
- ["--comment"],
264
- ["--comment-label"],
265
- ["--comment-id"]
262
+ ['--user-id'],
263
+ ['--user'],
264
+ ['--user-label'],
265
+ ['--comment-id'],
266
+ ['--comment'],
267
+ ['--comment-label']
266
268
  ]
267
269
  end
268
270
  end
@@ -327,7 +329,7 @@ describe HammerCLIForeman::DependentSearchablesOptionBuilder do
327
329
  let(:resource) { api.resource(:users) }
328
330
  let(:searchables) { FakeSearchables.new(["name", "label", "uuid"]) }
329
331
  let(:builder) { HammerCLIForeman::DependentSearchablesOptionBuilder.new(resource, searchables) }
330
- let(:builder_params) { {} }
332
+ let(:builder_params) { { command: Class.new(HammerCLIForeman::Command) } }
331
333
  let(:options) { builder.build(builder_params) }
332
334
 
333
335
  describe "empty searchables" do
@@ -339,41 +341,40 @@ describe HammerCLIForeman::DependentSearchablesOptionBuilder do
339
341
  end
340
342
  end
341
343
 
342
- describe "multiple searchables" do
343
-
344
- it "creates correct switches" do
344
+ describe 'multiple searchables' do
345
+ it 'creates correct switches' do
345
346
  _(options.map(&:switches)).must_equal [
346
- ["--user"], # first option does not have the suffix
347
- ["--user-label"], # other options with suffixes
348
- ["--user-uuid"],
349
- ["--user-id"] # additional id
347
+ ['--user-id'], # main option from API docs
348
+ ['--user'], # additional option
349
+ ['--user-label'], # other options with suffixes
350
+ ['--user-uuid']
350
351
  ]
351
352
  end
352
353
 
353
- it "creates correct option types" do
354
- _(options.map(&:type)).must_equal [
355
- "USER_NAME",
356
- "USER_LABEL",
357
- "USER_UUID",
358
- "USER_ID",
354
+ it 'creates correct option types' do
355
+ _(options.map(&:type)).must_equal %w[
356
+ USER_ID
357
+ USER_NAME
358
+ USER_LABEL
359
+ USER_UUID
359
360
  ]
360
361
  end
361
362
 
362
- it "creates correct descriptions" do
363
+ it 'creates correct descriptions' do
363
364
  _(options.map(&:description)).must_equal [
364
- "Search by name",
365
- "Search by label",
366
- "Search by uuid",
367
- "DESC"
365
+ 'DESC',
366
+ 'Search by name',
367
+ 'Search by label',
368
+ 'Search by uuid'
368
369
  ]
369
370
  end
370
371
 
371
- it "creates correct attribute readers" do
372
- _(options.map(&:read_method)).must_equal [
373
- "option_user_name",
374
- "option_user_label",
375
- "option_user_uuid",
376
- "option_user_id",
372
+ it 'creates correct attribute readers' do
373
+ _(options.map(&:read_method)).must_equal %w[
374
+ option_user_id
375
+ option_user_name
376
+ option_user_label
377
+ option_user_uuid
377
378
  ]
378
379
  end
379
380
 
@@ -385,44 +386,48 @@ describe HammerCLIForeman::DependentSearchablesOptionBuilder do
385
386
 
386
387
  describe "aliasing resource names" do
387
388
 
388
- let(:builder_params) { {:resource_mapping => {:user => :usr}} }
389
+ let(:builder_params) do
390
+ {
391
+ resource_mapping: { user: :usr },
392
+ command: Class.new(HammerCLIForeman::Command)
393
+ }
394
+ end
389
395
 
390
- it "renames options" do
396
+ it 'renames options' do
391
397
  _(options.map(&:switches)).must_equal [
392
- ["--usr"], # first option does not have the suffix
393
- ["--usr-label"], # other options with suffixes
394
- ["--usr-uuid"],
395
- ["--usr-id"] # additional id
398
+ ['--usr-id'], # parent option id
399
+ ['--usr'], # additional option
400
+ ['--usr-label'], # other options with suffixes
401
+ ['--usr-uuid']
396
402
  ]
397
403
  end
398
404
 
399
- it "renames option types" do
400
- _(options.map(&:type)).must_equal [
401
- "USR_NAME",
402
- "USR_LABEL",
403
- "USR_UUID",
404
- "USR_ID",
405
+ it 'renames option types' do
406
+ _(options.map(&:type)).must_equal %w[
407
+ USR_ID
408
+ USR_NAME
409
+ USR_LABEL
410
+ USR_UUID
405
411
  ]
406
412
  end
407
413
 
408
- it "keeps option accessor the same" do
409
- _(options.map(&:attribute_name)).must_equal [
410
- "option_user_name",
411
- "option_user_label",
412
- "option_user_uuid",
413
- "option_user_id"
414
+ it 'keeps option accessor the same' do
415
+ _(options.map(&:attribute_name)).must_equal %w[
416
+ option_user_id
417
+ option_user_name
418
+ option_user_label
419
+ option_user_uuid
414
420
  ]
415
421
  end
416
422
  end
417
423
 
418
- describe "resources with id parameter in show action" do
419
-
420
- it "uses descriptions from the action" do
424
+ describe 'resources with id parameter in show action' do
425
+ it 'uses descriptions from the action' do
421
426
  _(options.map(&:description)).must_equal [
422
- "Search by name",
423
- "Search by label",
424
- "Search by uuid",
425
- "DESC"
427
+ 'DESC',
428
+ 'Search by name',
429
+ 'Search by label',
430
+ 'Search by uuid'
426
431
  ]
427
432
  end
428
433
  end
@@ -18,8 +18,8 @@ describe HammerCLIForeman::Settings do
18
18
  context "parameters" do
19
19
  it_should_accept "no arguments"
20
20
  it_should_accept_search_params
21
- it_should_fail_with 'organization param', ['--organization-id=1']
22
- it_should_fail_with 'location param', ['--location-id=1']
21
+ it_should_accept 'organization', ['--organization-id=1']
22
+ it_should_accept 'location', ['--location-id=1']
23
23
  end
24
24
 
25
25
  context "output" do
@@ -40,8 +40,8 @@ describe HammerCLIForeman::Settings do
40
40
  context "parameters" do
41
41
  it_should_accept "name", ["--name=setting1", "--value=setting2"]
42
42
  it_should_accept "id", ["--id=1", "--value=setting2"]
43
- it_should_fail_with 'organization param', ['--organization-id=1']
44
- it_should_fail_with 'location param', ['--location-id=1']
43
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
44
+ it_should_accept 'location', %w[--id=1 --location-id=1]
45
45
  end
46
46
 
47
47
  end
@@ -90,18 +90,6 @@ describe HammerCLIForeman::SmartProxy do
90
90
 
91
91
  end
92
92
 
93
- context "ImportPuppetClassesCommand" do
94
-
95
- let(:cmd) { HammerCLIForeman::SmartProxy::ImportPuppetClassesCommand.new("", ctx) }
96
-
97
- context "parameters" do
98
- it_should_accept "id, environment-id and dryrun", ["--id=1", "--environment-id=1", "--dryrun"]
99
- # it_should_fail_with "id missing", []
100
- # TODO: temporarily disabled, parameters are checked in the id resolver
101
- end
102
-
103
- end
104
-
105
93
  context "RefreshFeaturesCommand" do
106
94
 
107
95
  let(:cmd) { HammerCLIForeman::SmartProxy::RefreshFeaturesCommand.new("", ctx) }
@@ -18,8 +18,8 @@ describe HammerCLIForeman::Usergroup do
18
18
  context "parameters" do
19
19
  it_should_accept "no arguments"
20
20
  it_should_accept_search_params
21
- it_should_fail_with 'organization param', ['--organization-id=1']
22
- it_should_fail_with 'location param', ['--location-id=1']
21
+ it_should_accept 'organization', ['--organization-id=1']
22
+ it_should_accept 'location', ['--location-id=1']
23
23
  end
24
24
 
25
25
  context "output" do
@@ -37,8 +37,8 @@ describe HammerCLIForeman::Usergroup do
37
37
  context "parameters" do
38
38
  it_should_accept "id", ["--id=1"]
39
39
  it_should_accept "name", ["--name=ug"]
40
- it_should_fail_with 'organization param', ['--organization-id=1']
41
- it_should_fail_with 'location param', ['--location-id=1']
40
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
41
+ it_should_accept 'location', %w[--id=1 --location-id=1]
42
42
  end
43
43
 
44
44
  context "output" do
@@ -62,8 +62,8 @@ describe HammerCLIForeman::Usergroup do
62
62
  context "parameters" do
63
63
  it_should_accept "name", ["--name=ug"]
64
64
  it_should_accept "name, role ids, user group ids and user ids", ["--name=ug", "--role-ids=1,2,3", "--user-group-ids=1,2,3", "--user-ids=1,2,3"]
65
- it_should_fail_with 'organization param', ['--organization-id=1']
66
- it_should_fail_with 'location param', ['--location-id=1']
65
+ it_should_accept 'organization', %w[--name=ug --organization-id=1]
66
+ it_should_accept 'location', %w[--name=ug --location-id=1]
67
67
  end
68
68
  end
69
69
 
@@ -74,8 +74,8 @@ describe HammerCLIForeman::Usergroup do
74
74
  context "parameters" do
75
75
  it_should_accept "name", ["--name=ug"]
76
76
  it_should_accept "id", ["--id=1"]
77
- it_should_fail_with 'organization param', ['--organization-id=1']
78
- it_should_fail_with 'location param', ['--location-id=1']
77
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
78
+ it_should_accept 'location', %w[--id=1 --location-id=1]
79
79
  end
80
80
  end
81
81
 
@@ -88,8 +88,8 @@ describe HammerCLIForeman::Usergroup do
88
88
  it_should_accept "id", ["--id=1"]
89
89
  it_should_accept "name and new name", ["--name=ug", "--new-name=ug2"]
90
90
  it_should_accept "id, new name, role ids, user group ids and user ids", ["--id=1", "--new-name=ug", "--role-ids=1,2,3", "--user-group-ids=1,2,3", "--user-ids=1,2,3"]
91
- it_should_fail_with 'organization param', ['--organization-id=1']
92
- it_should_fail_with 'location param', ['--location-id=1']
91
+ it_should_accept 'organization', %w[--id=1 --organization-id=1]
92
+ it_should_accept 'location', %w[--id=1 --location-id=1]
93
93
  end
94
94
  end
95
95
  end