Class: Html::Test::ValidateFilter
- Inherits:
-
Object
- Object
- Html::Test::ValidateFilter
- Includes:
- Assertions, Test::Unit::Assertions
- Defined in:
- lib/validate_filter.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
-
#validators ⇒ Object
Returns the value of attribute validators.
Class Method Summary collapse
- .already_validated?(url) ⇒ Boolean
-
.clear_validated_urls ⇒ Object
Used in testing (of html_test_extension plugin) to remove the validated_urls hash so can test with the same url.
- .mark_url_validated(url) ⇒ Object
- .validated_urls ⇒ Object
Instance Method Summary collapse
-
#initialize(controller) ⇒ ValidateFilter
constructor
A new instance of ValidateFilter.
-
#should_validate? ⇒ Boolean
Override this method if you only want to validate a subset of pages.
- #validate_page ⇒ Object
Methods included from Assertions
#assert_tidy, #assert_validates, #assert_w3c, #assert_xmllint
Constructor Details
#initialize(controller) ⇒ ValidateFilter
Returns a new instance of ValidateFilter.
9 10 11 12 13 14 |
# File 'lib/validate_filter.rb', line 9 def initialize(controller) self.request = controller.request self.response = controller.response self.params = controller.params self.validators = controller.class.validators end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/validate_filter.rb', line 4 def params @params end |
#request ⇒ Object
Returns the value of attribute request.
4 5 6 |
# File 'lib/validate_filter.rb', line 4 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
4 5 6 |
# File 'lib/validate_filter.rb', line 4 def response @response end |
#validators ⇒ Object
Returns the value of attribute validators.
4 5 6 |
# File 'lib/validate_filter.rb', line 4 def validators @validators end |
Class Method Details
.already_validated?(url) ⇒ Boolean
26 27 28 29 30 31 32 |
# File 'lib/validate_filter.rb', line 26 def self.already_validated?(url) if Html::Test::Validator.revalidate_all false else validated_urls[url] end end |
.clear_validated_urls ⇒ Object
Used in testing (of html_test_extension plugin) to remove the validated_urls hash so can test with the same url.
56 57 58 |
# File 'lib/validate_filter.rb', line 56 def self.clear_validated_urls @validated_urls = {} end |
.mark_url_validated(url) ⇒ Object
34 35 36 |
# File 'lib/validate_filter.rb', line 34 def self.mark_url_validated(url) validated_urls[url] = true end |
.validated_urls ⇒ Object
38 39 40 |
# File 'lib/validate_filter.rb', line 38 def self.validated_urls @validated_urls ||= {} end |
Instance Method Details
#should_validate? ⇒ Boolean
Override this method if you only want to validate a subset of pages
43 44 45 46 47 48 49 50 51 |
# File 'lib/validate_filter.rb', line 43 def should_validate? # response.status =~ /200/ && # (response.headers['Content-Type'] =~ /text\/html/i || response.body =~ /<html/) # In rails 3, # response.status is a Fixnum which would return nil in this match # and response.headers['Content-Type'] is blank response.status.to_s =~ /200/ && (response.content_type =~ /text\/html/i || response.body =~ /<html/) end |
#validate_page ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/validate_filter.rb', line 16 def validate_page # url = request.request_uri # no more request_uri in Rails 3 url = request.url return if (!should_validate? || ValidateFilter.already_validated?(url)) # assert_validates(validators, response.body.strip, url, :verbose => true) assert_validates(validators, response.body.strip, url ) ValidateFilter.mark_url_validated(url) end |