dtext links: add table for tracking links between wikis.
Add a dtext_links table for tracking links between wiki pages. This is to allow for broken link detection and "what links here" searches, among other uses.
This commit is contained in:
@@ -56,5 +56,31 @@ class DTextTest < ActiveSupport::TestCase
|
||||
refute_match(/dtext-tag-does-not-exist/, DText.format_text("[[help:nothing]]"))
|
||||
end
|
||||
end
|
||||
|
||||
context "#parse_wiki_titles" do
|
||||
should "parse wiki links in dtext" do
|
||||
assert_equal(["foo"], DText.parse_wiki_titles("[[foo]] [[FOO]"))
|
||||
end
|
||||
end
|
||||
|
||||
context "#parse_external_links" do
|
||||
should "parse external links in dtext" do
|
||||
dtext = <<~EOS
|
||||
* https://test1.com
|
||||
* <https://test2.com>
|
||||
* "test":https://test3.com
|
||||
* "test":[https://test4.com]
|
||||
* [https://test5.com](test)
|
||||
* <a href="https://test6.com">test</a>
|
||||
EOS
|
||||
|
||||
links = %w[
|
||||
https://test1.com https://test2.com https://test3.com
|
||||
https://test4.com https://test5.com https://test6.com
|
||||
]
|
||||
|
||||
assert_equal(links, DText.parse_external_links(dtext))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -110,6 +110,21 @@ class WikiPageTest < ActiveSupport::TestCase
|
||||
version = WikiPageVersion.last
|
||||
assert_not_equal(@wiki_page.creator_id, version.updater_id)
|
||||
end
|
||||
|
||||
should "update its dtext links" do
|
||||
@wiki_page.update!(body: "[[long hair]]")
|
||||
assert_equal(1, @wiki_page.dtext_links.size)
|
||||
assert_equal("wiki_link", @wiki_page.dtext_links.first.link_type)
|
||||
assert_equal("long_hair", @wiki_page.dtext_links.first.link_target)
|
||||
|
||||
@wiki_page.update!(body: "http://www.google.com")
|
||||
assert_equal(1, @wiki_page.dtext_links.size)
|
||||
assert_equal("external_link", @wiki_page.dtext_links.first.link_type)
|
||||
assert_equal("http://www.google.com", @wiki_page.dtext_links.first.link_target)
|
||||
|
||||
@wiki_page.update!(body: "nothing")
|
||||
assert_equal(0, @wiki_page.dtext_links.size)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user