Skip to content

Commit

Permalink
Merge pull request #605 from gjtorikian/cache-crash
Browse files Browse the repository at this point in the history
Correct internal links when pulled from outdated cache
  • Loading branch information
gjtorikian authored Dec 3, 2020
2 parents 21b0edd + ef4eafa commit a830821
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/html-proofer/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def validate_internal_urls
urls_to_check = load_internal_cache

urls_to_check.each_pair do |url, internal_urls|
# pulled from cache
internal_urls = @internal_urls[url] unless internal_urls.first.is_a?(LinkCheck::InternalLink)

result = @internal_link_checks.check_internal_link(internal_urls.first.link, internal_urls.first.path, internal_urls.first.line, internal_urls.first.content)
code = result ? 200 : 404
@cache.add(url, @internal_urls_to_paths[url].sort, code, '') # TODO: blank msg for now
Expand Down
19 changes: 19 additions & 0 deletions spec/html-proofer/cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,25 @@ def read_cache(cache_file)
end
end

context 'not within date for internal url' do
let(:cache_file_name) { '.not_within_date_internal.log' }
it 'does write file if timestamp is not within date' do
# this is frozen to within 7 days of the log
new_time = Time.local(2015, 10, 27, 12, 0, 0)
Timecop.freeze(new_time)

expect_any_instance_of(HTMLProofer::Cache).to receive(:write)
root_link = "#{FIXTURES_DIR}/links/root_link/root_link.html"

# we expect an add since we are mocking outside the timeframe
expect_any_instance_of(HTMLProofer::Cache).to receive(:add).with('/', ['spec/html-proofer/fixtures/links/root_link/root_link.html'], 200, '')

run_proofer(root_link, :file, disable_external: true, cache: { timeframe: '4d', cache_file: cache_file_name }.merge(default_cache_options))

Timecop.return
end
end

context 'new external url added' do
let(:cache_file_name) { '.new_external_url.log' }
it 'does write file if a new URL is added' do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"/":{"time":"2015-10-20 12:00:00 -0700","filenames":["spec/html-proofer/fixtures/links/root_link/root_link.html"],"status":200,"message":""}}

0 comments on commit a830821

Please sign in to comment.