hammer_cli_foreman 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +13 -0
  3. data/lib/hammer_cli_foreman/command_extensions/subnet.rb +25 -10
  4. data/lib/hammer_cli_foreman/command_extensions/user.rb +9 -5
  5. data/lib/hammer_cli_foreman/commands.rb +1 -2
  6. data/lib/hammer_cli_foreman/compute_attribute.rb +1 -1
  7. data/lib/hammer_cli_foreman/compute_resource.rb +1 -0
  8. data/lib/hammer_cli_foreman/hostgroup.rb +13 -6
  9. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +7 -7
  10. data/lib/hammer_cli_foreman/id_resolver.rb +7 -7
  11. data/lib/hammer_cli_foreman/option_builders.rb +65 -53
  12. data/lib/hammer_cli_foreman/option_sources/id_params.rb +21 -8
  13. data/lib/hammer_cli_foreman/option_sources/ids_params.rb +22 -9
  14. data/lib/hammer_cli_foreman/smart_proxy.rb +7 -5
  15. data/lib/hammer_cli_foreman/template.rb +3 -15
  16. data/lib/hammer_cli_foreman/user.rb +4 -4
  17. data/lib/hammer_cli_foreman/version.rb +1 -1
  18. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  19. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  20. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  21. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  22. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  23. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  24. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  25. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  26. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  27. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  28. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  29. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  30. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  31. data/test/data/3.1/foreman_api.json +1 -0
  32. data/test/functional/compute_attribute_test.rb +20 -20
  33. data/test/functional/host_test.rb +34 -0
  34. data/test/functional/hostgroup/create_test.rb +11 -0
  35. data/test/functional/hostgroup/update_test.rb +11 -0
  36. data/test/functional/personal_access_token_test.rb +4 -4
  37. data/test/functional/template_test.rb +74 -14
  38. data/test/functional/user_mail_notification_test.rb +3 -3
  39. data/test/test_helper.rb +1 -1
  40. data/test/unit/commands_test.rb +1 -2
  41. data/test/unit/option_builders_test.rb +88 -83
  42. data/test/unit/option_sources/id_params_test.rb +0 -9
  43. data/test/unit/option_sources/ids_params_test.rb +0 -9
  44. metadata +28 -26
@@ -11,11 +11,11 @@ describe "parameters" do
11
11
  }
12
12
  end
13
13
 
14
- it "should print error on missing --compute-profile-id or --compute-profile" do
14
+ it 'should print error on missing --compute-profile-id or --compute-profile' do
15
15
  expected_result = common_error_result(
16
16
  @cmd,
17
- "Could not find compute_profile, please set one of options --compute-profile, --compute-profile-id.",
18
- "Could not set the compute profile attributes"
17
+ 'Could not find compute_profile, please set one of options --compute-profile-id, --compute-profile.',
18
+ 'Could not set the compute profile attributes'
19
19
  )
20
20
 
21
21
  api_expects_no_call
@@ -23,12 +23,12 @@ describe "parameters" do
23
23
  assert_cmd(expected_result, result)
24
24
  end
25
25
 
26
- it "should print error on missing --compute-resource-id or --compute-resource" do
26
+ it 'should print error on missing --compute-resource-id or --compute-resource' do
27
27
  params = ['--compute-profile-id=1']
28
28
  expected_result = common_error_result(
29
29
  @cmd,
30
- "Could not find compute_resource, please set one of options --compute-resource, --compute-resource-id.",
31
- "Could not set the compute profile attributes"
30
+ 'Could not find compute_resource, please set one of options --compute-resource-id, --compute-resource.',
31
+ 'Could not set the compute profile attributes'
32
32
  )
33
33
 
34
34
  api_expects_no_call
@@ -103,11 +103,11 @@ describe "parameters" do
103
103
  params = ['--compute-profile-id=1', '--compute-resource-id=1', '--compute-attributes', 'cores=1']
104
104
 
105
105
  api_expects(:compute_profiles, :show) do |par|
106
- par['id'] == 1
106
+ par['id'] == '1'
107
107
  end.returns(@compute_profile)
108
108
 
109
109
  api_expects(:compute_resources, :show) do |par|
110
- par['id'] == 1
110
+ par['id'] == '1'
111
111
  end.returns(@compute_resource)
112
112
 
113
113
  api_expects(:compute_attributes, :update) do |par|
@@ -177,7 +177,7 @@ describe "parameters" do
177
177
  expected_result.expected_exit_code = HammerCLI::EX_USAGE
