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