Skip to content
This repository
Browse code

Fix deprecated Whois::Record::Part.new usage

  • Loading branch information...
commit 7a96b2699027f2ab1972dbe98e0c49cea586672c 1 parent 2dad3d3
Simone Carletti authored
4 lib/whois/record.rb
@@ -104,12 +104,12 @@ def match?(pattern)
104 104 # and separates each response with a newline character.
105 105 #
106 106 # @example Record with one part
107   - # record = Whois::Record.new([Whois::Record::Part.new("First record.")])
  107 + # record = Whois::Record.new([Whois::Record::Part.new(:body => "First record.")])
108 108 # record.content
109 109 # # => "First record."
110 110 #
111 111 # @example Record with multiple parts
112   - # record = Whois::Record.new([Whois::Record::Part.new("First record."), Whois::Record::Part.new("Second record.")])
  112 + # record = Whois::Record.new([Whois::Record::Part.new(:body => "First record."), Whois::Record::Part.new(:body => "Second record.")])
113 113 # record.content
114 114 # # => "First record.\nSecond record."
115 115 #
2  lib/whois/server/adapters/base.rb
@@ -141,7 +141,7 @@ def request(string)
141 141 #
142 142 # @api public
143 143 def buffer_append(body, host)
144   - @buffer << Whois::Record::Part.new(body, host)
  144 + @buffer << Whois::Record::Part.new(:body => body, :host => host)
145 145 end
146 146
147 147 # @api internal
22 spec/whois/record/parser/base_spec.rb
@@ -3,7 +3,7 @@
3 3 describe Whois::Record::Parser::Base do
4 4
5 5 before(:each) do
6   - @part = Whois::Record::Part.new("This is the response.", "whois.example.test")
  6 + @part = Whois::Record::Part.new(:body => "This is the response.", :host => "whois.example.test")
7 7 end
8 8
9 9
@@ -54,12 +54,12 @@
54 54
55 55 describe "#content_for_scanner" do
56 56 it "returns the part body with line feed normalized" do
57   - i = klass.new(Whois::Record::Part.new("This is\r\nthe response.", "whois.example.test"))
  57 + i = klass.new(Whois::Record::Part.new(:body => "This is\r\nthe response.", :host => "whois.example.test"))
58 58 i.send(:content_for_scanner).should == "This is\nthe response."
59 59 end
60 60
61 61 it "caches the result" do
62   - i = klass.new(Whois::Record::Part.new("This is\r\nthe response.", "whois.example.test"))
  62 + i = klass.new(Whois::Record::Part.new(:body => "This is\r\nthe response.", :host => "whois.example.test"))
63 63 i.instance_eval { @content_for_scanner }.should be_nil
64 64 i.send(:content_for_scanner)
65 65 i.instance_eval { @content_for_scanner }.should == "This is\nthe response."
@@ -125,14 +125,14 @@
125 125 end
126 126
127 127 it "returns true if the content_for_scanner is the same" do
128   - i = klass.new(Whois::Record::Part.new("This is the\nresponse 1.", "whois.example.test"))
129   - o = klass.new(Whois::Record::Part.new("This is the\r\nresponse 1.", "whois.example.test"))
  128 + i = klass.new(Whois::Record::Part.new(:body => "This is the\nresponse 1.", :host => "whois.example.test"))
  129 + o = klass.new(Whois::Record::Part.new(:body => "This is the\r\nresponse 1.", :host => "whois.example.test"))
130 130 i.unchanged?(o).should be_true
131 131 end
132 132
133 133 it "returns false if the content_for_scanner is not the same" do
134   - i = klass.new(Whois::Record::Part.new("This is the response 1.", "whois.example.test"))
135   - o = klass.new(Whois::Record::Part.new("This is the response 2.", "whois.example.test"))
  134 + i = klass.new(Whois::Record::Part.new(:body => "This is the response 1.", :host => "whois.example.test"))
  135 + o = klass.new(Whois::Record::Part.new(:body => "This is the response 2.", :host => "whois.example.test"))
136 136 i.unchanged?(o).should be_false
137 137 end
138 138 end
@@ -221,20 +221,20 @@ def response_throttled?
221 221
222 222 context "property supported" do
223 223 it "raises Whois::ResponseIsThrottled when the response is throttled" do
224   - i = Klass.new(Whois::Record::Part.new("", "throttled.whois.test"))
  224 + i = Klass.new(Whois::Record::Part.new(:body => "", :host => "throttled.whois.test"))
225 225 lambda { i.domain }.should raise_error(Whois::ResponseIsThrottled)
226 226
227   - i = Klass.new(Whois::Record::Part.new("", "success.whois.test"))
  227 + i = Klass.new(Whois::Record::Part.new(:body => "", :host => "success.whois.test"))