178
178
 
179
179
  api_expects(:compute_profiles, :show) do |par|
180
- par['id'] == 1
180
+ par['id'] == '1'
181
181
  end.returns(@compute_profile)
182
182
 
183
183
  result = run_cmd(@cmd + params)
@@ -189,7 +189,7 @@ describe "parameters" do
189
189
  params = ['--compute-profile-id=1', '--compute-resource-id=1', '--volume', 'size_gb=1']
190
190
 
191
191
  api_expects(:compute_profiles, :show) do |par|
192
- par['id'] == 1
192
+ par['id'] == '1'
193
193
  end.returns(@compute_profile)
194
194
 
195
195
  api_expects(:compute_attributes, :update) do |par|
@@ -261,7 +261,7 @@ describe "parameters" do
261
261
  params = ['--compute-profile-id=1', '--compute-resource-id=1', '--volume-id=1', '--volume', 'size_gb=1']
262
262
 
263
263
  api_expects(:compute_profiles, :show) do |par|
264
- par['id'] == 1
264
+ par['id'] == '1'
265
265
  end.returns(@compute_profile)
266
266
 
267
267
  api_expects(:compute_attributes, :update) do |par|
@@ -339,7 +339,7 @@ describe "parameters" do
339
339
  params = ['--compute-profile-id=1', '--compute-resource-id=1', '--volume-id=1']
340
340
 
341
341
  api_expects(:compute_profiles, :show) do |par|
342
- par['id'] == 1
342
+ par['id'] == '1'
343
343
  end.returns(@compute_profile)
344
344
 
345
345
  api_expects(:compute_attributes, :update) do |par|
@@ -438,7 +438,7 @@ describe "parameters" do
438
438
  expected_result.expected_exit_code = HammerCLI::EX_USAGE
439
439
 
440
440
  api_expects(:compute_profiles, :show) do |par|
441
- par['id'] == 1
441
+ par['id'] == '1'
442
442
  end.returns(@compute_profile)
443
443
  result = run_cmd(@cmd + params)
444
444
  assert_cmd(expected_result, result)
@@ -455,7 +455,7 @@ describe "parameters" do
455
455
  response = HammerCLIForeman.foreman_api.api.send(:create_fake_response, 404,
456
456
  expected_message, "GET", "http://example.com/", {})
457
457
  api_expects(:compute_profiles, :show) do |par|
458
- par['id'] == 200
458
+ par['id'] == '200'
459
459
  end.raises(RestClient::NotFound, response)
460
460
 
461
461
  result = run_cmd(@cmd + params)
@@ -465,11 +465,11 @@ describe "parameters" do
465
465
  it "should add interface" do
466
466
  params = [ '--interface', 'name=eth0', '--compute-profile-id=1', '--compute-resource-id=1']
467
467
  api_expects(:compute_profiles, :show) do |par|
468
- par['id'] == 1
468
+ par['id'] == '1'
469
469
  end.returns(@compute_profile)
470
470
 
471
471
  api_expects(:compute_resources, :show) do |par|
472
- par['id'] == 1
472
+ par['id'] == '1'
473
473
  end.returns(@compute_resource)
474
474
 
475
475
  api_expects(:compute_attributes, :update) do |par|
@@ -548,11 +548,11 @@ describe "parameters" do
548
548
  params = ['--compute-profile-id=1', '--compute-resource-id=1', '--interface-id=1', '--interface', 'compute_name=eth0']
549
549
 
550
550
  api_expects(:compute_profiles, :show) do |par|
551
- par['id'] == 1
551
+ par['id'] == '1'
552
552
  end.returns(@compute_profile)
553
553
 
554
554
  api_expects(:compute_resources, :show) do |par|
555
- par['id'] == 1
555
+ par['id'] == '1'
556
556
  end.returns(@compute_resource)
557
557
 
558
558
  api_expects(:compute_attributes, :update) do |par|
@@ -637,11 +637,11 @@ describe "parameters" do
637
637
  params = ['--compute-profile-id=1', '--compute-resource-id=1', '--interface-id=1']
638
638
 
639
639
  api_expects(:compute_profiles, :show) do |par|
640
- par['id'] == 1
640
+ par['id'] == '1'
641
641
  end.returns(@compute_profile)
642
642
 
643
643
  api_expects(:compute_resources, :show) do |par|
