hammer_cli_foreman 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/doc/host_create.md +120 -85
  3. data/doc/release_notes.md +12 -0
  4. data/lib/hammer_cli_foreman/compute_resource.rb +106 -11
  5. data/lib/hammer_cli_foreman/compute_resources/vmware/host_help_extenstion.rb +25 -21
  6. data/lib/hammer_cli_foreman/host.rb +42 -1
  7. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +9 -3
  8. data/lib/hammer_cli_foreman/output/fields.rb +45 -10
  9. data/lib/hammer_cli_foreman/output/formatters.rb +82 -45
  10. data/lib/hammer_cli_foreman/subnet.rb +25 -0
  11. data/lib/hammer_cli_foreman/version.rb +1 -1
  12. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  13. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  14. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  15. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  16. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  17. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  18. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  19. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  20. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  21. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  22. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  23. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  24. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  25. data/test/functional/compute_resource_test.rb +260 -0
  26. data/test/functional/host_test.rb +49 -0
  27. data/test/functional/subnet/create_test.rb +131 -0
  28. data/test/functional/subnet/update_test.rb +130 -0
  29. data/test/unit/apipie_resource_mock.rb +4 -0
  30. data/test/unit/compute_resource_test.rb +22 -0
  31. data/test/unit/host_test.rb +2 -2
  32. data/test/unit/output/formatters_test.rb +77 -68
  33. metadata +10 -6
@@ -53,6 +53,42 @@ describe 'host enc-dump' do
53
53
  end
54
54
  end
55
55
 
56
+ describe 'host boot' do
57
+ let(:cmd) { ['host', 'boot'] }
58
+ let(:params) { ['--id=1', '--device=pxe'] }
59
+ let(:success_boot) do
60
+ JSON.dump(:action => 'pxe', :result => true)
61
+ end
62
+
63
+ it 'boots the host' do
64
+ expected_result = success_result("The host is booting.\n")
65
+ api_expects(:hosts, :boot, 'Interface boots from specified device')
66
+ .with_params('id' => '1', 'device' => 'pxe')
67
+ .returns(success_boot)
68
+
69
+ result = run_cmd(cmd + params)
70
+ assert_cmd(expected_result, result)
71
+ end
72
+ end
73
+
74
+ describe 'host reset' do
75
+ let(:cmd) { ['host', 'reset'] }
76
+ let(:params) { ['--id=1'] }
77
+ let(:success_cycle) do
78
+ JSON.dump(:power => true)
79
+ end
80
+
81
+ it 'boots the host' do
82
+ expected_result = success_result("Host reset started.\n")
83
+ api_expects(:hosts, :power, 'Run power operation on interface.')
84
+ .with_params('id' => '1', 'power_action' => :cycle)
85
+ .returns(success_cycle)
86
+
87
+ result = run_cmd(cmd + params)
88
+ assert_cmd(expected_result, result)
89
+ end
90
+ end
91
+
56
92
  describe "host create" do
57
93
  let(:cmd) { ["host", "create"] }
58
94
  let(:minimal_params_without_hostgroup) { ['--location-id=1', '--organization-id=1', '--name=test'] }
@@ -87,6 +123,19 @@ describe "host create" do
87
123
  assert_cmd(expected_result, result)
88
124
  end
89
125
 
126
+ it "accepts host parameter attributes" do
127
+ params = ['--parameters', 'param1=value1']
128
+
129
+ api_expects(:hosts, :create, 'Create host with parameters') do |par|
130
+ par['host']['host_parameters_attributes'][0]['name'] == 'param1' &&
131
+ par['host']['host_parameters_attributes'][0]['value'] == 'value1'
132
+ end
133
+
134
+ expected_result = success_result("Host created.\n")
135
+ result = run_cmd(cmd + minimal_params + params)
136
+ assert_cmd(expected_result, result)
137
+ end
138
+
90
139
  it "sends empty hash for no interfaces" do
91
140
  # For some reason the Foreman replaces empty interfaces_attributes to nil,
92
141
  # which causes failure in nested attributes assignment in the host model
