]> git.openstreetmap.org Git - rails.git/blob - test/models/social_link_test.rb
Merge remote-tracking branch 'upstream/pull/6102'
[rails.git] / test / models / social_link_test.rb
1 require "test_helper"
2
3 class SocialLinkTest < ActiveSupport::TestCase
4   def test_user_required
5     social_link = create(:social_link)
6
7     assert_predicate social_link, :valid?
8     social_link.user = nil
9     assert_not_predicate social_link, :valid?
10   end
11
12   def test_url_required
13     social_link = create(:social_link)
14
15     assert_predicate social_link, :valid?
16     social_link.url = nil
17     assert_not_predicate social_link, :valid?
18   end
19
20   def test_url_https_valid
21     social_link = create(:social_link)
22
23     assert_predicate social_link, :valid?
24     social_link.url = "test"
25     assert_not_predicate social_link, :valid?
26   end
27
28   def test_parsed_platform
29     social_link = create(:social_link, :url => "https://github.com/test")
30
31     assert_equal "github", social_link.parsed[:platform]
32     assert_equal "test", social_link.parsed[:name]
33   end
34
35   def test_parsed_platform_with_www
36     social_link = create(:social_link, :url => "http://www.github.com/test")
37
38     assert_equal "github", social_link.parsed[:platform]
39     assert_equal "test", social_link.parsed[:name]
40   end
41
42   def test_parsed_platform_custom_name
43     social_link = create(:social_link, :url => "https://discord.com/users/0")
44
45     assert_equal "discord", social_link.parsed[:platform]
46     assert_equal "Discord", social_link.parsed[:name]
47   end
48
49   def test_parsed_platform_mastodon
50     social_link = create(:social_link, :url => "https://mastodon.social/@test")
51
52     assert_equal "mastodon", social_link.parsed[:platform]
53     assert_equal "@test@mastodon.social", social_link.parsed[:name]
54   end
55
56   def test_parsed_platform_mastodon_parsed
57     social_link = create(:social_link, :url => "@test@mapstodon.space")
58
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]
62   end
63
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)
68
69     assert_nil social_link.parsed[:platform]
70     assert_equal social_link.parsed[:name], expected
71   end
72 end