644
- par['id'] == 1
644
+ par['id'] == '1'
645
645
  end.returns(@compute_resource)
646
646
 
647
647
  api_expects(:compute_attributes, :update) do |par|
@@ -568,7 +568,41 @@ describe 'disassociate host from vm' do
568
568
  end
569
569
  end
570
570
 
571
+ describe 'defaults' do
572
+ let(:cmd) { %w[host list] }
573
+ let(:defaults) do
574
+ HammerCLI::Defaults.new(
575
+ {
576
+ organization_id: {
577
+ value: '1'
578
+ },
579
+ organization: {
580
+ value: 'Default Organization'
581
+ }
582
+ }
583
+ )
584
+ end
585
+
586
+ it 'works with default org name overridden via cli' do
587
+ params = %w[--organization=Org2]
571
588
 
589
+ api_expects_search(:organizations, name: 'Org2').returns(index_response([{ 'id' => '2' }]))
590
+ api_expects(:hosts, :index) do |p|
591
+ p['organization_id'] == '2'
592
+ end
593
+
594
+ run_cmd(cmd + params, { use_defaults: true, defaults: defaults })
595
+ end
596
+ it 'works with default org id overridden via cli' do
597
+ params = %w[--organization-id=2]
598
+
599
+ api_expects(:hosts, :index) do |p|
600
+ p['organization_id'] == '2'
601
+ end
602
+
603
+ run_cmd(cmd + params, { use_defaults: true, defaults: defaults })
604
+ end
605
+ end
572
606
 
573
607
  describe 'list' do
574
608
  before do
@@ -165,6 +165,17 @@ module HammerCLIForeman
165
165
  run_cmd(%w(hostgroup create --name hg1 --parent parent_hg))
166
166
  end
167
167
 
168
+ it 'allows parent hostgroup title' do
169
+ api_expects(:hostgroups, :index) do |p|
170
+ p[:search] = 'title = "parent_hg"'
171
+ end.returns(index_response([{ 'id' => 1 }]))
172
+ api_expects(:hostgroups, :create) do |p|
173
+ p['hostgroup']['parent_id'] == 1 &&
174
+ p['hostgroup']['name'] == 'hg1'
175
+ end
176
+ run_cmd(%w[hostgroup create --name hg1 --parent parent_hg])
177
+ end
178
+
168
179
  it 'allows partition table id' do
169
180
  api_expects(:hostgroups, :create) do |p|
170
181
  p['hostgroup']['ptable_id'] == 1 &&
@@ -163,6 +163,17 @@ module HammerCLIForeman
163
163
  run_cmd(%w(hostgroup update --id 1 --parent parent_hg))
164
164
  end
165
165
 
166
+ it 'allows parent hostgroup title' do
167
+ api_expects(:hostgroups, :index) do |p|
168
+ p[:search] = 'title = "parent_hg"'
169
+ end.returns(index_response([{ 'id' => 1 }]))
170
+ api_expects(:hostgroups, :update) do |p|
171
+ p['hostgroup']['parent_id'] == 1 &&
172
+ p['id'] == '1'
173
+ end
174
+ run_cmd(%w[hostgroup update --id 1 --parent parent_hg])
175
+ end
176
+
166
177
  it 'allows partition table id' do
167
178
  api_expects(:hostgroups, :update) do |p|
168
179
  p['hostgroup']['ptable_id'] == 1 &&
@@ -37,7 +37,7 @@ describe 'personal_access_token' do
37
37
 
38
38
  it 'lists all access tokens for a given user' do
39
39
  api_expects(:personal_access_tokens, :index, 'List').with_params(
40
- 'user_id' => 1, 'page' => 1, 'per_page' => 1000
40
+ 'user_id' => '1', 'page' => 1, 'per_page' => 1000
41
41
  ).returns(index_response([access_token, active_access_token]))
42
42
 
