mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
Refactor :follow_links option
This commit is contained in:
parent
bf6c900ca7
commit
4a2a393ed4
2 changed files with 38 additions and 24 deletions
|
@ -20,7 +20,7 @@ module Docs
|
|||
internal_urls << url.merge!(fragment: nil).to_s if internal_urls
|
||||
end
|
||||
|
||||
result[:internal_urls] = (internal_urls || []).to_a
|
||||
result[:internal_urls] = internal_urls.to_a if internal_urls
|
||||
doc
|
||||
end
|
||||
|
||||
|
|
|
@ -133,28 +133,6 @@ class InternalUrlsFilterTest < MiniTest::Spec
|
|||
assert_includes internal_urls, 'http://example.com/'
|
||||
end
|
||||
end
|
||||
|
||||
context "when context[:follow_links] is a block" do
|
||||
before do
|
||||
@body = link_to context[:url]
|
||||
end
|
||||
|
||||
it "calls the block with the filter instance" do
|
||||
context[:follow_links] = ->(arg) { @arg = arg; nil }
|
||||
filter.call
|
||||
assert_equal filter, @arg
|
||||
end
|
||||
|
||||
it "is empty when the block returns false" do
|
||||
context[:follow_links] = ->(_) { false }
|
||||
assert_empty internal_urls
|
||||
end
|
||||
|
||||
it "is the default when the block returns true" do
|
||||
context[:follow_links] = ->(_) { true }
|
||||
refute_empty internal_urls
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when the base url is 'example.com'" do
|
||||
|
@ -325,7 +303,7 @@ class InternalUrlsFilterTest < MiniTest::Spec
|
|||
context[:skip_links] = ->(_) { false }
|
||||
end
|
||||
|
||||
it "set :internal_urls" do
|
||||
it "sets :internal_urls" do
|
||||
assert internal_urls
|
||||
end
|
||||
|
||||
|
@ -335,4 +313,40 @@ class InternalUrlsFilterTest < MiniTest::Spec
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "context[:follow_links] is a block" do
|
||||
before do
|
||||
@body = link_to context[:url]
|
||||
end
|
||||
|
||||
it "calls the block with the filter instance" do
|
||||
context[:follow_links] = ->(arg) { @arg = arg; nil }
|
||||
filter.call
|
||||
assert_equal filter, @arg
|
||||
end
|
||||
|
||||
context "and the block returns false" do
|
||||
before do
|
||||
context[:follow_links] = ->(_) { false }
|
||||
end
|
||||
|
||||
it "doesn't set :internal_urls" do
|
||||
refute internal_urls
|
||||
end
|
||||
|
||||
it "replaces urls" do
|
||||
refute_equal @body, filter_output_string
|
||||
end
|
||||
end
|
||||
|
||||
context "and the block returns true" do
|
||||
before do
|
||||
context[:follow_links] = ->(_) { true }
|
||||
end
|
||||
|
||||
it "sets :internal_urls" do
|
||||
assert internal_urls
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue