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
20 internal_urls << url.merge!(fragment: nil).to_s if internal_urls20 internal_urls << url.merge!(fragment: nil).to_s if internal_urls
21 end21 end
22 22
23 result[:internal_urls] = (internal_urls || []).to_a23 result[:internal_urls] = internal_urls.to_a if internal_urls
24 doc24 doc
25 end25 end
26 26
test/lib/docs/filters/core/internal_urls_test.rb+37−23
@@ -133,28 +133,6 @@ class InternalUrlsFilterTest < MiniTest::Spec · 132 unmodified lines
133 assert_includes internal_urls, 'http://example.com/'133 assert_includes internal_urls, 'http://example.com/'
134 end134 end
135 end135 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
158 end136 end
159 137
160 context "when the base url is 'example.com'" do138 context "when the base url is 'example.com'" do
@@ -325,7 +303,7 @@ class InternalUrlsFilterTest < MiniTest::Spec · 164 unmodified lines
325 context[:skip_links] = ->(_) { false }303 context[:skip_links] = ->(_) { false }
326 end304 end
327 305
328 it "set :internal_urls" do306 it "sets :internal_urls" do
329 assert internal_urls307 assert internal_urls
330 end308 end
331 309
@@ -335,4 +313,40 @@ class InternalUrlsFilterTest < MiniTest::Spec · 3 unmodified lines
335 end313 end
336 end314 end
337 end315 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
338end352end