Skip to content

Commit

Permalink
Merge pull request #17 from doc75/fix_big_files
Browse files Browse the repository at this point in the history
ensure post is used for files (otherwise big files check are crashing)
  • Loading branch information
doc75 committed Oct 25, 2016
2 parents 56c705f + 031dc43 commit d1eadfe
Show file tree
Hide file tree
Showing 6 changed files with 1,484 additions and 30 deletions.
14 changes: 8 additions & 6 deletions lib/w3c_validators/css_validator.rb
Expand Up @@ -61,8 +61,8 @@ def validate_uri(uri)
# Validate the CSS of a string.
#
# Returns W3CValidators::Results.
def validate_text(text)
return validate({:text => text})
def validate_text(text, request_mode = :get)
return validate({:text => text}, request_mode)
end

# Validate the CSS of a local file.
Expand All @@ -77,14 +77,16 @@ def validate_file(file_path)
else
src = read_local_file(file_path)
end
return validate_text(src)
# we force the :post mode otherwise it fails for
# big files
return validate_text(src, :post)
end


protected
def validate(options) # :nodoc:
def validate(options, request_mode = :get) # :nodoc:
options = get_request_options(options)
response = send_request(options, :get)
response = send_request(options, request_mode)
@results = parse_soap_response(response.body)
@results
end
Expand Down Expand Up @@ -150,4 +152,4 @@ def parse_soap_response(response) # :nodoc:


end
end
end
6 changes: 6 additions & 0 deletions test/fixtures/bootstrap.min.css

Large diffs are not rendered by default.

1,423 changes: 1,423 additions & 0 deletions test/http_recording/css_validating_big_file.yml

Large diffs are not rendered by default.

30 changes: 18 additions & 12 deletions test/http_recording/css_validating_file.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 18 additions & 12 deletions test/http_recording/css_validating_text_via_file.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions test/test_css_validator.rb
Expand Up @@ -55,4 +55,15 @@ def test_validating_text_via_file
assert_errors r, 1
end
end

def test_validating_big_file
VCR.use_cassette('css_validating_big_file') do
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/bootstrap.min.css')
fh = File.new(file_path, 'r+')
r = @v.validate_file(fh)
fh.close
assert_errors r
end
end

end

0 comments on commit d1eadfe

Please sign in to comment.