Fix :follow_links option not doing anything when set to false

pull/656/merge
Thibaut Courouble 8 years ago
parent ba6d80b27f
commit dd8c80060a

@ -30,15 +30,15 @@ module Docs
end end
def skip_links? def skip_links?
if context[:skip_links].is_a? Proc return context[:skip_links].call(self) if context[:skip_links].is_a?(Proc)
context[:skip_links].call self return true if context[:skip_links]
else false
context[:skip_links]
end
end end
def follow_links? def follow_links?
!(context[:follow_links] && context[:follow_links].call(self) == false) return false if context[:follow_links] == false
return false if context[:follow_links].is_a?(Proc) && context[:follow_links].call(self) == false
true
end end
def to_internal_url(str) def to_internal_url(str)

@ -331,20 +331,14 @@ class InternalUrlsFilterTest < MiniTest::Spec
end end
end end
context "context[:follow_links] is a block" do context "context[:follow_links]" do
before do before do
@body = link_to context[:url] @body = link_to context[:url]
end end
it "calls the block with the filter instance" do context "when it is false" do
context[:follow_links] = ->(arg) { @arg = arg; nil }
filter.call
assert_equal filter, @arg
end
context "and the block returns false" do
before do before do
context[:follow_links] = ->(_) { false } context[:follow_links] = false
end end
it "doesn't set :internal_urls" do it "doesn't set :internal_urls" do
@ -356,13 +350,35 @@ class InternalUrlsFilterTest < MiniTest::Spec
end end
end end
context "and the block returns true" do context "when it is a block" do
before do it "calls the block with the filter instance" do
context[:follow_links] = ->(_) { true } context[:follow_links] = ->(arg) { @arg = arg; nil }
filter.call
assert_equal filter, @arg
end end
it "sets :internal_urls" do context "and the block returns false" do
assert internal_urls 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 end
end end

Loading…
Cancel
Save