hammer_cli_foreman 0.1.1 → 0.1.2

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

Potentially problematic release.


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

Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -3
  3. data/doc/developer_docs.md +13 -0
  4. data/doc/name_id_resolution.md +50 -0
  5. data/doc/option_builder.md +48 -0
  6. data/doc/release_notes.md +64 -0
  7. data/lib/hammer_cli_foreman.rb +100 -23
  8. data/lib/hammer_cli_foreman/architecture.rb +0 -1
  9. data/lib/hammer_cli_foreman/associating_commands.rb +71 -0
  10. data/lib/hammer_cli_foreman/auth.rb +0 -1
  11. data/lib/hammer_cli_foreman/commands.rb +112 -80
  12. data/lib/hammer_cli_foreman/common_parameter.rb +5 -3
  13. data/lib/hammer_cli_foreman/compute_resource.rb +0 -2
  14. data/lib/hammer_cli_foreman/dependency_resolver.rb +32 -0
  15. data/lib/hammer_cli_foreman/domain.rb +0 -1
  16. data/lib/hammer_cli_foreman/environment.rb +0 -2
  17. data/lib/hammer_cli_foreman/exception_handler.rb +3 -3
  18. data/lib/hammer_cli_foreman/fact.rb +1 -1
  19. data/lib/hammer_cli_foreman/filter.rb +102 -0
  20. data/lib/hammer_cli_foreman/host.rb +5 -7
  21. data/lib/hammer_cli_foreman/hostgroup.rb +4 -3
  22. data/lib/hammer_cli_foreman/id_resolver.rb +60 -51
  23. data/lib/hammer_cli_foreman/image.rb +0 -1
  24. data/lib/hammer_cli_foreman/location.rb +7 -3
  25. data/lib/hammer_cli_foreman/media.rb +1 -1
  26. data/lib/hammer_cli_foreman/model.rb +1 -1
  27. data/lib/hammer_cli_foreman/operating_system.rb +4 -6
  28. data/lib/hammer_cli_foreman/option_builders.rb +285 -0
  29. data/lib/hammer_cli_foreman/organization.rb +7 -3
  30. data/lib/hammer_cli_foreman/param_filters.rb +61 -0
  31. data/lib/hammer_cli_foreman/parameter.rb +5 -3
  32. data/lib/hammer_cli_foreman/partition_table.rb +1 -1
  33. data/lib/hammer_cli_foreman/puppet_class.rb +1 -1
  34. data/lib/hammer_cli_foreman/references.rb +16 -0
  35. data/lib/hammer_cli_foreman/report.rb +1 -1
  36. data/lib/hammer_cli_foreman/role.rb +78 -0
  37. data/lib/hammer_cli_foreman/smart_class_parameter.rb +1 -1
  38. data/lib/hammer_cli_foreman/smart_proxy.rb +17 -2
  39. data/lib/hammer_cli_foreman/smart_variables.rb +111 -0
  40. data/lib/hammer_cli_foreman/subnet.rb +1 -1
  41. data/lib/hammer_cli_foreman/template.rb +10 -4
  42. data/lib/hammer_cli_foreman/user.rb +5 -1
  43. data/lib/hammer_cli_foreman/usergroup.rb +58 -0
  44. data/lib/hammer_cli_foreman/version.rb +1 -1
  45. data/locale/Makefile +12 -11
  46. data/locale/README.md +18 -0
  47. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  48. data/locale/en/hammer-cli-foreman.po +1584 -0
  49. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  50. data/locale/en_GB/hammer-cli-foreman.po +1975 -0
  51. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  52. data/locale/es/hammer-cli-foreman.po +1976 -0
  53. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  54. data/locale/fr/hammer-cli-foreman.po +1976 -0
  55. data/locale/hammer-cli-foreman.pot +1197 -787
  56. data/test/unit/api_test.rb +25 -0
  57. data/test/unit/architecture_test.rb +1 -0
  58. data/test/unit/commands_test.rb +18 -0
  59. data/test/unit/common_parameter_test.rb +1 -0
  60. data/test/unit/compute_resource_test.rb +1 -0
  61. data/test/unit/data/1.6/foreman_api.json +1 -0
  62. data/test/unit/dependency_resolver_test.rb +42 -0
  63. data/test/unit/domain_test.rb +1 -0
  64. data/test/unit/environment_test.rb +1 -0
  65. data/test/unit/fact_test.rb +1 -0
  66. data/test/unit/filter_test.rb +133 -0
  67. data/test/unit/helpers/command.rb +0 -13
  68. data/test/unit/host_test.rb +3 -0
  69. data/test/unit/hostgroup_test.rb +1 -0
  70. data/test/unit/id_resolver_test.rb +21 -68
  71. data/test/unit/image_test.rb +1 -1
  72. data/test/unit/location_test.rb +2 -0
  73. data/test/unit/media_test.rb +2 -0
  74. data/test/unit/model_test.rb +1 -0
  75. data/test/unit/operating_system_test.rb +1 -0
  76. data/test/unit/option_builders_test.rb +543 -0
  77. data/test/unit/organization_test.rb +1 -0
  78. data/test/unit/param_filters_test.rb +143 -0
  79. data/test/unit/partition_table_test.rb +1 -0
  80. data/test/unit/puppet_class_test.rb +1 -0
  81. data/test/unit/report_test.rb +1 -0
  82. data/test/unit/role_test.rb +94 -0
  83. data/test/unit/smart_class_parameter_test.rb +1 -0
  84. data/test/unit/smart_proxy_test.rb +14 -1
  85. data/test/unit/subnet_test.rb +1 -0
  86. data/test/unit/template_test.rb +1 -0
  87. data/test/unit/test_helper.rb +1 -1
  88. data/test/unit/user_test.rb +1 -0
  89. data/test/unit/usergroup_test.rb +80 -0
  90. metadata +50 -7
  91. data/lib/hammer_cli_foreman/searchables_option_builder.rb +0 -99
  92. data/test/unit/searchables_option_builder_test.rb +0 -172
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'test_helper')
2
2
  require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
