Skip to content

Commit

Permalink
Deprecated Whois::Answer::Part#response.
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Sep 21, 2010
1 parent 2903cd9 commit 6e963ee
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
= Changelog


== master

* CHANGED: Deprecated Whois::Answer::Part#response.


== Release 1.3.5

* SERVER: Updated the .so TLD definition (#36).
Expand Down
2 changes: 1 addition & 1 deletion lib/whois/answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def eql?(other)
# String:: The content of this answer.
#
def content
@content ||= parts.map(&:response).join("\n")
@content ||= parts.map(&:body).join("\n")
end


Expand Down
2 changes: 1 addition & 1 deletion lib/whois/answer/parser/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def part
# That said, the only constraints about this method is to return the data to be parsed as string.
#
def content
part.response
part.body
end


Expand Down
30 changes: 25 additions & 5 deletions lib/whois/answer/part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,33 @@ class Answer
#
# = Part
#
# A single <tt>Whois::Answer</tt> fragment. For instance,
# in case of thin server, a <tt>Whois::Answer</tt> may be composed by
# one or more parts corresponding to all responses
# A single <tt>Whois::Answer</tt> fragment. For instance,
# in case of thin server, a <tt>Whois::Answer</tt> may be composed by
# one or more parts corresponding to all responses
# returned by the WHOIS servers.
#
class Part < SuperStruct.new(:response, :host)
# A <tt>Part</tt> is composed by the following attributes:
#
# * body - The body containing the whois output.
# * host - The host which returned the body.
#
class Part < SuperStruct.new(:body, :host)

def response=(value) # :nodoc:
Whois.deprecate \
"Whois::Answer::Part#response= is deprecated " \
"and will be removed in Whois 1.5. Use Whois::Answer::Part#body=."
self.body = value
end

def response # :nodoc:
Whois.deprecate \
"Whois::Answer::Part#response is deprecated " \
"and will be removed in Whois 1.5. Use Whois::Answer::Part#body."
self.body
end

end

end
end
end
2 changes: 1 addition & 1 deletion test/whois/answer/parser/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_initialize_should_require_part

def test_content
parser = @klass.new(@part)
assert_equal @part.response, parser.content
assert_equal @part.body, parser.content
end

def test_content_for_scanner
Expand Down
59 changes: 59 additions & 0 deletions test/whois/answer/part_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require 'test_helper'

class Whois::Answer::PartTest < Test::Unit::TestCase

def setup
@klass = Whois::Answer::Part
end

def test_initialize_with_empty_values
instance = @klass.new
assert_instance_of @klass, instance
assert_equal nil, instance.body

instance = @klass.new({})
assert_instance_of @klass, instance
assert_equal nil, instance.body
end

def test_initialize_with_params
instance = @klass.new("This is a WHOIS record.", "whois.example.test")

assert_equal "This is a WHOIS record.", instance.body
assert_equal "whois.example.test", instance.host
end

def test_initialize_with_hash
instance = @klass.new(:body => "This is a WHOIS record.", :host => "whois.example.test")

assert_equal "This is a WHOIS record.", instance.body
assert_equal "whois.example.test", instance.host
end

def test_initialize_with_block
instance = @klass.new do |c|
c.body = "This is a WHOIS record."
c.host = "whois.example.test"
end

assert_equal "This is a WHOIS record.", instance.body
assert_equal "whois.example.test", instance.host
end


def test_deprecated_response_setter
instance = @klass.new(:host => "whois.example.test")
instance.response = "This is a WHOIS record."

assert_equal "This is a WHOIS record.", instance.body
assert_equal "whois.example.test", instance.host
end

def test_deprecated_response_getter
instance = @klass.new(:body => "This is a WHOIS record.", :host => "whois.example.test")

assert_equal "This is a WHOIS record.", instance.response
assert_equal "whois.example.test", instance.host
end

end

0 comments on commit 6e963ee

Please sign in to comment.