228 228 lambda { i.domain }.should_not raise_error
229 229 end
230 230 end
231 231
232 232 context "property not supported" do
233 233 it "raises Whois::ResponseIsThrottled when the response is throttled" do
234   - i = Klass.new(Whois::Record::Part.new("", "throttled.whois.test"))
  234 + i = Klass.new(Whois::Record::Part.new(:body => "", :host => "throttled.whois.test"))
235 235 lambda { i.domain_id }.should raise_error(Whois::PropertyNotSupported)
236 236
237   - i = Klass.new(Whois::Record::Part.new("", "success.whois.test"))
  237 + i = Klass.new(Whois::Record::Part.new(:body => "", :host => "success.whois.test"))
238 238 lambda { i.domain_id }.should raise_error(Whois::PropertyNotSupported)
239 239 end
240 240 end
2  spec/whois/record/parser/blank_spec.rb
@@ -4,7 +4,7 @@
4 4 describe Whois::Record::Parser::Blank do
5 5
6 6 before(:each) do
7   - @part = Whois::Record::Part.new("This is the response.", "whois.example.test")
  7 + @part = Whois::Record::Part.new(:body => "This is the response.", :host => "whois.example.test")
8 8 end
9 9
10 10 Whois::Record::Parser::PROPERTIES.each do |method|
50 spec/whois/record/parser_spec.rb
@@ -85,29 +85,29 @@ class Whois::Record::Parser::ParserUnsupportedTest < Whois::Record::Parser::Base
85 85 end
86 86
87 87 it "delegates to first parser when all supported" do
88   - r = Whois::Record.new(nil, [Whois::Record::Part.new("", "parser.supported.test"), Whois::Record::Part.new("", "parser.undefined.test")])
  88 + r = Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "parser.supported.test"), Whois::Record::Part.new(:body => "", :host => "parser.undefined.test")])
89 89 klass.new(r).status.should == :status_undefined
90   - r = Whois::Record.new(nil, [Whois::Record::Part.new("", "parser.undefined.test"), Whois::Record::Part.new("", "parser.supported.test")])
  90 + r = Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "parser.undefined.test"), Whois::Record::Part.new(:body => "", :host => "parser.supported.test")])
91 91 klass.new(r).status.should == :status_supported
92 92 end
93 93
94 94 it "delegates to first parser when one supported" do
95   - r = Whois::Record.new(nil, [Whois::Record::Part.new("", "parser.supported.test"), Whois::Record::Part.new("", "parser.undefined.test")])
  95 + r = Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "parser.supported.test"), Whois::Record::Part.new(:body => "", :host => "parser.undefined.test")])
96 96 klass.new(r).created_on.should == :created_on_supported
97   - r = Whois::Record.new(nil, [Whois::Record::Part.new("", "parser.undefined.test"), Whois::Record::Part.new("", "parser.supported.test")])
  97 + r = Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "parser.undefined.test"), Whois::Record::Part.new(:body => "", :host => "parser.supported.test")])
98 98 klass.new(r).created_on.should == :created_on_supported
99 99 end
100 100
101 101 it "raises unless at least one is supported" do
102 102 lambda do
103   - r = Whois::Record.new(nil, [Whois::Record::Part.new("", "parser.unsupported.test"), Whois::Record::Part.new("", "parser.unsupported.test")])
  103 + r = Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "parser.unsupported.test"), Whois::Record::Part.new(:body => "", :host => "parser.unsupported.test")])
104 104 klass.new(r).created_on
105 105 end.should raise_error(Whois::PropertyNotSupported)
106 106 end
107 107
108 108 it "raises when parsers are undefined" do
109 109 lambda do
110   - r = Whois::Record.new(nil, [Whois::Record::Part.new("", "parser.undefined.test"), Whois::Record::Part.new("", "parser.undefined.test")])
  110 + r = Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "parser.undefined.test"), Whois::Record::Part.new(:body => "", :host => "parser.undefined.test")])
111 111 klass.new(r).created_on
112 112 end.should raise_error(Whois::PropertyNotAvailable)
113 113 end
@@ -121,7 +121,7 @@ class Whois::Record::Parser::ParserUnsupportedTest < Whois::Record::Parser::Base
121 121
122 122 it "does not delegate unknown properties" do
123 123 lambda do
124   - r = Whois::Record.new(nil, [Whois::Record::Part.new("", "parser.undefined.test")])
  124 + r = Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "parser.undefined.test")])
125 125 klass.new(r).unknown_method
126 126 end.should raise_error(NoMethodError)
127 127 end
@@ -137,32 +137,32 @@ class Whois::Record::Parser::ParserUnsupportedTest < Whois::Record::Parser::Base
137 137 end
138 138
139 139 it "returns 1 parser when 1 part" do
140   - record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "whois.nic.it")])
  140 + record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "whois.nic.it")])
