hammer_cli_foreman 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +12 -1
- data/doc/configuration.md +13 -0
- data/lib/hammer_cli_foreman.rb +3 -0
- data/lib/hammer_cli_foreman/architecture.rb +9 -9
- data/lib/hammer_cli_foreman/associating_commands.rb +57 -34
- data/lib/hammer_cli_foreman/commands.rb +188 -101
- data/lib/hammer_cli_foreman/common_parameter.rb +7 -10
- data/lib/hammer_cli_foreman/compute_resource.rb +8 -11
- data/lib/hammer_cli_foreman/domain.rb +14 -40
- data/lib/hammer_cli_foreman/environment.rb +10 -15
- data/lib/hammer_cli_foreman/exceptions.rb +4 -0
- data/lib/hammer_cli_foreman/fact.rb +5 -5
- data/lib/hammer_cli_foreman/host.rb +76 -132
- data/lib/hammer_cli_foreman/hostgroup.rb +26 -61
- data/lib/hammer_cli_foreman/id_resolver.rb +163 -0
- data/lib/hammer_cli_foreman/image.rb +14 -50
- data/lib/hammer_cli_foreman/location.rb +35 -17
- data/lib/hammer_cli_foreman/media.rb +9 -16
- data/lib/hammer_cli_foreman/model.rb +6 -8
- data/lib/hammer_cli_foreman/operating_system.rb +129 -63
- data/lib/hammer_cli_foreman/organization.rb +36 -16
- data/lib/hammer_cli_foreman/output/fields.rb +10 -2
- data/lib/hammer_cli_foreman/output/formatters.rb +44 -18
- data/lib/hammer_cli_foreman/parameter.rb +45 -41
- data/lib/hammer_cli_foreman/partition_table.rb +9 -12
- data/lib/hammer_cli_foreman/puppet_class.rb +14 -14
- data/lib/hammer_cli_foreman/references.rb +122 -0
- data/lib/hammer_cli_foreman/report.rb +3 -6
- data/lib/hammer_cli_foreman/searchables_option_builder.rb +99 -0
- data/lib/hammer_cli_foreman/smart_class_parameter.rb +17 -13
- data/lib/hammer_cli_foreman/smart_proxy.rb +18 -28
- data/lib/hammer_cli_foreman/subnet.rb +12 -13
- data/lib/hammer_cli_foreman/template.rb +10 -19
- data/lib/hammer_cli_foreman/user.rb +9 -28
- data/lib/hammer_cli_foreman/version.rb +1 -1
- data/locale/hammer-cli-foreman.pot +828 -817
- data/test/unit/apipie_resource_mock.rb +33 -11
- data/test/unit/architecture_test.rb +7 -10
- data/test/unit/commands_test.rb +8 -9
- data/test/unit/common_parameter_test.rb +6 -8
- data/test/unit/compute_resource_test.rb +9 -12
- data/test/unit/data/1.5/foreman_api.json +14130 -0
- data/test/unit/domain_test.rb +19 -22
- data/test/unit/environment_test.rb +9 -11
- data/test/unit/fact_test.rb +5 -6
- data/test/unit/helpers/command.rb +115 -59
- data/test/unit/helpers/fake_searchables.rb +19 -0
- data/test/unit/host_test.rb +44 -33
- data/test/unit/hostgroup_test.rb +19 -26
- data/test/unit/id_resolver_test.rb +225 -0
- data/test/unit/image_test.rb +16 -18
- data/test/unit/location_test.rb +8 -10
- data/test/unit/media_test.rb +11 -13
- data/test/unit/model_test.rb +8 -10
- data/test/unit/operating_system_test.rb +23 -23
- data/test/unit/organization_test.rb +9 -10
- data/test/unit/output/formatters_test.rb +133 -20
- data/test/unit/partition_table_test.rb +12 -9
- data/test/unit/puppet_class_test.rb +3 -7
- data/test/unit/report_test.rb +3 -7
- data/test/unit/searchables_option_builder_test.rb +172 -0
- data/test/unit/smart_class_parameter_test.rb +5 -7
- data/test/unit/smart_proxy_test.rb +11 -12
- data/test/unit/subnet_test.rb +15 -16
- data/test/unit/template_test.rb +15 -12
- data/test/unit/test_helper.rb +1 -1
- data/test/unit/user_test.rb +9 -12
- metadata +536 -509
data/test/unit/media_test.rb
CHANGED
@@ -3,11 +3,7 @@ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
|
|
3
3
|
|
4
4
|
describe HammerCLIForeman::Medium do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
before :each do
|
9
|
-
cmd.stubs(:name_to_id).returns(1)
|
10
|
-
end
|
6
|
+
include CommandTestHelper
|
11
7
|
|
12
8
|
context "ListCommand" do
|
13
9
|
|
@@ -36,7 +32,7 @@ describe HammerCLIForeman::Medium do
|
|
36
32
|
context "parameters" do
|
37
33
|
it_should_accept "id", ["--id=1"]
|
38
34
|
it_should_accept "name", ["--name=medium_x"]
|
39
|
-
it_should_fail_with "no arguments"
|
35
|
+
# it_should_fail_with "no arguments" # TODO: temporarily disabled, parameters are checked in the id resolver
|
40
36
|
end
|
41
37
|
|
42
38
|
context "output" do
|
@@ -46,7 +42,7 @@ describe HammerCLIForeman::Medium do
|
|
46
42
|
it_should_print_column "Id"
|
47
43
|
it_should_print_column "Path"
|
48
44
|
it_should_print_column "OS Family"
|
49
|
-
it_should_print_column "
|
45
|
+
it_should_print_column "Operating systems"
|
50
46
|
it_should_print_column "Created at"
|
51
47
|
it_should_print_column "Updated at"
|
52
48
|
end
|
@@ -59,8 +55,9 @@ describe HammerCLIForeman::Medium do
|
|
59
55
|
|
60
56
|
context "parameters" do
|
61
57
|
it_should_accept "name, path, os ids", ["--name=media", "--path=http://some.path/abc/$major/Fedora/$arch/", "--operatingsystem-ids=1,2"]
|
62
|
-
it_should_fail_with "name missing", ["--path=http://some.path/abc/$major/Fedora/$arch/"]
|
63
|
-
it_should_fail_with "path missing", ["--name=media"]
|
58
|
+
# it_should_fail_with "name missing", ["--path=http://some.path/abc/$major/Fedora/$arch/"]
|
59
|
+
# it_should_fail_with "path missing", ["--name=media"]
|
60
|
+
# TODO: temporarily disabled, parameters are checked in the api
|
64
61
|
end
|
65
62
|
|
66
63
|
with_params ["--name=medium_x", "--path=http://some.path/", "--operatingsystem-ids=1,2"] do
|
@@ -75,7 +72,7 @@ describe HammerCLIForeman::Medium do
|
|
75
72
|
context "parameters" do
|
76
73
|
it_should_accept "name", ["--name=media"]
|
77
74
|
it_should_accept "id", ["--id=1"]
|
78
|
-
it_should_fail_with "name or id missing", []
|
75
|
+
# it_should_fail_with "name or id missing", [] # TODO: temporarily disabled, parameters are checked in the id resolver
|
79
76
|
end
|
80
77
|
end
|
81
78
|
|
@@ -87,12 +84,13 @@ describe HammerCLIForeman::Medium do
|
|
87
84
|
it_should_accept "name", ["--name=medium"]
|
88
85
|
it_should_accept "id", ["--id=1"]
|
89
86
|
it_should_accept "os ids", ["--id=1", "--operatingsystem-ids=1,2"]
|
90
|
-
it_should_fail_with "no params", []
|
91
|
-
it_should_fail_with "name or id missing", ["--new-name=medium_x", "--path=http://some.path/"]
|
87
|
+
# it_should_fail_with "no params", []
|
88
|
+
# it_should_fail_with "name or id missing", ["--new-name=medium_x", "--path=http://some.path/"]
|
89
|
+
# TODO: temporarily disabled, parameters are checked in the id resolver
|
92
90
|
end
|
93
91
|
|
94
92
|
with_params ["--id=1", "--new-name=medium_x", "--path=http://some.path/", "--operatingsystem-ids=1,2"] do
|
95
|
-
it_should_call_action :update, {'id' => '1', 'medium' => {'name' => 'medium_x', 'path' => 'http://some.path/', 'operatingsystem_ids' => ['1', '2']}}
|
93
|
+
it_should_call_action :update, {'id' => '1', 'name' => 'medium_x', 'medium' => {'name' => 'medium_x', 'path' => 'http://some.path/', 'operatingsystem_ids' => ['1', '2']}}
|
96
94
|
end
|
97
95
|
|
98
96
|
end
|
data/test/unit/model_test.rb
CHANGED
@@ -4,11 +4,7 @@ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
|
|
4
4
|
|
5
5
|
describe HammerCLIForeman::Model do
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
before :each do
|
10
|
-
cmd.stubs(:name_to_id).returns(1)
|
11
|
-
end
|
7
|
+
include CommandTestHelper
|
12
8
|
|
13
9
|
context "ListCommand" do
|
14
10
|
|
@@ -38,7 +34,7 @@ describe HammerCLIForeman::Model do
|
|
38
34
|
context "parameters" do
|
39
35
|
it_should_accept "id", ["--id=1"]
|
40
36
|
it_should_accept "name", ["--name=model"]
|
41
|
-
it_should_fail_with "no arguments"
|
37
|
+
# it_should_fail_with "no arguments" # TODO: temporarily disabled, parameters are checked in the id resolver
|
42
38
|
end
|
43
39
|
|
44
40
|
context "output" do
|
@@ -63,7 +59,8 @@ describe HammerCLIForeman::Model do
|
|
63
59
|
|
64
60
|
context "parameters" do
|
65
61
|
it_should_accept "name", ["--name=model", "--info=description", "--vendor-class=class", "--hardware-model=model"]
|
66
|
-
it_should_fail_with "name missing", ["--info=description", "--vendor-class=class", "--hardware-model=model"]
|
62
|
+
# it_should_fail_with "name missing", ["--info=description", "--vendor-class=class", "--hardware-model=model"]
|
63
|
+
# TODO: temporarily disabled, parameters are checked in the api
|
67
64
|
end
|
68
65
|
|
69
66
|
end
|
@@ -76,7 +73,7 @@ describe HammerCLIForeman::Model do
|
|
76
73
|
context "parameters" do
|
77
74
|
it_should_accept "name", ["--name=model"]
|
78
75
|
it_should_accept "id", ["--id=1"]
|
79
|
-
it_should_fail_with "name or id missing", []
|
76
|
+
# it_should_fail_with "name or id missing", [] # TODO: temporarily disabled, parameters are checked in the id resolver
|
80
77
|
end
|
81
78
|
|
82
79
|
end
|
@@ -89,8 +86,9 @@ describe HammerCLIForeman::Model do
|
|
89
86
|
context "parameters" do
|
90
87
|
it_should_accept "name", ["--name=model", "--new-name=model2", "--info=description", "--vendor-class=class", "--hardware-model=model"]
|
91
88
|
it_should_accept "id", ["--id=1", "--new-name=model2", "--info=description", "--vendor-class=class", "--hardware-model=model"]
|
92
|
-
it_should_fail_with "no params", []
|
93
|
-
it_should_fail_with "name or id missing", ["--new-name=model2", "--info=description", "--vendor-class=class", "--hardware-model=model"]
|
89
|
+
# it_should_fail_with "no params", []
|
90
|
+
# it_should_fail_with "name or id missing", ["--new-name=model2", "--info=description", "--vendor-class=class", "--hardware-model=model"]
|
91
|
+
# TODO: temporarily disabled, parameters are checked in the id resolver
|
94
92
|
end
|
95
93
|
|
96
94
|
end
|
@@ -4,11 +4,7 @@ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
|
|
4
4
|
|
5
5
|
describe HammerCLIForeman::OperatingSystem do
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
before :each do
|
10
|
-
cmd.stubs(:name_to_id).returns(1)
|
11
|
-
end
|
7
|
+
include CommandTestHelper
|
12
8
|
|
13
9
|
context "ListCommand" do
|
14
10
|
|
@@ -27,7 +23,7 @@ describe HammerCLIForeman::OperatingSystem do
|
|
27
23
|
let(:expected_record_count) { cmd.resource.call(:index).length }
|
28
24
|
|
29
25
|
it_should_print_n_records
|
30
|
-
it_should_print_column "
|
26
|
+
it_should_print_column "Full name"
|
31
27
|
it_should_print_column "Id"
|
32
28
|
it_should_print_column "Release name"
|
33
29
|
it_should_print_column "Family"
|
@@ -40,13 +36,9 @@ describe HammerCLIForeman::OperatingSystem do
|
|
40
36
|
|
41
37
|
let(:cmd) { HammerCLIForeman::OperatingSystem::InfoCommand.new("", ctx) }
|
42
38
|
|
43
|
-
before :each do
|
44
|
-
HammerCLIForeman::Parameter.stubs(:get_parameters).returns([])
|
45
|
-
end
|
46
|
-
|
47
39
|
context "parameters" do
|
48
40
|
it_should_accept "id", ["--id=1"]
|
49
|
-
it_should_fail_with "no arguments"
|
41
|
+
# it_should_fail_with "no arguments" # TODO: temporarily disabled, parameters are checked in the id resolver
|
50
42
|
end
|
51
43
|
|
52
44
|
context "output" do
|
@@ -54,12 +46,15 @@ describe HammerCLIForeman::OperatingSystem do
|
|
54
46
|
it_should_print_n_records 1
|
55
47
|
it_should_print_column "Name"
|
56
48
|
it_should_print_column "Id"
|
49
|
+
it_should_print_column "Major version"
|
50
|
+
it_should_print_column "Minor version"
|
57
51
|
it_should_print_column "Release name"
|
58
52
|
it_should_print_column "Family"
|
59
53
|
it_should_print_column "Installation media"
|
60
54
|
it_should_print_column "Architectures"
|
61
55
|
it_should_print_column "Partition tables"
|
62
|
-
it_should_print_column "
|
56
|
+
it_should_print_column "Templates"
|
57
|
+
it_should_print_column "Default templates"
|
63
58
|
it_should_print_column "Parameters"
|
64
59
|
end
|
65
60
|
end
|
@@ -73,7 +68,8 @@ describe HammerCLIForeman::OperatingSystem do
|
|
73
68
|
|
74
69
|
context "parameters" do
|
75
70
|
it_should_accept "name, major, minor, family, release name", ["--name=media", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
|
76
|
-
it_should_fail_with "name missing", ["--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
|
71
|
+
# it_should_fail_with "name missing", ["--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
|
72
|
+
# TODO: temporarily disabled, parameters are checked in the api
|
77
73
|
end
|
78
74
|
|
79
75
|
with_params ["--name=os", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"] do
|
@@ -88,7 +84,8 @@ describe HammerCLIForeman::OperatingSystem do
|
|
88
84
|
|
89
85
|
context "parameters" do
|
90
86
|
it_should_accept "id", ["--id=1"]
|
91
|
-
it_should_fail_with "name or id missing", []
|
87
|
+
# it_should_fail_with "name or id missing", [] # TODO: temporarily disabled, parameters are checked in the id resolver
|
88
|
+
# TODO: temporarily disabled, parameters are checked in the id resolver
|
92
89
|
end
|
93
90
|
|
94
91
|
end
|
@@ -101,8 +98,9 @@ describe HammerCLIForeman::OperatingSystem do
|
|
101
98
|
context "parameters" do
|
102
99
|
it_should_accept "id", ["--id=1"]
|
103
100
|
it_should_accept "name, major, minor, family, release name", ["--id=83", "--name=os", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
|
104
|
-
it_should_fail_with "no params", []
|
105
|
-
it_should_fail_with "label or id missing", ["--name=os", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
|
101
|
+
# it_should_fail_with "no params", []
|
102
|
+
# it_should_fail_with "label or id missing", ["--name=os", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
|
103
|
+
# TODO: temporarily disabled, parameters are checked in the id resolver
|
106
104
|
end
|
107
105
|
|
108
106
|
with_params ["--id=83", "--name=os", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"] do
|
@@ -121,10 +119,11 @@ describe HammerCLIForeman::OperatingSystem do
|
|
121
119
|
let(:cmd) { HammerCLIForeman::OperatingSystem::SetParameterCommand.new("", ctx) }
|
122
120
|
|
123
121
|
context "parameters" do
|
124
|
-
it_should_accept "name, value and os id", ["--name=domain", "--value=val", "--
|
125
|
-
it_should_fail_with "name missing", ["--value=val", "--
|
126
|
-
it_should_fail_with "value missing", ["--name=name", "--
|
127
|
-
it_should_fail_with "os id missing", ["--name=name", "--value=val"]
|
122
|
+
it_should_accept "name, value and os id", ["--name=domain", "--value=val", "--operatingsystem-id=id"]
|
123
|
+
# it_should_fail_with "name missing", ["--value=val", "--operatingsystem-id=id"]
|
124
|
+
# it_should_fail_with "value missing", ["--name=name", "--operatingsystem-id=id"]
|
125
|
+
# it_should_fail_with "os id missing", ["--name=name", "--value=val"]
|
126
|
+
# TODO: temporarily disabled, parameters are checked in the id resolver
|
128
127
|
end
|
129
128
|
|
130
129
|
end
|
@@ -135,9 +134,10 @@ describe HammerCLIForeman::OperatingSystem do
|
|
135
134
|
let(:cmd) { HammerCLIForeman::OperatingSystem::DeleteParameterCommand.new("", ctx) }
|
136
135
|
|
137
136
|
context "parameters" do
|
138
|
-
it_should_accept "name and os id", ["--name=domain", "--
|
139
|
-
it_should_fail_with "name missing", ["--
|
140
|
-
it_should_fail_with "os id missing", ["--name=name"]
|
137
|
+
it_should_accept "name and os id", ["--name=domain", "--operatingsystem-id=id"]
|
138
|
+
# it_should_fail_with "name missing", ["--operatingsystem-id=id"]
|
139
|
+
# it_should_fail_with "os id missing", ["--name=name"]
|
140
|
+
# TODO: temporarily disabled, parameters are checked in the id resolver
|
141
141
|
end
|
142
142
|
|
143
143
|
end
|
@@ -5,13 +5,9 @@ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
|
|
5
5
|
|
6
6
|
describe HammerCLIForeman::Organization do
|
7
7
|
|
8
|
-
|
8
|
+
include CommandTestHelper
|
9
9
|
extend ResourceDisabled
|
10
10
|
|
11
|
-
before :each do
|
12
|
-
cmd.stubs(:name_to_id).returns(1)
|
13
|
-
end
|
14
|
-
|
15
11
|
context "ListCommand" do
|
16
12
|
|
17
13
|
before :each do
|
@@ -48,7 +44,7 @@ describe HammerCLIForeman::Organization do
|
|
48
44
|
context "parameters" do
|
49
45
|
it_should_accept "id", ["--id=1"]
|
50
46
|
it_should_accept "name", ["--name=arch"]
|
51
|
-
it_should_fail_with "no arguments"
|
47
|
+
# it_should_fail_with "no arguments" # TODO: temporarily disabled, parameters are checked in the id resolver
|
52
48
|
end
|
53
49
|
|
54
50
|
context "output" do
|
@@ -73,7 +69,8 @@ describe HammerCLIForeman::Organization do
|
|
73
69
|
|
74
70
|
context "parameters" do
|
75
71
|
it_should_accept "name", ["--name=org"]
|
76
|
-
it_should_fail_with "name missing", []
|
72
|
+
# it_should_fail_with "name missing", []
|
73
|
+
# TODO: temporarily disabled, parameters are checked in the api
|
77
74
|
end
|
78
75
|
|
79
76
|
with_params ["--name=org"] do
|
@@ -89,7 +86,9 @@ describe HammerCLIForeman::Organization do
|
|
89
86
|
context "parameters" do
|
90
87
|
it_should_accept "name", ["--name=org"]
|
91
88
|
it_should_accept "id", ["--id=1"]
|
92
|
-
|
89
|
+
|
90
|
+
# it_should_fail_with "name or id missing", []
|
91
|
+
# TODO: temporarily disabled, parameters are checked in the id resolver
|
93
92
|
end
|
94
93
|
|
95
94
|
with_params ["--id=1"] do
|
@@ -105,8 +104,8 @@ describe HammerCLIForeman::Organization do
|
|
105
104
|
context "parameters" do
|
106
105
|
it_should_accept "name", ["--name=org", "--new-name=org2"]
|
107
106
|
it_should_accept "id", ["--id=1", "--new-name=org2"]
|
108
|
-
it_should_fail_with "no params", []
|
109
|
-
it_should_fail_with "name or id missing", ["--new-name=org2"]
|
107
|
+
# it_should_fail_with "no params", [] # TODO: temporarily disabled, parameters are checked in the id resolver
|
108
|
+
# it_should_fail_with "name or id missing", ["--new-name=org2"] # TODO: temporarily disabled, parameters are checked in the id resolver
|
110
109
|
end
|
111
110
|
|
112
111
|
with_params ["--id=1"] do
|
@@ -1,34 +1,147 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '../test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
|
4
|
+
describe HammerCLIForeman::Output::Formatters::SingleReferenceFormatter do
|
5
|
+
|
6
|
+
let(:formatter) { HammerCLIForeman::Output::Formatters::SingleReferenceFormatter.new }
|
7
|
+
let(:reference) do
|
8
|
+
{
|
9
|
+
:server_id => 1,
|
10
|
+
:server_name => 'Server',
|
11
|
+
}
|
7
12
|
end
|
8
|
-
|
9
|
-
|
10
|
-
|
13
|
+
|
14
|
+
let(:reference_str_keys) do
|
15
|
+
reference.inject({}) do |new_ref, (key, value)|
|
16
|
+
new_ref.update(key.to_s => value)
|
17
|
+
end
|
11
18
|
end
|
12
19
|
|
13
|
-
|
14
|
-
|
15
|
-
|
20
|
+
context "with symbol keys" do
|
21
|
+
it "formats name" do
|
22
|
+
options = {:key => :server}
|
23
|
+
formatter.format(reference, options).must_equal 'Server'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "formats id" do
|
27
|
+
options = {:key => :server, :context => {:show_ids => true}}
|
28
|
+
formatter.format(reference, options).must_equal 'Server (id: 1)'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
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'
|
36
|
+
end
|
37
|
+
|
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)'
|
41
|
+
end
|
16
42
|
end
|
43
|
+
|
17
44
|
end
|
18
45
|
|
19
|
-
describe HammerCLIForeman::Output::Formatters::
|
20
|
-
|
21
|
-
|
22
|
-
|
46
|
+
describe HammerCLIForeman::Output::Formatters::ReferenceFormatter do
|
47
|
+
|
48
|
+
let(:formatter) { HammerCLIForeman::Output::Formatters::ReferenceFormatter.new }
|
49
|
+
let(:reference) do
|
50
|
+
{
|
51
|
+
:id => 1,
|
52
|
+
:another_id => 2,
|
53
|
+
:name => 'Server',
|
54
|
+
:another_name => 'SERVER',
|
55
|
+
:url => "URL",
|
56
|
+
:desc => "Description"
|
57
|
+
}
|
23
58
|
end
|
24
59
|
|
25
|
-
|
26
|
-
|
27
|
-
formatter.format(
|
60
|
+
|
61
|
+
it "recovers when the resource is missing" do
|
62
|
+
formatter.format(nil).must_equal ''
|
28
63
|
end
|
29
64
|
|
30
|
-
|
31
|
-
|
32
|
-
|
65
|
+
context "with symbol keys" do
|
66
|
+
let(:reference_sym_keys) do
|
67
|
+
reference
|
68
|
+
end
|
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)'
|
82
|
+
end
|
83
|
+
|
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)'
|
87
|
+
end
|
88
|
+
|
89
|
+
it "formats details" do
|
90
|
+
options = {:details => :url}
|
91
|
+
formatter.format(reference_sym_keys, options).must_equal 'Server (URL)'
|
92
|
+
end
|
93
|
+
|
94
|
+
it "formats multiple details" do
|
95
|
+
options = {:details => [:url, :desc]}
|
96
|
+
formatter.format(reference_sym_keys, options).must_equal 'Server (URL, Description)'
|
97
|
+
end
|
98
|
+
|
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)'
|
102
|
+
end
|
33
103
|
end
|
104
|
+
|
105
|
+
context "with string keys" do
|
106
|
+
let(:reference_str_keys) do
|
107
|
+
reference.inject({}) do |new_ref, (key, value)|
|
108
|
+
new_ref.update(key.to_s => value)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it "formats name" do
|
113
|
+
formatter.format(reference_str_keys, {}).must_equal 'Server'
|
114
|
+
end
|
115
|
+
|
116
|
+
it "can override name key" do
|
117
|
+
options = {:name_key => :another_name}
|
118
|
+
formatter.format(reference_str_keys, options).must_equal 'SERVER'
|
119
|
+
end
|
120
|
+
|
121
|
+
it "formats id" do
|
122
|
+
options = {:context => {:show_ids => true}}
|
123
|
+
formatter.format(reference_str_keys, options).must_equal 'Server (id: 1)'
|
124
|
+
end
|
125
|
+
|
126
|
+
it "can override id key" do
|
127
|
+
options = {:id_key => :another_id, :context => {:show_ids => true}}
|
128
|
+
formatter.format(reference_str_keys, options).must_equal 'Server (id: 2)'
|
129
|
+
end
|
130
|
+
|
131
|
+
it "formats details" do
|
132
|
+
options = {:details => :url}
|
133
|
+
formatter.format(reference_str_keys, options).must_equal 'Server (URL)'
|
134
|
+
end
|
135
|
+
|
136
|
+
it "formats multiple details" do
|
137
|
+
options = {:details => [:url, :desc]}
|
138
|
+
formatter.format(reference_str_keys, options).must_equal 'Server (URL, Description)'
|
139
|
+
end
|
140
|
+
|
141
|
+
it "formats details and id" do
|
142
|
+
options = {:context => {:show_ids => true}, :details => [:url, :desc]}
|
143
|
+
formatter.format(reference_str_keys, options).must_equal 'Server (URL, Description, id: 1)'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
34
147
|
end
|