opensrs 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,228 +0,0 @@
1
- require 'spec_helper'
2
- require 'date'
3
-
4
- describe OpenSRS::XmlProcessor::Nokogiri do
5
- describe ".build" do
6
- it "should create XML for a nested hash" do
7
- attributes = {:foo => {:bar => 'baz'}}
8
- xml = OpenSRS::XmlProcessor::Nokogiri.build(attributes)
9
- xml.should eq %{<?xml version=\"1.0\"?>\n<OPS_envelope>\n <header>\n <version>0.9</version>\n </header>\n <body>\n <data_block>\n <dt_assoc>\n <item key=\"foo\">\n <dt_assoc>\n <item key=\"bar\">baz</item>\n </dt_assoc>\n </item>\n </dt_assoc>\n </data_block>\n </body>\n</OPS_envelope>\n}
10
- end
11
- end
12
-
13
- describe '.encode_data' do
14
-
15
- before(:each) do
16
- @builder = ::Nokogiri::XML::Builder.new
17
- @doc = @builder.doc
18
- end
19
-
20
- context "on a 3 element array" do
21
- before(:each) do
22
- @e = OpenSRS::XmlProcessor::Nokogiri.encode_data([1,2,3], @doc)
23
- end
24
-
25
- it { @e.should be_an_instance_of(::Nokogiri::XML::Element) }
26
- it { @e.name.should eql('dt_array') }
27
-
28
- it { @e.should have(3).children }
29
- it { @e.children[0].name.should eql("item") }
30
- it { @e.children[1].name.should eql("item") }
31
- it { @e.children[2].name.should eql("item") }
32
-
33
- it { @e.children[0].attributes["key"].value.should eql("0") }
34
- it { @e.children[1].attributes["key"].value.should eql("1") }
35
- it { @e.children[2].attributes["key"].value.should eql("2") }
36
- end
37
-
38
- context "on a hash" do
39
- before(:each) do
40
- @e = OpenSRS::XmlProcessor::Nokogiri.encode_data({:name => "kitteh"}, @doc)
41
- end
42
-
43
- it { @e.should be_an_instance_of(::Nokogiri::XML::Element) }
44
- it { @e.name.should eql('dt_assoc') }
45
-
46
- it { @e.should have(1).children }
47
- it { @e.children[0].name.should eql('item') }
48
- it { @e.children[0].attributes["key"].value.should eql('name') }
49
- end
50
-
51
- context "on a nested hash" do
52
- before(:each) do
53
- @e = OpenSRS::XmlProcessor::Nokogiri.encode_data({:suggestion => {:maximum => "10"}}, @doc)
54
- @suggestion = @e.children[0]
55
- @dt_assoc = @suggestion.children[0]
56
- end
57
-
58
- it { @e.should be_an_instance_of(::Nokogiri::XML::Element) }
59
- it { @e.name.should == 'dt_assoc' }
60
-
61
- context "<item> child" do
62
- it { @e.should have(1).children }
63
- it { @suggestion.name.should eql('item') }
64
- it { @suggestion.attributes["key"].value.should eql('suggestion') }
65
- end
66
-
67
- context "suggesion children" do
68
- it { @suggestion.should have(1).children }
69
- it { @dt_assoc.name.should eql('dt_assoc') }
70
- end
71
-
72
- context "dt_assoc children" do
73
- before(:each) do
74
- @maximum = @dt_assoc.children[0]
75
- end
76
- it { @dt_assoc.should have(1).children }
77
- it { @maximum.name.should eql('item') }
78
- it { @maximum.attributes["key"].value.should eql('maximum') }
79
- end
80
- end
81
-
82
- context "produces a scalar" do
83
- it { OpenSRS::XmlProcessor::Nokogiri.encode_data("cheezburger").to_s.should eql("cheezburger") }
84
- it { OpenSRS::XmlProcessor::Nokogiri.encode_data("<smile>").to_s.should eql("<smile>") }
85
-
86
- it { OpenSRS::XmlProcessor::Nokogiri.encode_data(12345).to_s.should eql("12345") }
87
- it { OpenSRS::XmlProcessor::Nokogiri.encode_data(Date.parse("2010/02/12")).to_s.should eql("2010-02-12") }
88
- it { OpenSRS::XmlProcessor::Nokogiri.encode_data(:name).to_s.should eql("name") }
89
- it { OpenSRS::XmlProcessor::Nokogiri.encode_data(true).to_s.should eql("true") }
90
- it { OpenSRS::XmlProcessor::Nokogiri.encode_data(false).to_s.should eql("false") }
91
- end
92
- end
93
-
94
- describe '.parse' do
95
-
96
- context "when scaler values" do
97
- before(:each) do
98
- xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
99
- <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
100
- <OPS_envelope>
101
- <header>
102
- <version>1.0</version>
103
- </header>
104
- <body>
105
- <data_block>
106
- <dt_scalar>Tom Jones</dt_scalar>
107
- </data_block>
108
- </body>
109
- </OPS_envelope>}
110
- @response = OpenSRS::XmlProcessor::Nokogiri.parse(xml)
111
- end
112
-
113
- it { @response.should eql("Tom Jones") }
114
- end
115
-
116
- context "when associative arrays with arrays of values" do
117
- before(:each) do
118
- xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
119
- <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
120
- <OPS_envelope>
121
- <header>
122
- <version>1.0</version>
123
- </header>
124
- <body>
125
- <data_block>
126
- <dt_assoc>
127
- <item key='domain_list'>
128
- <dt_array>
129
- <item key='0'>ns1.example.com</item>
130
- <item key='1'>ns2.example.com</item>
131
- <item key='2'>ns3.example.com</item>
132
- </dt_array>
133
- </item>
134
- </dt_assoc>
135
- </data_block>
136
- </body>
137
- </OPS_envelope>}
138
-
139
- @response = OpenSRS::XmlProcessor::Nokogiri.parse(xml)
140
- end
141
-
142
- it { @response["domain_list"].class.should eql(Array) }
143
- it { @response["domain_list"][0].should eql("ns1.example.com") }
144
- it { @response["domain_list"][1].should eql("ns2.example.com") }
145
- it { @response["domain_list"][2].should eql("ns3.example.com") }
146
- end
147
-
148
- context "when associative arrays containing other associative arrays" do
149
- before(:each) do
150
- xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
151
- <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
152
- <OPS_envelope>
153
- <header>
154
- <version>1.0</version>
155
- </header>
156
- <body>
157
- <data_block>
158
- <dt_assoc>
159
- <item key="contact_set">
160
- <dt_assoc>
161
- <item key='owner'>
162
- <dt_assoc>
163
- <item key='first_name'>Tom</item>
164
- <item key='last_name'>Jones</item>
165
- </dt_assoc>
166
- </item>
167
- <item key='tech'>
168
- <dt_assoc>
169
- <item key='first_name'>Anne</item>
170
- <item key='last_name'>Smith</item>
171
- </dt_assoc>
172
- </item>
173
- </dt_assoc>
174
- </item>
175
- </dt_assoc>
176
- </data_block>
177
- </body>
178
- </OPS_envelope>}
179
-
180
- @response = OpenSRS::XmlProcessor::Nokogiri.parse(xml)
181
- end
182
- it { @response["contact_set"]["owner"]["first_name"].should eql("Tom") }
183
- it { @response["contact_set"]["owner"]["last_name"].should eql("Jones") }
184
- it { @response["contact_set"]["tech"]["first_name"].should eql("Anne") }
185
- it { @response["contact_set"]["tech"]["last_name"].should eql("Smith") }
186
- end
187
-
188
- context "with a balance enquiry example response" do
189
- before(:each) do
190
- xml = %{<?xml version='1.0' encoding='UTF-8' standalone='no' ?>
191
- <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
192
- <OPS_envelope>
193
- <header>
194
- <version>0.9</version>
195
- </header>
196
- <body>
197
- <data_block>
198
- <dt_assoc>
199
- <item key="protocol">XCP</item>
200
- <item key="action">REPLY</item>
201
- <item key="object">BALANCE</item>
202
- <item key="is_success">1</item>
203
- <item key="response_code">200</item>
204
- <item key="response_text">Command successful</item>
205
- <item key="attributes">
206
- <dt_assoc>
207
- <item key="balance">8549.18</item>
208
- <item key="hold_balance">1676.05</item>
209
- </dt_assoc>
210
- </item>
211
- </dt_assoc>
212
- </data_block>
213
- </body>
214
- </OPS_envelope>}
215
-
216
- @response = OpenSRS::XmlProcessor::Nokogiri.parse(xml)
217
- end
218
-
219
- it { @response.should be_an_instance_of(Hash) }
220
- it { @response["protocol"].should eql("XCP") }
221
- it { @response["action"].should eql("REPLY") }
222
- it { @response["object"].should eql("BALANCE") }
223
- it { @response["attributes"]["balance"].should eql("8549.18") }
224
- it { @response["attributes"]["hold_balance"].should eql("1676.05") }
225
-
226
- end
227
- end
228
- end
data/spec/spec_helper.rb DELETED
@@ -1,6 +0,0 @@
1
- require 'opensrs/xml_processor.rb'
2
- require 'opensrs/xml_processor/libxml.rb'
3
- require 'opensrs/xml_processor/nokogiri.rb'
4
- require 'opensrs/server.rb'
5
- require 'opensrs/version.rb'
6
- require 'opensrs/response.rb'