Skip to content
Browse files

Those changes were supposed to be part of Release 0.6.0

  • Loading branch information...
1 parent 60dec5f commit 54d575fb616f48d0a035e3da61f9086323b33b77 @weppos committed Aug 26, 2009
View
25 lib/whois/response.rb
@@ -56,7 +56,7 @@ def eql?(other)
self == other
end
- # Returns whether this response is equal to <tt>other</tt>.
+ # Returns whether this response changed compared to <tt>other</tt>.
#
# Comparing the Response contents is not always as trivial as it seems.
# Whois servers sometimes inject dynamic method into the whois response such as
@@ -66,11 +66,17 @@ def eql?(other)
#
# This method should provide a bulletproof way to detect whether this response
# changed if compared with <tt>other</tt>.
- # def equals?
- #
- # end
+ def changed?(other)
+ !unchanged?(other)
+ end
+
+ # The opposite of <tt>changed?</tt>.
+ def unchanged?(other)
+ self == other ||
+ parser.unchanged?(other.parser)
+ end
+
-
# Invokes <tt>match</tt> and returns <tt>true</tt> if <tt>pattern</tt>
# matches <tt>@content</tt>, <tt>false</tt> otherwise.
def match?(pattern)
@@ -100,6 +106,7 @@ def parser
@parser ||= self.class.parser_klass(@server).new(self)
end
+
protected
# Delegates all method calls to the internal parser.
@@ -133,14 +140,6 @@ def self.host_to_parser(server)
gsub(/\./, '_').
gsub(/(?:^|_)(.)/) { $1.upcase }
end
-
- # available?
- # registered?
- # status
-
- # created_on
- # updated_on
- # expires_on
end
View
1 lib/whois/response/parsers/base.rb
@@ -44,7 +44,6 @@ class Base
:created_on, :updated_on, :expires_on,
:registrar, :registrant, :admin, :technical,
:nameservers,
- :equals?
]
def self.allowed_methods
View
42 lib/whois/response/parsers/whois.nic.it.rb
@@ -128,24 +128,30 @@ def nameservers
end
-# # Returns whether this response is equal to <tt>other</tt>.
-# #
-# # Comparing the Response contents is not always as trivial as it seems.
-# # Whois servers sometimes inject dynamic method into the whois response such as
-# # the timestamp the request was generated.
-# # This causes two responses to be different even if they actually should be considered equal
-# # because the registry data didn't change.
-# #
-# # This method should provide a bulletproof way to detect whether this response
-# # changed if compared with <tt>other</tt>.
-# def equals?(other)
-# self == other ||
-# self.response.to_s == other.response.to_s
-# # domain == other.domain &&
-# # created_on == other.created_on &&
-# # updated_on == other.updated_on &&
-# # expires_on == other.expires_on
-# end
+ # Returns whether this response changed compared to <tt>other</tt>.
+ #
+ # Comparing the Response contents is not always as trivial as it seems.
+ # Whois servers sometimes inject dynamic method into the whois response such as
+ # the timestamp the request was generated.
+ # This causes two responses to be different even if they actually should be considered equal
+ # because the registry data didn't change.
+ #
+ # This method should provide a bulletproof way to detect whether this response
+ # changed if compared with <tt>other</tt>.
+ def changed?(other)
+ !unchanged?(other)
+ end
+
+ # The opposite of <tt>changed?</tt>.
+ def unchanged?(other)
+ self == other ||
+ self.response.to_s == other.response.to_s
+ # (self == other) ||
+ # (domain == other.domain &&
+ # created_on == other.created_on &&
+ # updated_on == other.updated_on &&
+ # expires_on == other.expires_on )
+ end
protected
View
10 lib/whois/response/parsers/whois.publicinterestregistry.net.rb
@@ -100,6 +100,16 @@ def nameservers
end
+ def changed?(other)
+ !unchanged?(other)
+ end
+
+ def unchanged?(other)
+ self == other ||
+ self.response.to_s == other.response.to_s
+ end
+
+
protected
def contact(element)
View
90 test/parsers/whois_nic_it_test.rb
@@ -172,27 +172,75 @@ def test_nameservers_with_available
end
-# def test_equals_question
-# parser = load_response('/registered.txt').parser
-# assert parser.equals?(load_response('/registered.txt').parser)
-# assert !parser.equals?(load_response('/available.txt').parser)
-# end
-#
-# def test_equals_question_with_available
-# parser = @response.new(<<-RESPONSE, @server).parser
-# Domain: google.it
-# Status: AVAILABLE
-# RESPONSE
-#
-# assert parser.equals?(@response.new(<<-RESPONSE, @server).parser)
-# Domain: google.it
-# Status: AVAILABLE
-# RESPONSE
-# assert !parser.equals?(@response.new(<<-RESPONSE, @server).parser)
-# Domain: weppos.it
-# Status: AVAILABLE
-# RESPONSE
-# end
+ def test_changed_question_check_self
+ parser = load_response('/registered.txt').parser
+ assert !parser.changed?(parser)
+ end
+
+ def test_changed_question_check_internals
+ parser = load_response('/registered.txt').parser
+ assert parser.changed?(load_response('/available.txt').parser)
+ end
+
+ def test_changed_question_check_self_with_available
+ parser = @response.new(<<-RESPONSE, @server).parser
+Domain: google.it
+Status: AVAILABLE
+ RESPONSE
+
+ assert !parser.changed?(parser)
+ end
+
+ def test_changed_question_check_internals_with_available
+ parser = @response.new(<<-RESPONSE, @server).parser
+Domain: google.it
+Status: AVAILABLE
+ RESPONSE
+
+ assert parser.changed?(@response.new(<<-RESPONSE, @server).parser)
+Domain: weppos.it
+Status: AVAILABLE
+ RESPONSE
+ assert !parser.changed?(@response.new(<<-RESPONSE, @server).parser)
+Domain: google.it
+Status: AVAILABLE
+ RESPONSE
+ end
+
+ def test_unchanged_question_check_self
+ parser = load_response('/registered.txt').parser
+ assert parser.unchanged?(parser)
+ end
+
+ def test_unchanged_question_check_internals
+ parser = load_response('/registered.txt').parser
+ assert parser.unchanged?(load_response('/registered.txt').parser)
+ end
+
+ def test_unchanged_question_check_self_with_available
+ parser = @response.new(<<-RESPONSE, @server).parser
+Domain: google.it
+Status: AVAILABLE
+ RESPONSE
+
+ assert parser.unchanged?(parser)
+ end
+
+ def test_unchanged_question_check_internals_with_available
+ parser = @response.new(<<-RESPONSE, @server).parser
+Domain: google.it
+Status: AVAILABLE
+ RESPONSE
+
+ assert parser.unchanged?(@response.new(<<-RESPONSE, @server).parser)
+Domain: google.it
+Status: AVAILABLE
+ RESPONSE
+ assert !parser.unchanged?(@response.new(<<-RESPONSE, @server).parser)
+Domain: weppos.it
+Status: AVAILABLE
+ RESPONSE
+ end
protected
View
6 test/response_test.rb
@@ -38,19 +38,19 @@ def test_match
assert_equal @content.match(/google/), @response.match(/google/)
end
- def test_equality_with_self
+ def test_equality_check_self
assert_equal @response, @response
assert @response.eql?(@response)
end
- def test_equality_with_string
+ def test_equality_check_string
assert_equal @response, @content
assert_not_equal @content, @response
assert @response.eql?(@content)
assert !@content.eql?(@response)
end
- def test_equality
+ def test_equality_check_content
other = @klass.new(@content, @server)
assert_equal @response, other
assert_equal other, @response

0 comments on commit 54d575f

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