Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 7a96b2699027f2ab1972dbe98e0c49cea586672c 1 parent 2dad3d3
@weppos authored
View
4 lib/whois/record.rb
@@ -104,12 +104,12 @@ def match?(pattern)
# and separates each response with a newline character.
#
# @example Record with one part
- # record = Whois::Record.new([Whois::Record::Part.new("First record.")])
+ # record = Whois::Record.new([Whois::Record::Part.new(:body => "First record.")])
# record.content
# # => "First record."
#
# @example Record with multiple parts
- # record = Whois::Record.new([Whois::Record::Part.new("First record."), Whois::Record::Part.new("Second record.")])
+ # record = Whois::Record.new([Whois::Record::Part.new(:body => "First record."), Whois::Record::Part.new(:body => "Second record.")])
# record.content
# # => "First record.\nSecond record."
#
View
2  lib/whois/server/adapters/base.rb
@@ -141,7 +141,7 @@ def request(string)
#
# @api public
def buffer_append(body, host)
- @buffer << Whois::Record::Part.new(body, host)
+ @buffer << Whois::Record::Part.new(:body => body, :host => host)
end
# @api internal
View
22 spec/whois/record/parser/base_spec.rb
@@ -3,7 +3,7 @@
describe Whois::Record::Parser::Base do
before(:each) do
- @part = Whois::Record::Part.new("This is the response.", "whois.example.test")
+ @part = Whois::Record::Part.new(:body => "This is the response.", :host => "whois.example.test")
end
@@ -54,12 +54,12 @@
describe "#content_for_scanner" do
it "returns the part body with line feed normalized" do
- i = klass.new(Whois::Record::Part.new("This is\r\nthe response.", "whois.example.test"))
+ i = klass.new(Whois::Record::Part.new(:body => "This is\r\nthe response.", :host => "whois.example.test"))
i.send(:content_for_scanner).should == "This is\nthe response."
end
it "caches the result" do
- i = klass.new(Whois::Record::Part.new("This is\r\nthe response.", "whois.example.test"))
+ i = klass.new(Whois::Record::Part.new(:body => "This is\r\nthe response.", :host => "whois.example.test"))
i.instance_eval { @content_for_scanner }.should be_nil
i.send(:content_for_scanner)
i.instance_eval { @content_for_scanner }.should == "This is\nthe response."
@@ -125,14 +125,14 @@
end
it "returns true if the content_for_scanner is the same" do
- i = klass.new(Whois::Record::Part.new("This is the\nresponse 1.", "whois.example.test"))
- o = klass.new(Whois::Record::Part.new("This is the\r\nresponse 1.", "whois.example.test"))
+ i = klass.new(Whois::Record::Part.new(:body => "This is the\nresponse 1.", :host => "whois.example.test"))
+ o = klass.new(Whois::Record::Part.new(:body => "This is the\r\nresponse 1.", :host => "whois.example.test"))
i.unchanged?(o).should be_true
end
it "returns false if the content_for_scanner is not the same" do
- i = klass.new(Whois::Record::Part.new("This is the response 1.", "whois.example.test"))
- o = klass.new(Whois::Record::Part.new("This is the response 2.", "whois.example.test"))
+ i = klass.new(Whois::Record::Part.new(:body => "This is the response 1.", :host => "whois.example.test"))
+ o = klass.new(Whois::Record::Part.new(:body => "This is the response 2.", :host => "whois.example.test"))
i.unchanged?(o).should be_false
end
end
@@ -221,20 +221,20 @@ def response_throttled?
context "property supported" do
it "raises Whois::ResponseIsThrottled when the response is throttled" do
- i = Klass.new(Whois::Record::Part.new("", "throttled.whois.test"))
+ i = Klass.new(Whois::Record::Part.new(:body => "", :host => "throttled.whois.test"))
lambda { i.domain }.should raise_error(Whois::ResponseIsThrottled)
- i = Klass.new(Whois::Record::Part.new("", "success.whois.test"))
+ i = Klass.new(Whois::Record::Part.new(:body => "", :host => "success.whois.test"))
lambda { i.domain }.should_not raise_error
end
end
context "property not supported" do
it "raises Whois::ResponseIsThrottled when the response is throttled" do
- i = Klass.new(Whois::Record::Part.new("", "throttled.whois.test"))
+ i = Klass.new(Whois::Record::Part.new(:body => "", :host => "throttled.whois.test"))
lambda { i.domain_id }.should raise_error(Whois::PropertyNotSupported)
- i = Klass.new(Whois::Record::Part.new("", "success.whois.test"))
+ i = Klass.new(Whois::Record::Part.new(:body => "", :host => "success.whois.test"))
lambda { i.domain_id }.should raise_error(Whois::PropertyNotSupported)
end
end
View
2  spec/whois/record/parser/blank_spec.rb
@@ -4,7 +4,7 @@
describe Whois::Record::Parser::Blank do
before(:each) do
- @part = Whois::Record::Part.new("This is the response.", "whois.example.test")
+ @part = Whois::Record::Part.new(:body => "This is the response.", :host => "whois.example.test")
end
Whois::Record::Parser::PROPERTIES.each do |method|
View
50 spec/whois/record/parser_spec.rb
@@ -85,29 +85,29 @@ class Whois::Record::Parser::ParserUnsupportedTest < Whois::Record::Parser::Base
end
it "delegates to first parser when all supported" do
- r = Whois::Record.new(nil, [Whois::Record::Part.new("", "parser.supported.test"), Whois::Record::Part.new("", "parser.undefined.test")])
+ r = Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "parser.supported.test"), Whois::Record::Part.new(:body => "", :host => "parser.undefined.test")])
klass.new(r).status.should == :status_undefined
- r = Whois::Record.new(nil, [Whois::Record::Part.new("", "parser.undefined.test"), Whois::Record::Part.new("", "parser.supported.test")])
+ r = Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "parser.undefined.test"), Whois::Record::Part.new(:body => "", :host => "parser.supported.test")])
klass.new(r).status.should == :status_supported
end
it "delegates to first parser when one supported" do
- r = Whois::Record.new(nil, [Whois::Record::Part.new("", "parser.supported.test"), Whois::Record::Part.new("", "parser.undefined.test")])
+ r = Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "parser.supported.test"), Whois::Record::Part.new(:body => "", :host => "parser.undefined.test")])
klass.new(r).created_on.should == :created_on_supported
- r = Whois::Record.new(nil, [Whois::Record::Part.new("", "parser.undefined.test"), Whois::Record::Part.new("", "parser.supported.test")])
+ r = Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "parser.undefined.test"), Whois::Record::Part.new(:body => "", :host => "parser.supported.test")])
klass.new(r).created_on.should == :created_on_supported
end
it "raises unless at least one is supported" do
lambda do
- r = Whois::Record.new(nil, [Whois::Record::Part.new("", "parser.unsupported.test"), Whois::Record::Part.new("", "parser.unsupported.test")])
+ r = Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "parser.unsupported.test"), Whois::Record::Part.new(:body => "", :host => "parser.unsupported.test")])
klass.new(r).created_on
end.should raise_error(Whois::PropertyNotSupported)
end
it "raises when parsers are undefined" do
lambda do
- r = Whois::Record.new(nil, [Whois::Record::Part.new("", "parser.undefined.test"), Whois::Record::Part.new("", "parser.undefined.test")])
+ r = Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "parser.undefined.test"), Whois::Record::Part.new(:body => "", :host => "parser.undefined.test")])
klass.new(r).created_on
end.should raise_error(Whois::PropertyNotAvailable)
end
@@ -121,7 +121,7 @@ class Whois::Record::Parser::ParserUnsupportedTest < Whois::Record::Parser::Base
it "does not delegate unknown properties" do
lambda do
- r = Whois::Record.new(nil, [Whois::Record::Part.new("", "parser.undefined.test")])
+ r = Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "parser.undefined.test")])
klass.new(r).unknown_method
end.should raise_error(NoMethodError)
end
@@ -137,32 +137,32 @@ class Whois::Record::Parser::ParserUnsupportedTest < Whois::Record::Parser::Base
end
it "returns 1 parser when 1 part" do
- record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "whois.nic.it")])
+ record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "whois.nic.it")])
parser = klass.new(record)
parser.parsers.should have(1).parsers
end
it "returns 2 parsers when 2 part" do
- record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "whois.crsnic.net"), Whois::Record::Part.new(nil, "whois.nic.it")])
+ 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")])
parser = klass.new(record)
parser.parsers.should have(2).parsers
end
it "initializes the parsers in reverse order" do
- record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "whois.crsnic.net"), Whois::Record::Part.new(nil, "whois.nic.it")])
+ 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")])
parser = klass.new(record)
parser.parsers[0].should be_a(Whois::Record::Parser::WhoisNicIt)
parser.parsers[1].should be_a(Whois::Record::Parser::WhoisCrsnicNet)
end
it "returns the host parser when the part is supported" do
- record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "whois.nic.it")])
+ record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "whois.nic.it")])
parser = klass.new(record)
parser.parsers.first.should be_a(Whois::Record::Parser::WhoisNicIt)
end
it "returns the Blank parser when the part is not supported" do
- record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "missing.nic.it")])
+ record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "missing.nic.it")])
parser = klass.new(record)
parser.parsers.first.should be_a(Whois::Record::Parser::Blank)
end
@@ -175,22 +175,22 @@ class Whois::Record::Parser::ParserUnsupportedTest < Whois::Record::Parser::Base
end
it "returns true when 1 part supported" do
- record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "whois.nic.it")])
+ record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "whois.nic.it")])
klass.new(record).property_supported?(:disclaimer).should be_true
end
it "returns false when 1 part supported" do
- record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "missing.nic.it")])
+ record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "missing.nic.it")])
klass.new(record).property_supported?(:disclaimer).should be_false
end
it "returns true when 2 parts" do
- record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "whois.crsnic.net"), Whois::Record::Part.new(nil, "whois.nic.it")])
+ 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")])
klass.new(record).property_supported?(:disclaimer).should be_true
end
it "returns true when 1 part supported 1 part not supported" do
- record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "missing.nic.it"), Whois::Record::Part.new(nil, "whois.nic.it")])
+ 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")])
klass.new(record).property_supported?(:disclaimer).should be_true
end
end
@@ -217,21 +217,21 @@ class Whois::Record::Parser::Contacts3Test< Whois::Record::Parser::Base
end
it "returns an array of contact when 1 part is supported" do
- record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "contacts2.test")])
+ record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "contacts2.test")])
parser = klass.new(record)
parser.contacts.should have(2).contacts
parser.contacts.should == %w( p2-a1 p2-t1 )
end
it "returns an array of contact when 1 part is not supported" do
- record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "contacts1.test")])
+ record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "contacts1.test")])
parser = klass.new(record)
parser.contacts.should have(0).contacts
parser.contacts.should == %w()
end
it "merges the contacts and returns an array of contact when 2 parts" do
- record = Whois::Record.new(nil, [Whois::Record::Part.new(nil, "contacts2.test"), Whois::Record::Part.new(nil, "contacts3.test")])
+ record = Whois::Record.new(nil, [Whois::Record::Part.new(:body => nil, :host => "contacts2.test"), Whois::Record::Part.new(:body => nil, :host => "contacts3.test")])
parser = klass.new(record)
parser.contacts.should have(3).contacts
parser.contacts.should == %w( p3-t1 p2-a1 p2-t1 )
@@ -269,7 +269,7 @@ class Whois::Record::Parser::Contacts3Test< Whois::Record::Parser::Base
it "returns false if parser and other.parser have different number of elements" do
instance = klass.new(Whois::Record.new(nil, []))
- other = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new("", "foo.example.test")]))
+ other = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new(:body => "", :host => "foo.example.test")]))
instance.unchanged?(other).should be_false
end
@@ -281,15 +281,15 @@ class Whois::Record::Parser::Contacts3Test< Whois::Record::Parser::Base
it "returns true if every parser in self marches the corresponding parser in other" do
- instance = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new("hello", "foo.example.test"), Whois::Record::Part.new("world", "bar.example.test")]))
- other = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new("hello", "foo.example.test"), Whois::Record::Part.new("world", "bar.example.test")]))
+ 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")]))
+ 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")]))
instance.unchanged?(other).should be_true
end
it "returns false unless every parser in self marches the corresponding parser in other" do
- instance = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new("hello", "foo.example.test"), Whois::Record::Part.new("world", "bar.example.test")]))
- other = klass.new(Whois::Record.new(nil, [Whois::Record::Part.new("hello", "foo.example.test"), Whois::Record::Part.new("baby!", "bar.example.test")]))
+ 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")]))
+ 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")]))
instance.unchanged?(other).should be_false
end
@@ -371,7 +371,7 @@ class Whois::Record::Parser::ResponseUndefinedTest < Whois::Record::Parser::Base
end
def parsers(*types)
- klass.new(Whois::Record.new(nil, types.map { |type| Whois::Record::Part.new("", "response-#{type}.test") }))
+ klass.new(Whois::Record.new(nil, types.map { |type| Whois::Record::Part.new(:body => "", :host => "response-#{type}.test") }))
end
end
View
24 spec/whois/record_spec.rb
@@ -5,8 +5,8 @@
before(:each) do
@server = Whois::Server.factory(:tld, ".foo", "whois.example.test")
@parts = [
- Whois::Record::Part.new("This is a record from foo.", "foo.example.test"),
- Whois::Record::Part.new("This is a record from bar.", "bar.example.test")
+ Whois::Record::Part.new(:body => "This is a record from foo.", :host => "foo.example.test"),
+ Whois::Record::Part.new(:body => "This is a record from bar.", :host => "bar.example.test")
]
@content = @parts.map(&:body).join("\n")
end
@@ -203,57 +203,57 @@ class Whois::Record::Parser::WhoisPropertiesTest < Whois::Record::Parser::Base
describe "#property_supported?" do
it "returns true if the property is supported" do
- r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
+ r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
r.property_supported?(:status).should == true
r.property_supported?(:created_on).should == true
end
it "returns false if the property is not supported" do
- r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
+ r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
r.property_supported?(:updated_on).should == false
end
it "returns false if the property is not defined" do
- r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
+ r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
r.property_supported?(:expires_on).should == false
end
end
describe "property" do
it "returns value when the property is supported" do
- r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
+ r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
r.created_on.should == Date.parse("2010-10-20")
end
it "returns nil when the property is not supported" do
- r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
+ r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
r.updated_on.should be_nil
end
it "returns nil when the property is not implemented" do
- r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
+ r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
r.expires_on.should be_nil
end
end
describe "property?" do
it "returns true when the property is supported and has no value" do
- r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
+ r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
r.status?.should == false
end
it "returns false when the property is supported and has q value" do
- r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
+ r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
r.created_on?.should == true
end
it "returns false when the property is not supported" do
- r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
+ r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
r.updated_on?.should == false
end
it "returns false when the property is not implemented" do
- r = klass.new(nil, [Whois::Record::Part.new("", "whois.properties.test")])
+ r = klass.new(nil, [Whois::Record::Part.new(:body => "", :host => "whois.properties.test")])
r.expires_on?.should == false
end
end

0 comments on commit 7a96b26

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