3 class SocialLinkTest < ActiveSupport::TestCase
5 social_link = create(:social_link)
7 assert_predicate social_link, :valid?
9 assert_not_predicate social_link, :valid?
13 social_link = create(:social_link)
15 assert_predicate social_link, :valid?
17 assert_not_predicate social_link, :valid?
20 def test_url_https_valid
21 social_link = create(:social_link)
23 assert_predicate social_link, :valid?
24 social_link.url = "test"
25 assert_not_predicate social_link, :valid?
28 def test_parsed_platform
29 social_link = create(:social_link, :url => "https://github.com/test")
31 assert_equal "github", social_link.parsed[:platform]
32 assert_equal "test", social_link.parsed[:name]
35 def test_parsed_platform_with_www
36 social_link = create(:social_link, :url => "http://www.github.com/test")
38 assert_equal "github", social_link.parsed[:platform]
39 assert_equal "test", social_link.parsed[:name]
42 def test_parsed_platform_custom_name
43 social_link = create(:social_link, :url => "https://discord.com/users/0")
45 assert_equal "discord", social_link.parsed[:platform]
46 assert_equal "Discord", social_link.parsed[:name]
49 def test_parsed_platform_mastodon
50 social_link = create(:social_link, :url => "https://mastodon.social/@test")
52 assert_equal "mastodon", social_link.parsed[:platform]
53 assert_equal "@test@mastodon.social", social_link.parsed[:name]
56 def test_parsed_platform_mastodon_parsed
57 social_link = create(:social_link, :url => "@test@mapstodon.space")
59 assert_equal "https://mapstodon.space/@test", social_link.parsed[:url]
60 assert_equal "mastodon", social_link.parsed[:platform]
61 assert_equal "@test@mapstodon.space", social_link.parsed[:name]
64 def test_parsed_platform_other
65 url = "https://test.com/test"
66 expected = "test.com/test"
67 social_link = create(:social_link, :url => url)
69 assert_nil social_link.parsed[:platform]
70 assert_equal social_link.parsed[:name], expected