@@ -0,0 +1,131 @@
1
+ require_relative '../test_helper'
2
+ require 'hammer_cli_foreman/subnet'
3
+
4
+ module HammerCLIForeman
5
+ describe Subnet do
6
+ describe CreateCommand do
7
+ def subnet_params(additional_params = {})
8
+ params = {
9
+ :subnet => {
10
+ :name => 'net1'
11
+ }
12
+ }
13
+ params[:subnet].merge!(additional_params)
14
+ params
15
+ end
16
+
17
+ it 'allows minimal options' do
18
+ api_expects(:subnets, :create) do |par|
19
+ par['subnet']['name'] == 'net1'
20
+ end
21
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0))
22
+ end
23
+
24
+ it 'allows dhcp id' do
25
+ api_expects(:subnets, :create).with_params(subnet_params(:dhcp_id => '1'))
26
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --dhcp-id 1))
27
+ end
28
+
29
+ it 'allows dhcp name' do
30
+ api_expects_search(:smart_proxies, { :name => 'sp1' })
31
+ .returns(index_response([{'id' => 1}]))
32
+ api_expects(:subnets, :create).with_params(subnet_params(:dhcp_id => 1))
33
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --dhcp sp1))
34
+ end
35
+
36
+ it 'allows dns id' do
37
+ api_expects(:subnets, :create).with_params(subnet_params(:dns_id => '1'))
38
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --dns-id 1))
39
+ end
40
+
41
+ it 'allows dns name' do
42
+ api_expects_search(:smart_proxies, { :name => 'sp1' })
43
+ .returns(index_response([{'id' => 1}]))
44
+ api_expects(:subnets, :create).with_params(subnet_params(:dns_id => 1))
45
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --dns sp1))
46
+ end
47
+
48
+ it 'allows tftp id' do
49
+ api_expects(:subnets, :create).with_params(subnet_params(:tftp_id => '1'))
50
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --tftp-id 1))
51
+ end
52
+
53
+ it 'allows tftp name' do
54
+ api_expects_search(:smart_proxies, { :name => 'sp1' })
55
+ .returns(index_response([{'id' => 1}]))
56
+ api_expects(:subnets, :create).with_params(subnet_params(:tftp_id => 1))
57
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --tftp sp1))
58
+ end
59
+
60
+ it 'allows domain ids' do
61
+ api_expects(:subnets, :create).with_params(subnet_params(:domain_ids => ['1', '4']))
62
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --domain-ids 1,4))
63
+ end
64
+
65
+ it 'allows domain names' do
66
+ api_expects(:domains, :index) do |p|
67
+ p[:search] == "name = \"d1\" or name = \"d2\""
68
+ end.returns(index_response([{'id' => 1}, {'id' => 2}]))
69
+ api_expects(:subnets, :create).with_params(subnet_params(:domain_ids => [1, 2]))
70
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --domains d1,d2))
71
+ end
72
+
73
+ it 'allows location ids' do
74
+ api_expects(:subnets, :create).with_params(subnet_params(:location_ids => ['1', '4']))
75
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --location-ids 1,4))
76
+ end
77
+
78
+ it 'allows location names' do
79
+ api_expects(:locations, :index) do |p|
80
+ p[:search] == "name = \"loc1\" or name = \"loc2\""
81
+ end.returns(index_response([{'id' => 1}, {'id' => 2}]))
82
+ api_expects(:subnets, :create).with_params(subnet_params(:location_ids => [1, 2]))
83
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --locations loc1,loc2))
84
+ end
85
+
86
+ it 'allows organization ids' do
87
+ api_expects(:subnets, :create).with_params(subnet_params(:organization_ids => ['1', '4']))
88
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --organization-ids 1,4))
89
+ end
90
+
91
+ it 'allows organization names' do
92
+ api_expects(:organizations, :index) do |p|
93
+ p[:search] == "name = \"org1\" or name = \"org2\""
94
+ end.returns(index_response([{'id' => 1}, {'id' => 2}]))
95
+ api_expects(:subnets, :create).with_params(subnet_params(:organization_ids => [1, 2]))
96
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --organizations org1,org2))
97
+ end
98
+
99
+ it 'allows primary dns' do
100
+ api_expects(:subnets, :create).with_params(subnet_params(:dns_primary => '192.168.122.2'))
101
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --dns-primary 192.168.122.2))
102
+ end
103
+
104
+ it 'allows secondary dns' do
105
+ api_expects(:subnets, :create).with_params(subnet_params(:dns_secondary => '192.168.122.2'))
106
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --dns-secondary 192.168.122.2))
107
+ end
108
+
109
+ it 'allows ip address range FROM' do
110
+ api_expects(:subnets, :create).with_params(subnet_params(:from => '192.168.122.3'))
111
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --from 192.168.122.3))
112
+ end
113
+
114
+ it 'allows ip address range TO' do
115
+ api_expects(:subnets, :create).with_params(subnet_params(:to => '192.168.122.60'))
116
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --to 192.168.122.60))
117
+ end
118
+
119
+ it 'allows gateway' do
120
+ api_expects(:subnets, :create).with_params(subnet_params(:gateway => '192.168.122.1'))
121
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --gateway 192.168.122.1))
122
+ end
123
+
124
+ it 'allows network type' do
125
+ api_expects(:subnets, :create).with_params(subnet_params(:network_type => 'IPv4'))
126
+ run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --network-type IPv4))
127
+ end
128
+
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,130 @@
1
+ require_relative '../test_helper'
2
+ require 'hammer_cli_foreman/subnet'
3
+
4
+ module HammerCLIForeman
5
+ describe Subnet do
6
+ describe UpdateCommand do
7
+ def subnet_params(additional_params = {})
8
+ params = {
9
+ :id => '1',
10
+ :subnet => {}
11
+ }
12
+ params[:subnet].merge!(additional_params)
13
+ params
14
+ end
15
+
16
+ it 'allows minimal options' do
17
+ api_expects(:subnets, :update) do |par|
18
+ par['id'] == '1'
19
+ end
20
+ run_cmd(%w(subnet update --id 1))
21
+ end
22
+
23
+ it 'allows dhcp id' do
24
+ api_expects(:subnets, :update).with_params(subnet_params(:dhcp_id => '1'))
25
+ run_cmd(%w(subnet update --id 1 --dhcp-id 1))
26
+ end
27
+
28
+ it 'allows dhcp name' do
29
+ api_expects_search(:smart_proxies, { :name => 'sp1' })
30
+ .returns(index_response([{'id' => 1}]))
31
+ api_expects(:subnets, :update).with_params(subnet_params(:dhcp_id => 1))
32
+ run_cmd(%w(subnet update --id 1 --dhcp sp1))
33
+ end
34
+
35
+ it 'allows dns id' do
36
+ api_expects(:subnets, :update).with_params(subnet_params(:dns_id => '1'))
37
+ run_cmd(%w(subnet update --id 1 --dns-id 1))
38
+ end
39
+
40
+ it 'allows dns name' do
41
+ api_expects_search(:smart_proxies, { :name => 'sp1' })
42
+ .returns(index_response([{'id' => 1}]))
43
+ api_expects(:subnets, :update).with_params(subnet_params(:dns_id => 1))
44
+ run_cmd(%w(subnet update --id 1 --dns sp1))
45
+ end
46
+
47
+ it 'allows tftp id' do
48
+ api_expects(:subnets, :update).with_params(subnet_params(:tftp_id => '1'))
49
+ run_cmd(%w(subnet update --id 1 --tftp-id 1))
50
+ end
51
+
52
+ it 'allows tftp name' do
53
+ api_expects_search(:smart_proxies, { :name => 'sp1' })
54
+ .returns(index_response([{'id' => 1}]))
55
+ api_expects(:subnets, :update).with_params(subnet_params(:tftp_id => 1))
56
+ run_cmd(%w(subnet update --id 1 --tftp sp1))
57
+ end
58
+
59
+ it 'allows domain ids' do
60
+ api_expects(:subnets, :update).with_params(subnet_params(:domain_ids => ['1', '4']))
61
+ run_cmd(%w(subnet update --id 1 --domain-ids 1,4))
62
+ end
63
+
64
+ it 'allows domain names' do
65
+ api_expects(:domains, :index) do |p|
66
+ p[:search] == "name = \"d1\" or name = \"d2\""
67
+ end.returns(index_response([{'id' => 1}, {'id' => 2}]))
68
+ api_expects(:subnets, :update).with_params(subnet_params(:domain_ids => [1, 2]))
69
+ run_cmd(%w(subnet update --id 1 --domains d1,d2))
70
+ end
71
+
72
+ it 'allows location ids' do
73
+ api_expects(:subnets, :update).with_params(subnet_params(:location_ids => ['1', '4']))
74
+ run_cmd(%w(subnet update --id 1 --location-ids 1,4))
75
+ end
76
+
77
+ it 'allows location names' do
78
+ api_expects(:locations, :index) do |p|
79
+ p[:search] == "name = \"loc1\" or name = \"loc2\""
80
+ end.returns(index_response([{'id' => 1}, {'id' => 2}]))
81
+ api_expects(:subnets, :update).with_params(subnet_params(:location_ids => [1, 2]))
82
+ run_cmd(%w(subnet update --id 1 --locations loc1,loc2))
83
+ end
84
+
85
+ it 'allows organization ids' do
86
+ api_expects(:subnets, :update).with_params(subnet_params(:organization_ids => ['1', '4']))
87
+ run_cmd(%w(subnet update --id 1 --organization-ids 1,4))
88
+ end
89
+
90
+ it 'allows organization names' do
91
+ api_expects(:organizations, :index) do |p|
92
+ p[:search] == "name = \"org1\" or name = \"org2\""
93
+ end.returns(index_response([{'id' => 1}, {'id' => 2}]))
94
+ api_expects(:subnets, :update).with_params(subnet_params(:organization_ids => [1, 2]))
95
+ run_cmd(%w(subnet update --id 1 --organizations org1,org2))
96
+ end
97
+
98
+ it 'allows primary dns' do
99
+ api_expects(:subnets, :update).with_params(subnet_params(:dns_primary => '192.168.122.2'))
100
+ run_cmd(%w(subnet update --id 1 --dns-primary 192.168.122.2))
101
+ end
102
+
103
+ it 'allows secondary dns' do
104
+ api_expects(:subnets, :update).with_params(subnet_params(:dns_secondary => '192.168.122.2'))
105
+ run_cmd(%w(subnet update --id 1 --dns-secondary 192.168.122.2))
106
+ end
107
+
108
+ it 'allows ip address range FROM' do
109
+ api_expects(:subnets, :update).with_params(subnet_params(:from => '192.168.122.3'))
110
+ run_cmd(%w(subnet update --id 1 --from 192.168.122.3))
111
+ end
112
+
113
+ it 'allows ip address range TO' do
114
+ api_expects(:subnets, :update).with_params(subnet_params(:to => '192.168.122.60'))
115
+ run_cmd(%w(subnet update --id 1 --to 192.168.122.60))
116
+ end
117
+
118
+ it 'allows gateway' do
119
+ api_expects(:subnets, :update).with_params(subnet_params(:gateway => '192.168.122.1'))
120
+ run_cmd(%w(subnet update --id 1 --gateway 192.168.122.1))
121
+ end
122
+
123
+ it 'allows network type' do
124
+ api_expects(:subnets, :update).with_params(subnet_params(:network_type => 'IPv4'))
125
+ run_cmd(%w(subnet update --id 1 --network-type IPv4))
126
+ end
127
+
128
+ end
129
+ end
130
+ end
@@ -45,6 +45,10 @@ module ResourceMocks
45
45
  ResourceMocks.mock_action_call(:compute_resources, :available_networks, [])