141 141 parser = klass.new(record)
142 142 parser.parsers.should have(1).parsers
143 143 end
144 144
145 145 it "returns 2 parsers when 2 part" do
146   - record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "whois.crsnic.net"), Whois::Record::Part.new(nil, "whois.nic.it")])
  146 + record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "whois.crsnic.net"), Whois::Record::Part.new(:body => nil, :host => "whois.nic.it")])
147 147 parser = klass.new(record)
148 148 parser.parsers.should have(2).parsers
149 149 end
150 150
151 151 it "initializes the parsers in reverse order" do
152   - record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "whois.crsnic.net"), Whois::Record::Part.new(nil, "whois.nic.it")])
  152 + record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "whois.crsnic.net"), Whois::Record::Part.new(:body => nil, :host => "whois.nic.it")])
153 153 parser = klass.new(record)
154 154 parser.parsers[0].should be_a(Whois::Record::Parser::WhoisNicIt)
155 155 parser.parsers[1].should be_a(Whois::Record::Parser::WhoisCrsnicNet)
156 156 end
157 157
158 158 it "returns the host parser when the part is supported" do
159   - record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "whois.nic.it")])
  159 + record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "whois.nic.it")])
160 160 parser = klass.new(record)
161 161 parser.parsers.first.should be_a(Whois::Record::Parser::WhoisNicIt)
162 162 end
163 163
164 164 it "returns the Blank parser when the part is not supported" do
165   - record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "missing.nic.it")])
  165 + record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "missing.nic.it")])
166 166 parser = klass.new(record)
167 167 parser.parsers.first.should be_a(Whois::Record::Parser::Blank)
168 168 end
@@ -175,22 +175,22 @@ class Whois::Record::Parser::ParserUnsupportedTest < Whois::Record::Parser::Base
175 175 end
176 176
177 177 it "returns true when 1 part supported" do
178   - record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "whois.nic.it")])
  178 + record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "whois.nic.it")])
179 179 klass.new(record).property_supported?(:disclaimer).should be_true
180 180 end
181 181
182 182 it "returns false when 1 part supported" do
183   - record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "missing.nic.it")])
  183 + record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "missing.nic.it")])
184 184 klass.new(record).property_supported?(:disclaimer).should be_false
185 185 end
186 186
187 187 it "returns true when 2 parts" do
188   - record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "whois.crsnic.net"), Whois::Record::Part.new(nil, "whois.nic.it")])
  188 + record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "whois.crsnic.net"), Whois::Record::Part.new(:body => nil, :host => "whois.nic.it")])
189 189 klass.new(record).property_supported?(:disclaimer).should be_true
190 190 end
191 191
192 192 it "returns true when 1 part supported 1 part not supported" do
193   - record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "missing.nic.it"), Whois::Record::Part.new(nil, "whois.nic.it")])
  193 + record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "missing.nic.it"), Whois::Record::Part.new(:body => nil, :host => "whois.nic.it")])
194 194 klass.new(record).property_supported?(:disclaimer).should be_true
195 195 end
196 196 end
@@ -217,21 +217,21 @@ class Whois::Record::Parser::Contacts3Test< Whois::Record::Parser::Base
217 217 end
218 218
219 219 it "returns an array of contact when 1 part is supported" do
220   - record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "contacts2.test")])
  220 + record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "contacts2.test")])
221 221 parser = klass.new(record)
222 222 parser.contacts.should have(2).contacts
223 223 parser.contacts.should == %w( p2-a1 p2-t1 )
224 224 end
225 225
226 226 it "returns an array of contact when 1 part is not supported" do
227   - record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "contacts1.test")])
  227 + record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "contacts1.test")])
228 228 parser = klass.new(record)
229 229 parser.contacts.should have(0).contacts
230 230 parser.contacts.should == %w()
231 231 end
232 232
233 233 it "merges the contacts and returns an array of contact when 2 parts" do
234   - record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "contacts2.test"), Whois::Record::Part.new(nil, "contacts3.test")])
  234 + record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "contacts2.test"), Whois::Record::Part.new(:body => nil, :host => "contacts3.test")])
235 235 parser = klass.new(record)
236 236 parser.contacts.should have(3).contacts
237 237 parser.contacts.should == %w( p3-t1 p2-a1 p2-t1 )
@@ -269,7 +269,7 @@ class Whois::Record::Parser::Contacts3Test< Whois::Record::Parser::Base
269 269
270 270 it "returns false if parser and other.parser have different number of elements" do
271 271 instance = klass.new(Whois::Record.new(nil, []))
272   - other = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new("", "foo.example.test")]))
  272 + other = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "foo.example.test")]))
