Add tests for BrowseHelper#wikipedia_link
authorTom Hughes <tom@compton.nu>
Sat, 1 Mar 2014 00:25:33 +0000 (00:25 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 1 Mar 2014 00:25:33 +0000 (00:25 +0000)
test/helpers/browse_helper_test.rb [new file with mode: 0644]

diff --git a/test/helpers/browse_helper_test.rb b/test/helpers/browse_helper_test.rb
new file mode 100644 (file)
index 0000000..0e734a7
--- /dev/null
@@ -0,0 +1,31 @@
+require 'test_helper'
+
+class BrowseHelperTest < ActionView::TestCase
+  def test_wikipedia_link
+    link = wikipedia_link("wikipedia", "http://en.wikipedia.org/wiki/Full%20URL")
+    assert_nil link
+
+    link = wikipedia_link("wikipedia", "https://en.wikipedia.org/wiki/Full%20URL")
+    assert_nil link
+
+    link = wikipedia_link("wikipedia", "Test")
+    assert_equal "http://en.wikipedia.org/wiki/Test?uselang=en", link[:url]
+    assert_equal "Test", link[:title]
+
+    link = wikipedia_link("wikipedia", "de:Test")
+    assert_equal "http://de.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
+    assert_equal "de:Test", link[:title]
+
+    link = wikipedia_link("wikipedia:fr", "de:Test")
+    assert_equal "http://fr.wikipedia.org/wiki/de:Test?uselang=en", link[:url]
+    assert_equal "de:Test", link[:title]
+
+    I18n.locale = "pt-BR"
+    link = wikipedia_link("wikipedia", "zh-classical:Test#Section")
+    assert_equal "http://zh-classical.wikipedia.org/wiki/zh-classical:Test?uselang=pt-BR#Section", link[:url]
+    assert_equal "zh-classical:Test#Section", link[:title]
+
+    link = wikipedia_link("foo", "Test")
+    assert_nil link
+  end
+end