Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct internal links when pulled from outdated cache #605

Merged
merged 1 commit into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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":""}}