46
46
  end
47
47
 
48
+ def self.compute_resources_available_clusters
49
+ ResourceMocks.mock_action_call(:compute_resources, :available_clusters, [])
50
+ end
51
+
48
52
  def self.organizations_index
49
53
  ResourceMocks.mock_action_call(:organizations, :index, {
50
54
  "results" => [
@@ -94,6 +94,28 @@ describe HammerCLIForeman::ComputeResource do
94
94
 
95
95
  end
96
96
 
97
+ context "AvailableClustersCommand" do
98
+ before do
99
+ ResourceMocks.compute_resources_available_clusters
100
+ end
101
+
102
+ let(:cmd) { HammerCLIForeman::ComputeResource::AvailableClustersCommand.new("", ctx) }
103
+
104
+ context "parameters" do
105
+ it_should_accept "id", ["--id=1"]
106
+ it_should_accept "name", ["--name=domain-c7"]
107
+ end
108
+
109
+ context "output" do
110
+ let(:expected_record_count) { count_records(cmd.resource.call(:available_clusters)) }
111
+
112
+ with_params ["--name=testcr"] do
113
+ it_should_print_n_records
114
+ it_should_print_columns ["Name", "Id"]
115
+ end
116
+ end
117
+ end
118
+
97
119
  context "AvailableNetworksCommand" do
98
120
  before do
99
121
  ResourceMocks.compute_resources_available_networks
@@ -23,7 +23,7 @@ describe HammerCLIForeman::Host do
23
23
  let(:expected_record_count) { count_records(cmd.resource.call(:index)) }
24
24
 
25
25
  it_should_print_n_records
26
- it_should_print_columns ["Id", "Name", "Operating System", "Host Group", "IP", "MAC"]
26
+ it_should_print_columns ["Id", "Name", "Operating System", "Host Group", "IP", "MAC", "Global Status"]
27
27
  end
28
28
 
29
29
  end
@@ -47,7 +47,7 @@ describe HammerCLIForeman::Host do
47
47
  it_should_print_columns ["Id", "Name", "Organization", "Location"]
48
48
  it_should_print_columns ["Host Group", "Compute Resource", "Compute Profile", "Puppet Environment"]
49
49
  it_should_print_columns ["Puppet CA Proxy", "Puppet Master Proxy", "Cert name"]
50
- it_should_print_columns ["Managed", "Installed at", "Last report"]
50
+ it_should_print_columns ["Managed", "Status", "Installed at", "Last report"]
51
51
  it_should_print_columns ["Network", "Network interfaces", "Operating system", "Parameters", "All parameters", "Additional info"]
52
52
  end
53
53
  end
@@ -1,9 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), '../test_helper')
2
2
 
3
+ describe HammerCLIForeman::Output::Formatters::StructuredReferenceFormatter do
3
4
 
4
- describe HammerCLIForeman::Output::Formatters::SingleReferenceFormatter do
5
-
6
- let(:formatter) { HammerCLIForeman::Output::Formatters::SingleReferenceFormatter.new }
5
+ let(:formatter) { HammerCLIForeman::Output::Formatters::StructuredReferenceFormatter.new }
7
6
  let(:reference) do
8
7
  {
9
8
  :server_id => 1,
@@ -17,30 +16,32 @@ describe HammerCLIForeman::Output::Formatters::SingleReferenceFormatter do
17
16
  end
18
17
  end
19
18
 
20
- context "with symbol keys" do
21
- it "formats name" do
22
- options = {:key => :server}
23
- formatter.format(reference, options).must_equal 'Server'
19
+ context 'with symbol keys' do
20
+ it 'formats name' do
21
+ options = {:display_field_key => :server_name}
22
+ formatter.format(reference, options).must_equal('Name' => "#{reference_str_keys['server_name']}")
24
23
  end
25
24
 
26
- it "formats id" do
27
- options = {:key => :server, :context => {:show_ids => true}}
28
- formatter.format(reference, options).must_equal 'Server (id: 1)'
25
+ it 'formats id' do
26
+ options = {:display_field_key => :server_name,
27
+ :details => {:structured_label => 'Id', :key => :server_id}}
28
+ formatter.format(reference, options)
29
+ .must_equal('Name' => "#{reference_str_keys['server_name']}", 'Id' => reference_str_keys['server_id'])
29
30
  end
30
31
  end
31
32
 
32
- context "with string keys" do
33
- it "formats name" do
34
- options = {:key => :server}
35
- formatter.format(reference_str_keys, options).must_equal 'Server'
33
+ context 'with string keys' do
34
+ it 'formats name' do
35
+ options = {:display_field_key => :server_name}
36
+ formatter.format(reference_str_keys, options).must_equal('Name' => "#{reference_str_keys['server_name']}")
36
37
  end
37
38
 
38
- it "formats id" do
39
- options = {:key => :server, :context => {:show_ids => true}}
40
- formatter.format(reference_str_keys, options).must_equal 'Server (id: 1)'
39
+ it 'formats id' do
40
+ options = {:display_field_key => :server_name,
41
+ :details => {:structured_label => 'Id', :key => :server_id}}
42
+ formatter.format(reference_str_keys, options).must_equal('Name' => "#{reference_str_keys['server_name']}", 'Id' => reference_str_keys['server_id'])
41
43
  end
42
44
  end
43
-
44
45
  end
45
46
 
46
47
  describe HammerCLIForeman::Output::Formatters::ReferenceFormatter do
@@ -57,94 +58,102 @@ describe HammerCLIForeman::Output::Formatters::ReferenceFormatter do
57
58
  }
58
59
  end
59
60
 
60
-
61
- it "recovers when the resource is missing" do
61
+ it 'recovers when the resource is missing' do
62
62
  formatter.format(nil).must_equal ''
63
63
  end
64
64
 
65
- context "with symbol keys" do
65
+ context 'with symbol keys' do
66
66
  let(:reference_sym_keys) do
67
67
  reference
68
68
  end
69
69
 
70
- it "formats name" do
71
- formatter.format(reference_sym_keys, {}).must_equal 'Server'
72
- end
73
-
74
- it "can override name key" do
75
- options = {:name_key => :another_name}
76
- formatter.format(reference_sym_keys, options).must_equal 'SERVER'
77
- end
78
-
79
- it "formats id" do
80
- options = {:context => {:show_ids => true}}
81
- formatter.format(reference_sym_keys, options).must_equal 'Server (id: 1)'
70
+ it 'formats name' do
71
+ formatter.format(reference_sym_keys, {}).must_equal("#{reference_sym_keys[:name]}")
82
72
  end
83
73
 
84
- it "can override id key" do
85
- options = {:id_key => :another_id, :context => {:show_ids => true}}
86
- formatter.format(reference_sym_keys, options).must_equal 'Server (id: 2)'
74
+ it 'can override name key' do
75
+ options = {:display_field_key => :another_name}
76
+ formatter.format(reference_sym_keys, options).must_equal("#{reference_sym_keys[:another_name]}")
87
77
  end
88
78
 
89
- it "formats details" do
90
- options = {:details => :url}
91
- formatter.format(reference_sym_keys, options).must_equal 'Server (URL)'
79
+ it 'formats id' do
80
+ options = {:details => {:key => :id, :label => 'Id'}, :context => {:show_ids => true}}
81
+ formatter.format(reference_sym_keys, options)
82
+ .must_equal("Server (Id: #{reference_sym_keys[:id]})")
92
83
  end
93
84
 
94
- it "formats multiple details" do
95
- options = {:details => [:url, :desc]}
96
- formatter.format(reference_sym_keys, options).must_equal 'Server (URL, Description)'
85
+ it 'formats details' do
86
+ options = { :details => { :label => _('url'), :key => :url } }
87
+ formatter.format(reference_sym_keys, options).must_equal("Server (url: #{reference_sym_keys[:url]})")
97
88
  end
98
89
 
99
- it "formats details and id" do
100
- options = {:context => {:show_ids => true}, :details => [:url, :desc]}
101
- formatter.format(reference_sym_keys, options).must_equal 'Server (URL, Description, id: 1)'
90
+ it 'formats multiple details' do
91
+ options = { :details => [{ :label => _('url'), :key => :url },
92
+ {:label => _('desc'), :key => :desc }]
93
+ }
94
+ formatter.format(reference_sym_keys, options)
95
+ .must_equal("Server (url: #{reference_sym_keys[:url]}, desc: #{reference_sym_keys[:desc]})")
102
96
  end
103
97
 
104
- it "handles empty string properly" do
105
- formatter.format("", {}).must_equal ""
98
+ it 'formats details and id' do
99
+ options = {:context => {:show_ids => true},
100
+ :details => [{ :label => _('url'), :key => :url },
101
+ {:label => _('desc'), :key => :desc },
102
+ {:label => _('Id'), :key => :id }]
103
+ }
104
+ formatter.format(reference_sym_keys, options)
105
+ .must_equal("Server (url: #{reference_sym_keys[:url]}, desc: #{reference_sym_keys[:desc]}, Id: #{reference_sym_keys[:id]})")
106
106
  end
107
107
  end
108
108
 
109
- context "with string keys" do
109
+ context 'with string keys' do
110
110
  let(:reference_str_keys) do
111
111
  reference.inject({}) do |new_ref, (key, value)|
112
112
  new_ref.update(key.to_s => value)
113
113
  end
114
114
  end
115
115
 
116
- it "formats name" do
117
- formatter.format(reference_str_keys, {}).must_equal 'Server'
116
+ it 'formats name' do
117
+ formatter.format(reference_str_keys, {}).must_equal("#{reference_str_keys['name']}")
118
118
  end
119
119
 
120
- it "can override name key" do
121
- options = {:name_key => :another_name}
122
- formatter.format(reference_str_keys, options).must_equal 'SERVER'
120
+ it 'can override name key' do
121
+ options = {:display_field_key => :another_name}
122
+ formatter.format(reference_str_keys, options).must_equal("#{reference_str_keys['another_name']}")
123
123
  end
124
124
 
125
- it "formats id" do
126
- options = {:context => {:show_ids => true}}
127
- formatter.format(reference_str_keys, options).must_equal 'Server (id: 1)'
125
+ it 'formats id when show_ids is true' do
126
+ options = {:details => {:label => 'Id', :key => :id, :id => 1}, :context => {:show_ids => true}}
127
+ formatter.format(reference_str_keys, options)
128
+ .must_equal("Server (Id: #{reference_str_keys['id']})")
128
129
  end
129
130
 
130
- it "can override id key" do
131
- options = {:id_key => :another_id, :context => {:show_ids => true}}
132
- formatter.format(reference_str_keys, options).must_equal 'Server (id: 2)'
131
+ it 'does not formats id when show_ids is false' do
132
+ options = {:details => {:label => 'Id', :key => :id, :id => 1}, :context => {:show_ids => false}}
133
+ formatter.format(reference_str_keys, options)
134
+ .must_equal("#{reference_str_keys['name']}")
133
135
  end
134
136
 
135
- it "formats details" do
136
- options = {:details => :url}
137
- formatter.format(reference_str_keys, options).must_equal 'Server (URL)'
137
+ it 'formats details' do
138
+ options = { :details => { :label => _('url'), :key => :url } }
139
+ formatter.format(reference_str_keys, options)
140
+ .must_equal("Server (url: #{reference_str_keys['url']})")
138
141
  end
139
142
 
140
- it "formats multiple details" do
141
- options = {:details => [:url, :desc]}
142
- formatter.format(reference_str_keys, options).must_equal 'Server (URL, Description)'
143
+ it 'formats multiple details' do
144
+ options = { :details => [{ :label => _('url'), :key => :url },
145
+ { :label => _('desc'), :key => :desc }] }
146
+ formatter.format(reference_str_keys, options)
147
+ .must_equal("Server (url: #{reference_str_keys['url']}, desc: #{reference_str_keys['desc']})")
143
148
  end
144
149
 
145
- it "formats details and id" do
146
- options = {:context => {:show_ids => true}, :details => [:url, :desc]}
147
- formatter.format(reference_str_keys, options).must_equal 'Server (URL, Description, id: 1)'
150
+ it 'formats details and id' do
151
+ options = {:context => { :show_ids => true },
152
+ :details => [{ :label => _('url'), :key => :url },
153
+ { :label => _('desc'), :key => :desc },
154
+ { :label => _('Id'), :key => :id }] }
155
+ formatter.format(reference_str_keys, options)
156
+ .must_equal("Server (url: #{reference_str_keys['url']}, desc: #{reference_str_keys['desc']}, Id: #{reference_str_keys['id']})")
148
157
  end
149
158
  end
150
159