History

Refactor :follow_links option

Thibaut committed 12 years ago

Commit 4a2a3931 parent bf6c9002 files · +38 −24Browse files

Unified · Split

2 files
  1. lib/docs/filters/core/internal_urls.rb +1 −1
  2. test/lib/docs/filters/core/internal_urls_test.rb +37 −23
lib/docs/filters/core/internal_urls.rb+1−1
@@ -20,7 +20,7 @@ module Docs · 19 unmodified lines
2020 internal_urls << url.merge!(fragment: nil).to_s if internal_urls
2121 end
2222
23− result[:internal_urls] = (internal_urls || []).to_a
23+ result[:internal_urls] = internal_urls.to_a if internal_urls
2424 doc
2525 end
2626
test/lib/docs/filters/core/internal_urls_test.rb+37−23
@@ -133,28 +133,6 @@ class InternalUrlsFilterTest < MiniTest::Spec · 132 unmodified lines
133133 assert_includes internal_urls, 'http://example.com/'
134134 end
135135 end
136−
137− context "when context[:follow_links] is a block" do
138− before do
139− @body = link_to context[:url]
140− end
141−
142− it "calls the block with the filter instance" do
143− context[:follow_links] = ->(arg) { @arg = arg; nil }
144− filter.call
145− assert_equal filter, @arg
146− end
147−
148− it "is empty when the block returns false" do
149− context[:follow_links] = ->(_) { false }
150− assert_empty internal_urls
151− end
152−
153− it "is the default when the block returns true" do
154− context[:follow_links] = ->(_) { true }
155− refute_empty internal_urls
156− end
157− end
158136 end
159137
160138 context "when the base url is 'example.com'" do
@@ -325,7 +303,7 @@ class InternalUrlsFilterTest < MiniTest::Spec · 164 unmodified lines
325303 context[:skip_links] = ->(_) { false }
326304 end
327305
328− it "set :internal_urls" do
306+ it "sets :internal_urls" do
329307 assert internal_urls
330308 end
331309
@@ -335,4 +313,40 @@ class InternalUrlsFilterTest < MiniTest::Spec · 3 unmodified lines
335313 end
336314 end
337315 end
316+
317+ context "context[:follow_links] is a block" do
318+ before do
319+ @body = link_to context[:url]
320+ end
321+
322+ it "calls the block with the filter instance" do
323+ context[:follow_links] = ->(arg) { @arg = arg; nil }
324+ filter.call
325+ assert_equal filter, @arg
326+ end
327+
328+ context "and the block returns false" do
329+ before do
330+ context[:follow_links] = ->(_) { false }
331+ end
332+
333+ it "doesn't set :internal_urls" do
334+ refute internal_urls
335+ end
336+
337+ it "replaces urls" do
338+ refute_equal @body, filter_output_string
339+ end
340+ end
341+
342+ context "and the block returns true" do
343+ before do
344+ context[:follow_links] = ->(_) { true }
345+ end
346+
347+ it "sets :internal_urls" do
348+ assert internal_urls
349+ end
350+ end
351+ end
338352 end