3
  require File.join(File.dirname(__FILE__), 'test_output_adapter')
4
4
 
5
-
5
+ require 'hammer_cli_foreman/image'
6
6
 
7
7
  describe HammerCLIForeman::Image do
8
8
 
@@ -1,6 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
  require File.join(File.dirname(__FILE__), 'helpers/resource_disabled')
3
3
 
4
+ require 'hammer_cli_foreman/location'
5
+
4
6
  describe HammerCLIForeman::Location do
5
7
 
6
8
  include CommandTestHelper
@@ -1,6 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
  require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
3
 
4
+ require 'hammer_cli_foreman/media'
5
+
4
6
  describe HammerCLIForeman::Medium do
5
7
 
6
8
  include CommandTestHelper
@@ -1,6 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
  require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
3
 
4
+ require 'hammer_cli_foreman/model'
4
5
 
5
6
  describe HammerCLIForeman::Model do
6
7
 
@@ -1,6 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
  require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
3
 
4
+ require 'hammer_cli_foreman/operating_system'
4
5
 
5
6
  describe HammerCLIForeman::OperatingSystem do
6
7
 
@@ -0,0 +1,543 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'helpers/fake_searchables')
3
+
4
+ describe HammerCLIForeman::BuildParams do
5
+
6
+ let(:params) { HammerCLIForeman::BuildParams.new }
7
+
8
+ it "creates empty hash by default" do
9
+ params.to_hash.must_equal( {} )
10
+ end
11
+
12
+ it "can be prefonfigured" do
13
+ preconfigured_params = HammerCLIForeman::BuildParams.new(:expand => {:only => [:a, :b]}, :without => [:c, :d])
14
+ preconfigured_params.expand.including(:c, :d)
15
+ preconfigured_params.to_hash.must_equal( {:expand => {:only => [:a, :b], :including => [:c, :d]}, :without => [:c, :d]} )
16
+ end
17
+
18
+ describe "without" do
19
+
20
+ it "sets :without" do
21
+ params.without(:organization_id, :location_id)
22
+ params.to_hash.must_equal( {:without => [:organization_id, :location_id]} )
23
+ end
24
+
25
+ end
26
+
27
+ describe "expand" do
28
+
29
+ it "can set expand all" do
30
+ params.expand(:all)
31
+ params.to_hash.must_equal( {:expand => {}} )
32
+ end
33
+
34
+ it "expands all by default" do
35
+ params.expand
36
+ params.to_hash.must_equal( {:expand => {}} )
37
+ end
38
+
39
+ it "can disable expansion" do
40
+ params.expand(:none)
41
+ params.to_hash.must_equal( {:expand => {:only => []}} )
42
+ end
43
+
44
+ describe "except" do
45
+ it "sets except field" do
46
+ params.expand.except(:organizations)
47
+ params.to_hash.must_equal( {:expand => {:except => [:organizations]}} )
48
+ end
49
+ end
50
+
51
+ describe "including" do
52
+ it "sets including field" do
53
+ params.expand.including(:organizations)
54
+ params.to_hash.must_equal( {:expand => {:including => [:organizations]}} )
55
+ end
56
+ end
57
+
58
+ describe "only" do
59
+ it "sets only field" do
60
+ params.expand.only(:organizations)
61
+ params.to_hash.must_equal( {:expand => {:only => [:organizations]}} )
62
+ end
63
+ end
64
+
65
+ describe "primary" do
66
+ it "sets primary field" do
67
+ params.expand.primary(:organizations)
68
+ params.to_hash.must_equal( {:expand => {:primary => :organizations}} )
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ describe HammerCLIForeman::BuilderConfigurator do
77
+
78
+ let(:resource) { HammerCLIForeman.foreman_resource!(:operatingsystems)}
79
+ let(:action) { resource.action(:index)}
80
+
81
+ let(:searchables) { FakeSearchables.new(["name", "label"]) }
82
+ let(:resolver) { HammerCLIForeman::DependencyResolver.new }
83
+ let(:configurator) { HammerCLIForeman::BuilderConfigurator.new(searchables, resolver) }
84
+
85
+ let(:result_builders) { configurator.builders_for(resource, action) }
86
+ let(:result_classes) { result_builders.map(&:class) }
87
+
88
+ def builders_by_class(cls)
89
+ result_builders.select {|b| b.class == cls}
90
+ end
91
+
92
+ def resource_names(builders)
93
+ builders.map(&:resource).map(&:name)
94
+ end
95
+
96
+ describe "simple action without ids" do
97
+
98
+ let(:action) { resource.action(:index)}
99
+
100
+ it "adds no option builder" do
101
+ result_classes.must_equal []
102
+ end
103
+
104
+ end
105
+
106
+ describe "simple show action without dependent resources" do
107
+
108
+ let(:action) { resource.action(:show)}
109
+
110
+ it "adds searchable options builder" do
111
+ resource_names(builders_by_class(HammerCLIForeman::SearchablesOptionBuilder)).must_equal [:operatingsystems]
112
+ end
113
+
114
+ end
115
+
116
+ describe "action with dependent resources" do
117
+
118
+ let(:resource) { HammerCLIForeman.foreman_resource!(:images)}
119
+ let(:action) { HammerCLIForeman.foreman_resource!(:images).action(:show)}
120
+
121
+ it "adds searchable options builder" do
122
+ resource_names(builders_by_class(HammerCLIForeman::SearchablesOptionBuilder)).must_equal [:images]
123
+ end
124
+
125
+ it "adds dependent searchable option builders" do
126
+ resource_names(builders_by_class(HammerCLIForeman::DependentSearchablesOptionBuilder)).must_equal [
127
+ :compute_resources
128
+ ]
129
+ end
130
+
131
+ end
132
+
133
+ end
134
+
135
+ describe HammerCLIForeman::ForemanOptionBuilder do
136
+
137
+ let(:options) {
138
+ [
139
+ HammerCLI::Options::OptionDefinition.new(["--test"], "TEST", "test"),
140
+ HammerCLI::Options::OptionDefinition.new(["--test2"], "TEST2", "test2")
141
+ ]
142
+ }
143
+ let(:searchables) { FakeSearchables.new(["name", "label"]) }
144
+ let(:container) { HammerCLIForeman::ForemanOptionBuilder.new(searchables) }
145
+ let(:builder_classes) { container.builders.map(&:class) }
146
+
147
+
148
+ it "collects options from contained builders" do
149
+ builder = Object.new
150
+ builder.stubs(:build).returns(options)
151
+
152
+ container.builders = [builder, builder]
153
+ container.build.must_equal options+options
154
+ end
155
+
156
+ it "passes build parameters to contained builders" do
157
+ params = {:param => :value}
158
+ builder = Object.new
159
+ builder.expects(:build).with(params).returns(options)
160
+
161
+ container.builders = [builder]
162
+ container.build(params)
163
+ end
164
+
165
+
166
+ context "primary searchables options expansion" do
167
+ let(:option_switches) { container.build(@build_options).map(&:switches) }
168
+
169
+ it "can remove original searchable builder" do
170
+ container.builders = [
171
+ HammerCLIForeman::SearchablesOptionBuilder.new(HammerCLIForeman.foreman_resource(:organizations), FakeSearchables.new(["aaa", "bbb"]))
172
+ ]
173
+ @build_options = {:expand => {:primary => false}}
174
+ option_switches.must_equal []
175
+ end
176
+
177
+ it "can add custom searchable builder" do
178
+ container.builders = []
179
+ @build_options = {:expand => {:primary => :organizations}}
180
+ option_switches.must_equal [
181
+ ["--name"],
182
+ ["--label"]
183
+ ]
184
+ end
185
+
186
+ it "can replace original searchable builder with a custom one" do
187
+ container.builders = [
188
+ HammerCLIForeman::SearchablesOptionBuilder.new(HammerCLIForeman.foreman_resource(:locations), FakeSearchables.new(["aaa", "bbb"]))
189
+ ]
190
+ @build_options = {:expand => {:primary => :organizations}}
191
+ option_switches.must_equal [
192
+ ["--name"],
193
+ ["--label"]
194
+ ]
195
+ end
196
+
197
+ end
198
+
199
+ context "dependent searchables options expansion" do
200
+ let(:option_switches) { container.build(@build_options).map(&:switches) }
201
+
202
+ before :each do
203
+ container.builders = [
204
+ HammerCLIForeman::DependentSearchablesOptionBuilder.new(HammerCLIForeman.foreman_resource(:organizations), searchables),
205
+ HammerCLIForeman::DependentSearchablesOptionBuilder.new(HammerCLIForeman.foreman_resource(:locations), searchables)
206
+ ]
207
+ end
208
+
209
+ it "does not filter searchable builders by default" do
210
+ @build_options = {:expand => {}}
211
+ option_switches.must_equal [
212
+ ["--organization"],
213
+ ["--organization-label"],
214
+ ["--organization-id"],
215
+ ["--location"],
216
+ ["--location-label"],
217
+ ["--location-id"]
218
+ ]
219
+ end
220
+
221
+ it "adds dependent searchable builders on explicit requirement" do
222
+ @build_options = {:expand => {:including => [:organizations, :architectures]}}
223
+ option_switches.must_equal [
224
+ ["--organization"],
225
+ ["--organization-label"],
226
+ ["--organization-id"],
227
+ ["--location"],
228
+ ["--location-label"],
229
+ ["--location-id"],
230
+ ["--architecture"],
231
+ ["--architecture-label"],
232
+ ["--architecture-id"]
233
+ ]
234
+ end
235
+
236
+ it "filters dependent searchable builders on explicit requirement" do
237
+ @build_options = {:expand => {:except => [:organizations]}}
238
+ option_switches.must_equal [
239
+ ["--location"],
240
+ ["--location-label"],
241
+ ["--location-id"]
242
+ ]
243
+ end
244
+
245
+ it "specifies custom set of dependent searchable builders on explicit requirement" do
246
+ @build_options = {:expand => {:only => [:architectures, :organizations]}}
247
+ option_switches.must_equal [
248
+ ["--organization"],
249
+ ["--organization-label"],
250
+ ["--organization-id"],
251
+ ["--architecture"],
252
+ ["--architecture-label"],
253
+ ["--architecture-id"]
254
+ ]
255
+ end
256
+
257
+ end
258
+
259
+
260
+
261
+ end
262
+
263
+
264
+ describe HammerCLIForeman::SearchablesOptionBuilder do
265
+
266
+ let(:resource) { HammerCLIForeman.foreman_resource!(:architectures) }
267
+ let(:searchables) { FakeSearchables.new(["name", "label"]) }
268
+ let(:builder) { HammerCLIForeman::SearchablesOptionBuilder.new(resource, searchables) }
269
+ let(:options) { builder.build }
270
+
271
+ describe "empty searchables" do
272
+ let(:searchables) { FakeSearchables.new([]) }
273
+
274
+ it "builds no options for empty searchables" do
275
+ options.must_equal []
276
+ end
277
+ end
278
+
279
+ describe "multiple searchables" do
280
+
281
+ it "builds correct switches" do
282
+ options.map(&:switches).must_equal [["--name"], ["--label"]]
283
+ end
284
+
285
+ it "builds correct descriptions" do
286
+ options.map(&:description).must_equal ["Search by name", "Search by label"]
287
+ end
288
+
289
+ it "builds correct types" do
290
+ options.map(&:type).must_equal ["NAME", "LABEL"]
291
+ end
292
+
293
+ it "builds correct attribute readers" do
294
+ options.map(&:read_method).must_equal [
295
+ "option_name",
296
+ "option_label"
297
+ ]
298
+ end
299
+
300
+ it "none of the options is required" do
301
+ options.any?{|opt| opt.required? }.must_equal false
302
+ end
303
+ end
304
+
305
+ end
306
+
307
+
308
+ describe HammerCLIForeman::DependentSearchablesOptionBuilder do
309
+
310
+ let(:resource) { HammerCLIForeman.foreman_resource!(:architectures) }
311
+ let(:searchables) { FakeSearchables.new(["name", "label", "uuid"]) }
312
+ let(:builder) { HammerCLIForeman::DependentSearchablesOptionBuilder.new(resource, searchables) }
313
+ let(:builder_params) { {} }
314
+ let(:options) { builder.build(builder_params) }
315
+
316
+ describe "empty searchables" do
317
+
318
+ let(:searchables) { FakeSearchables.new([]) }
319
+
320
+ it "builds only id options" do
321
+ options.map(&:switches).must_equal [["--architecture-id"]]
322
+ end
323
+
324
+ end
325
+
326
+
327
+ describe "multiple searchables" do
328
+
329
+ it "creates correct switches" do
330
+ options.map(&:switches).must_equal [
331
+ ["--architecture"], # first option does not have the suffix
332
+ ["--architecture-label"], # other options with suffixes
333
+ ["--architecture-uuid"],
334
+ ["--architecture-id"] # additional id
335
+ ]
336
+ end
337
+
338
+ it "creates correct option types" do
339
+ options.map(&:type).must_equal [
340
+ "ARCHITECTURE_NAME",
341
+ "ARCHITECTURE_LABEL",
342
+ "ARCHITECTURE_UUID",
343
+ "ARCHITECTURE_ID",
344
+ ]
345
+ end
346
+
347
+ it "creates correct descriptions" do
348
+ options.map(&:description).must_equal [
349
+ "Search by name",
350
+ "Search by label",
351
+ "Search by uuid",
352
+ ""
353
+ ]
354
+ end
355
+
356
+ it "creates correct attribute readers" do
357
+ options.map(&:read_method).must_equal [
358
+ "option_architecture_name",
359
+ "option_architecture_label",
360
+ "option_architecture_uuid",
361
+ "option_architecture_id",
362
+ ]
363
+ end
364
+
365
+ it "none of the options is required" do
366
+ options.any?{|opt| opt.required? }.must_equal false
367
+ end
368
+ end
369
+
370
+
371
+ describe "aliasing resource names" do
372
+
373
+ let(:builder_params) { {:resource_mapping => {:architecture => :arch}} }
374
+
375
+ it "renames options" do
376
+ options.map(&:switches).must_equal [
377
+ ["--arch"], # first option does not have the suffix
378
+ ["--arch-label"], # other options with suffixes
379
+ ["--arch-uuid"],
380
+ ["--arch-id"] # additional id
381
+ ]
382
+ end
383
+
384
+ it "renames option types" do
385
+ options.map(&:type).must_equal [
386
+ "ARCH_NAME",
387
+ "ARCH_LABEL",
388
+ "ARCH_UUID",
389
+ "ARCH_ID",
390
+ ]
391
+ end
392
+
393
+ it "keeps option accessor the same" do
394
+ options.map(&:attribute_name).must_equal [
395
+ "option_architecture_name",
396
+ "option_architecture_label",
397
+ "option_architecture_uuid",
398
+ "option_architecture_id"
399
+ ]
400
+ end
401
+
402
+ end
403
+
404
+ describe "resources with id parameter in show action" do
405
+
406
+ before :each do
407
+ id_param = Object.new
408
+ id_param.stubs(:name).returns("id")
409
+ id_param.stubs(:params).returns([])
410
+ id_param.stubs(:description).returns("DESC")
411
+
412
+ action = Object.new
413
+ action.stubs(:params).returns([id_param])
414
+
415
+ resource.stubs(:action).with(:show).returns(action)
416
+ end
417
+
418
+ it "uses descriptions from the action" do
419
+ options.map(&:description).must_equal [
420
+ "Search by name",
421
+ "Search by label",
422
+ "Search by uuid",
423
+ "DESC"
424
+ ]
425
+ end
426
+
427
+ end
428
+
429
+ end
430
+
431
+
432
+ describe HammerCLIForeman::SearchablesUpdateOptionBuilder do
433
+
434
+ let(:resource) { HammerCLIForeman.foreman_resource!(:architectures) }
435
+ let(:searchables) { FakeSearchables.new(["name"], ["label"]) }
436
+ let(:builder) { HammerCLIForeman::SearchablesUpdateOptionBuilder.new(resource, searchables) }
437
+ let(:options) { builder.build }
438
+
439
+ describe "empty searchables" do
440
+ let(:searchables) { FakeSearchables.new([]) }
441
+
442
+ it "builds no options for empty searchables" do
443
+ options.must_equal []
444
+ end
445
+ end
446
+
447
+ describe "multiple searchables" do
448
+
449
+ it "builds correct switches" do
450
+ options.map(&:switches).must_equal [["--new-label"]]
451
+ end
452
+
453
+ it "builds correct descriptions" do
454
+ options.map(&:description).must_equal [" "]
455
+ end
456
+
457
+ it "builds correct types" do
458
+ options.map(&:type).must_equal ["NEW_LABEL"]
459
+ end
460
+
461
+ it "builds correct attribute readers" do
462
+ options.map(&:read_method).must_equal [
463
+ "option_new_label"
464
+ ]
465
+ end
466
+
467
+ it "none of the options is required" do
468
+ options.any?{|opt| opt.required? }.must_equal false
469
+ end
470
+ end
471
+
472
+ describe "resources with corresponding parameter in update action" do
473
+
474
+ before :each do
475
+ label_param = Object.new
476
+ label_param.stubs(:name).returns("label")
477
+ label_param.stubs(:params).returns([])
478
+ label_param.stubs(:description).returns("DESC")
479
+
480
+ action = Object.new
481
+ action.stubs(:params).returns([label_param])
482
+
483
+ resource.stubs(:action).with(:update).returns(action)
484
+ end
485
+
486
+ it "uses descriptions from the action" do
487
+ options.map(&:description).must_equal ["DESC"]
488
+ end
489
+
490
+ end
491
+
492
+
493
+ end
494
+
495
+
496
+ describe HammerCLIForeman::IdOptionBuilder do
497
+
498
+ let(:resource) { HammerCLIForeman.foreman_resource!(:architectures) }
499
+ let(:builder) { HammerCLIForeman::IdOptionBuilder.new(resource) }
500
+ let(:options) { builder.build }
501
+
502
+ describe "resources with parameter :id in show action" do
503
+
504
+ before :each do
505
+ id_param = Object.new
506
+ id_param.stubs(:name).returns("id")
507
+ id_param.stubs(:params).returns([])
508
+ id_param.stubs(:description).returns("DESC")
509
+
510
+ action = Object.new
511
+ action.stubs(:params).returns([id_param])
512
+
513
+ resource.stubs(:action).with(:show).returns(action)
514
+ end
515
+
516
+ it "creates options --id" do
517
+ options.map(&:switches).must_equal [["--id"]]
518
+ end
519
+
520
+ it "uses description from the :id param" do
521
+ options.map(&:description).must_equal ["DESC"]
522
+ end
523
+ end
524
+
525
+ describe "resources without parameter :id in show action" do
526
+
527
+ before :each do
528
+ action = Object.new
529
+ action.stubs(:params).returns([])
530
+
531
+ resource.stubs(:action).with(:show).returns(action)
532
+ end
533
+
534
+ it "creates options --id" do
535
+ options.map(&:switches).must_equal [["--id"]]
536
+ end
537
+
538
+ it "uses empty description" do
539
+ options.map(&:description).must_equal [" "]
540
+ end
541
+ end
542
+
543
+ end