43
43
  output = IndexMatcher.new([
@@ -67,7 +67,7 @@ describe 'personal_access_token' do
67
67
 
68
68
  it 'creates an access token to a given user' do
69
69
  api_expects(:personal_access_tokens, :create).with_params(
70
- 'user_id' => 1, 'personal_access_token' => {
70
+ 'user_id' => '1', 'personal_access_token' => {
71
71
  'expires_at' => '01/01/2048', 'name' => 'test'
72
72
  }
73
73
  ).returns(access_token)
@@ -85,7 +85,7 @@ describe 'personal_access_token' do
85
85
 
86
86
  it 'shows the personal access token' do
87
87
  api_expects(:personal_access_tokens, :show, 'Show PAT').with_params(
88
- 'id' => '1', 'user_id' => 1
88
+ 'id' => '1', 'user_id' => '1'
89
89
  ).returns(access_token)
90
90
 
91
91
  output = OutputMatcher.new([
@@ -109,7 +109,7 @@ describe 'personal_access_token' do
109
109
  let(:params) { ['--id=1', '--user-id=1'] }
110
110
  it 'deletes an access token to a given user' do
111
111
  api_expects(:personal_access_tokens, :destroy, 'Revoke PAT').with_params(
112
- 'id' => '1', 'user_id' => 1
112
+ 'id' => '1', 'user_id' => '1'
113
113
  ).returns(access_token)
114
114
 
115
115
  expected_result = success_result(
@@ -85,7 +85,6 @@ describe 'template' do
85
85
  it "doesn't send snippet flag when --type is undefined" do
86
86
  params = ['--id=1', '--locked=true']
87
87
 
88
- api_expects(:template_kinds, :index, 'Get list of template kinds').returns(index_response([]))
89
88
  api_expects(:provisioning_templates, :update, 'Update the template') do |par|
90
89
  par['id'] == '1' &&
91
90
  par['provisioning_template']['locked'] == true
@@ -99,7 +98,6 @@ describe 'template' do
99
98
  it 'updates nothing without template related parameters' do
100
99
  params = %w[--id=1 --organization-id=1 --location-id=1]
101
100
 
102
- api_expects(:template_kinds, :index, 'Get list of template kinds').returns(index_response([]))
103
101
  api_expects(:provisioning_templates, :update, 'Update template with no params').returns({})
104
102
 
105
103
  expected_result = success_result("Nothing to update.\n")
@@ -107,6 +105,48 @@ describe 'template' do
107
105
  result = run_cmd(@cmd + params)
108
106
  assert_cmd(expected_result, result)
109
107
  end
108
+
109
+ it 'should update a template' do
110
+ params = ['--id=1', '--type=snippet']
111
+
112
+ expected_result = CommandExpectation.new
113
+ expected_result.expected_out =
114
+ ['Provisioning template updated.',
115
+ ''].join("\n")
116
+ expected_result.expected_exit_code = HammerCLI::EX_OK
117
+
118
+ api_expects(:provisioning_templates, :update, 'Update template with params') do |p|
119
+ p['id'] == '1' && p['provisioning_template']['snippet'] == true
120
+ end
121
+
122
+ result = run_cmd(@cmd + params)
123
+ assert_cmd(expected_result, result)
124
+ end
125
+
126
+ it 'should update a template by name' do
127
+ params = ['--name=tpl', '--type=provision']
128
+
129
+ expected_result = CommandExpectation.new
130
+ expected_result.expected_out =
131
+ ['Provisioning template updated.',
132
+ ''].join("\n")
133
+ expected_result.expected_exit_code = HammerCLI::EX_OK
134
+
135
+ api_expects_search(:provisioning_templates, name: 'tpl').returns(
136
+ index_response([{ 'id' => '1' }])
137
+ )
138
+ api_expects_search(:template_kinds, name: 'provision').returns(
139
+ index_response([{ 'id' => '1' }])
140
+ )
141
+ api_expects(:provisioning_templates, :update, 'Update template with params') do |p|
142
+ p['id'] == '1' &&
143
+ p['provisioning_template']['snippet'] == false &&
144
+ p['provisioning_template']['template_kind_id'] == '1'
145
+ end
146
+
147
+ result = run_cmd(@cmd + params)
148
+ assert_cmd(expected_result, result)
149
+ end
110
150
  end
111
151
 
112
152
  describe 'create' do
@@ -120,15 +160,35 @@ describe 'template' do
120
160
  expected_result = CommandExpectation.new
121
161
  expected_result.expected_err =
122
162
  ['Could not create the provisioning template:',
123
- " Error: unknown template kind",
124
- ' ',
125
- " See: 'hammer template create --help'.",
163
+ ' Error: template_kind not found.',
126
164
  ''].join("\n")
127
- expected_result.expected_exit_code = HammerCLI::EX_USAGE
165
+ expected_result.expected_exit_code = HammerCLI::EX_SOFTWARE
128
166
 
129
- HammerCLIForeman::Template::CreateCommand.any_instance.stubs(:kinds).returns(["PXELinux"])
167
+ api_expects_search(:template_kinds, name: 'unknown').returns(
168
+ index_response([])
169
+ )
130
170
 
131
- api_expects_no_call
171
+ result = run_cmd(@cmd + params)
172
+ assert_cmd(expected_result, result)
173
+ end
174
+
175
+ it 'should create a template' do
176
+ params = ['--name=tpl', '--file=Gemfile', '--type=provision']
177
+
178
+ expected_result = CommandExpectation.new
179
+ expected_result.expected_out =
180
+ ['Provisioning template created.',
181
+ ''].join("\n")
182
+ expected_result.expected_exit_code = HammerCLI::EX_OK
183
+
184
+ api_expects_search(:template_kinds, name: 'provision').returns(
185
+ index_response([{ 'id' => '1' }])
186
+ )
187
+ api_expects(:provisioning_templates, :create, 'Create template with params') do |p|
188
+ p['provisioning_template']['name'] == 'tpl' &&
189
+ p['provisioning_template']['snippet'] == false &&
190
+ p['provisioning_template']['template_kind_id'] = '1'
191
+ end
132
192
 
133
193
  result = run_cmd(@cmd + params)
134
194
  assert_cmd(expected_result, result)
@@ -144,9 +204,9 @@ describe 'template' do
144
204
  params = ['create','--provisioning-template-id=10', '--hostgroup-id=1']
145
205
  expected_result = success_result("Template combination created.\n")
146
206
  api_expects(:template_combinations, :create, 'Create template combination') do |params|
147
- params['provisioning_template_id'] == 10 &&
148
- params['hostgroup_id'] == 1 &&
149
- params['template_combination'] == {'hostgroup_id' => 1}
207
+ params['provisioning_template_id'] == '10' &&
208
+ params['hostgroup_id'] == '1' &&
209
+ params['template_combination'] == { 'hostgroup_id' => '1' }
150
210
  end
151
211
 
152
212
  result = run_cmd(@cmd + params)
@@ -158,9 +218,9 @@ describe 'template' do
158
218
  expected_result = success_result("Template combination updated.\n")
159
219
  api_expects(:template_combinations, :update, 'Update template combination') do |params|
160
220
  params['id'] == '3' &&
161
- params['provisioning_template_id'] == 10 &&
162
- params['hostgroup_id'] == 1 &&
163
- params['template_combination'] == { 'hostgroup_id' => 1 }
221
+ params['provisioning_template_id'] == '10' &&
222
+ params['hostgroup_id'] == '1' &&
223
+ params['template_combination'] == { 'hostgroup_id' => '1' }
164
224
  end
165
225
 
166
226
  result = run_cmd(@cmd + params)
@@ -55,9 +55,9 @@ describe 'user_mail_notification' do
55
55
  params = ['--user-id=2']
56
56
 
57
57
  expected_result = common_error_result(
58
- @cmd,
59
- "Could not find mail_notification, please set one of options --mail-notification, --mail-notification-id.",
60
- "Could not add user mail notification"
58
+ @cmd,
59
+ 'Could not find mail_notification, please set one of options --mail-notification-id, --mail-notification.',
60
+ 'Could not add user mail notification'
61
61
  )
62
62
 
63
63
  result = run_cmd(@cmd + params)
data/test/test_helper.rb CHANGED
@@ -17,7 +17,7 @@ require "mocha/minitest"
17
17
  require 'hammer_cli'
18
18
  require 'hammer_cli_foreman/testing/api_expectations'
19
19
 
20
- FOREMAN_VERSION = ENV['TEST_API_VERSION'] || '2.5'
20
+ FOREMAN_VERSION = ENV['TEST_API_VERSION'] || '3.1'
21
21
  unless Dir.entries('test/data').include? FOREMAN_VERSION
22
22
  raise StandardError.new "Version is not correct"
23
23
  end
@@ -183,8 +183,7 @@ describe HammerCLIForeman::Command do
183
183
  out, err = capture_io do
184
184
  _(com.run(['--location', 'loc'])).wont_equal HammerCLI::EX_OK
185
185
  end
186
- _(err).must_equal "Error: Could not find location, please set one of options --location, --location-title, --location-id.\n"
187
-
186
+ _(err).must_equal "Error: Could not find location, please set one of options --location-id, --location, --location-title.\n"
188
187
  end
189
188
 
190
189
  it "ignores error on attempt to search of parameters that are not required" do
@@ -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