|
|
@ -5,16 +5,15 @@ class InternalUrlsFilterTest < MiniTest::Spec
|
|
|
|
include FilterTestHelper
|
|
|
|
include FilterTestHelper
|
|
|
|
self.filter_class = Docs::InternalUrlsFilter
|
|
|
|
self.filter_class = Docs::InternalUrlsFilter
|
|
|
|
|
|
|
|
|
|
|
|
describe ":internal_urls" do
|
|
|
|
before do
|
|
|
|
before do
|
|
|
|
context[:base_url] = context[:root_url] = context[:url] = 'http://example.com/dir'
|
|
|
|
context[:base_url] = context[:root_url] = 'http://example.com/dir'
|
|
|
|
end
|
|
|
|
context[:url] = 'http://example.com/dir'
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let :internal_urls do
|
|
|
|
let :internal_urls do
|
|
|
|
filter_result[:internal_urls]
|
|
|
|
filter_result[:internal_urls]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe ":internal_urls" do
|
|
|
|
it "is an array" do
|
|
|
|
it "is an array" do
|
|
|
|
assert_instance_of Array, internal_urls
|
|
|
|
assert_instance_of Array, internal_urls
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -135,31 +134,6 @@ class InternalUrlsFilterTest < MiniTest::Spec
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context "when context[:skip_links] is a block" do
|
|
|
|
|
|
|
|
let :block do
|
|
|
|
|
|
|
|
context[:skip_links] = Proc.new {}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "passes all links to the block" do
|
|
|
|
|
|
|
|
@body = link_to 'http://example.com'
|
|
|
|
|
|
|
|
context[:skip_links] = ->(arg) { @arg = arg }
|
|
|
|
|
|
|
|
internal_urls
|
|
|
|
|
|
|
|
assert_equal @body, @arg.to_s
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "doesn't include urls from links where the block returns true" do
|
|
|
|
|
|
|
|
@body = link_to 'http://example.com/dir/path'
|
|
|
|
|
|
|
|
context[:skip_links] = ->(_) { true }
|
|
|
|
|
|
|
|
assert_empty internal_urls
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "includes urls from links where the block returns false" do
|
|
|
|
|
|
|
|
@body = link_to 'http://example.com/dir/path'
|
|
|
|
|
|
|
|
context[:skip_links] = ->(_) { false }
|
|
|
|
|
|
|
|
assert_equal 1, internal_urls.length
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when context[:follow_links] is a block" do
|
|
|
|
context "when context[:follow_links] is a block" do
|
|
|
|
before do
|
|
|
|
before do
|
|
|
|
@body = link_to context[:url]
|
|
|
|
@body = link_to context[:url]
|
|
|
@ -305,4 +279,46 @@ class InternalUrlsFilterTest < MiniTest::Spec
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "context[:skip_links]" do
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
|
|
|
@body = link_to context[:url]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when it is a block" do
|
|
|
|
|
|
|
|
it "calls the block with the filter instance" do
|
|
|
|
|
|
|
|
context[:skip_links] = ->(arg) { @arg = arg; nil }
|
|
|
|
|
|
|
|
filter.call
|
|
|
|
|
|
|
|
assert_equal filter, @arg
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "and the block returns true" do
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
|
|
|
context[:skip_links] = ->(_) { true }
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "doesn't set :internal_urls" do
|
|
|
|
|
|
|
|
refute internal_urls
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "doesn't replace urls" do
|
|
|
|
|
|
|
|
assert_equal @body, filter_output_string
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "and the block returns false" do
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
|
|
|
context[:skip_links] = ->(_) { false }
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "set :internal_urls" do
|
|
|
|
|
|
|
|
assert internal_urls
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "replaces urls" do
|
|
|
|
|
|
|
|
refute_equal @body, filter_output_string
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|