273 273 instance.unchanged?(other).should be_false
274 274 end
275 275
@@ -281,15 +281,15 @@ class Whois::Record::Parser::Contacts3Test< Whois::Record::Parser::Base
281 281
282 282
283 283 it "returns true if every parser in self marches the corresponding parser in other" do
284   - instance = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new("hello", "foo.example.test"), Whois::Record::Part.new("world", "bar.example.test")]))
285   - other = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new("hello", "foo.example.test"), Whois::Record::Part.new("world", "bar.example.test")]))
  284 + instance = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new(:body => "hello", :host => "foo.example.test"), Whois::Record::Part.new(:body => "hello", :host => "bar.example.test")]))
  285 + other = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new(:body => "hello", :host => "foo.example.test"), Whois::Record::Part.new(:body => "hello", :host => "bar.example.test")]))
286 286
287 287 instance.unchanged?(other).should be_true
288 288 end
289 289
290 290 it "returns false unless every parser in self marches the corresponding parser in other" do
291   - instance = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new("hello", "foo.example.test"), Whois::Record::Part.new("world", "bar.example.test")]))
292   - other = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new("hello", "foo.example.test"), Whois::Record::Part.new("baby!", "bar.example.test")]))
  291 + instance = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new(:body => "hello", :host => "foo.example.test"), Whois::Record::Part.new(:body => "world", :host => "bar.example.test")]))
  292 + other = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new(:body => "hello", :host => "foo.example.test"), Whois::Record::Part.new(:body => "baby!", :host => "bar.example.test")]))
293 293
294 294 instance.unchanged?(other).should be_false
295 295 end
@@ -371,7 +371,7 @@ class Whois::Record::Parser::ResponseUndefinedTest < Whois::Record::Parser::Base
371 371 end
372 372
373 373 def parsers(*types)
374   - klass.new(Whois::Record.new(nil, types.map { |type| Whois::Record::Part.new("", "response-#{type}.test") }))
  374 + klass.new(Whois::Record.new(nil, types.map { |type| Whois::Record::Part.new(:body => "", :host => "response-#{type}.test") }))
375 375 end
376 376
377 377 end
24 spec/whois/record_spec.rb
@@ -5,8 +5,8 @@
5 5 before(:each) do
6 6 @server = Whois::Server.factory(:tld, ".foo", "whois.example.test")
7 7 @parts = [
8   - Whois::Record::Part.new("This is a record from foo.", "foo.example.test"),
9   - Whois::Record::Part.new("This is a record from bar.", "bar.example.test")
  8 + Whois::Record::Part.new(:body => "This is a record from foo.", :host => "foo.example.test"),
  9 + Whois::Record::Part.new(:body => "This is a record from bar.", :host => "bar.example.test")
10 10 ]
11 11 @content = @parts.map(&:body).join("\n")
12 12 end
@@ -203,57 +203,57 @@ class Whois::Record::Parser::WhoisPropertiesTest < Whois::Record::Parser::Base
203 203
204 204 describe "#property_supported?" do
205 205 it "returns true if the property is supported" do
206   - r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
  206 + r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
207 207 r.property_supported?(:status).should == true
208 208 r.property_supported?(:created_on).should == true
209 209 end
210 210
211 211 it "returns false if the property is not supported" do
212   - r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
  212 + r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
213 213 r.property_supported?(:updated_on).should == false
214 214 end
215 215
216 216 it "returns false if the property is not defined" do
217   - r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
  217 + r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
218 218 r.property_supported?(:expires_on).should == false
219 219 end
220 220 end
221 221
222 222 describe "property" do
223 223 it "returns value when the property is supported" do
224   - r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
  224 + r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
225 225 r.created_on.should == Date.parse("2010-10-20")
226 226 end
227 227
228 228 it "returns nil when the property is not supported" do
229   - r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
  229 + r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
230 230 r.updated_on.should be_nil
231 231 end
232 232
233 233 it "returns nil when the property is not implemented" do
234   - r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
  234 + r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
235 235 r.expires_on.should be_nil
236 236 end
237 237 end
238 238
239 239 describe "property?" do
240 240 it "returns true when the property is supported and has no value" do
241   - r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
  241 + r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
242 242 r.status?.should == false
243 243 end
244 244
245 245 it "returns false when the property is supported and has q value" do
246   - r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
  246 + r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
247 247 r.created_on?.should == true
248 248 end
249 249
250 250 it "returns false when the property is not supported" do
251   - r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
  251 + r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
252 252 r.updated_on?.should == false
253 253 end
254 254
255 255 it "returns false when the property is not implemented" do
256   - r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
  256 + r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
257 257 r.expires_on?.should == false
258 258 end
259 259 end

0 comments on commit 7a96b26

Please sign in to comment.
Something went wrong with that request. Please try again.