]> git.openstreetmap.org Git - rails.git/blob - test/controllers/profiles/links_controller_test.rb
Merge pull request #6394 from openstreetmap/dependabot/github_actions/ruby/setup...
[rails.git] / test / controllers / profiles / links_controller_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 module Profiles
6   class LinksControllerTest < ActionDispatch::IntegrationTest
7     ##
8     # test all routes which lead to this controller
9     def test_routes
10       assert_routing(
11         { :path => "/profile/links", :method => :get },
12         { :controller => "profiles/links", :action => "show" }
13       )
14       assert_routing(
15         { :path => "/profile/links", :method => :put },
16         { :controller => "profiles/links", :action => "update" }
17       )
18     end
19
20     def test_show
21       user = create(:user)
22       session_for(user)
23
24       get profile_links_path
25
26       assert_response :success
27       assert_template :show
28     end
29
30     def test_show_unauthorized
31       get profile_links_path
32
33       assert_redirected_to login_path(:referer => profile_links_path)
34     end
35
36     def test_update
37       user = create(:user)
38       session_for(user)
39
40       put profile_links_path, :params => { :user => { :social_links_attributes => [{ :url => "https://test.com/test" }] } }
41
42       assert_redirected_to user_path(user)
43       follow_redirect!
44       assert_response :success
45       assert_template :show
46       assert_dom ".alert-success", :text => "Profile links updated."
47       assert_dom "a[href*='test.com/test'] span", "test.com/test"
48     end
49
50     def test_update_empty_social_link
51       user = create(:user)
52       session_for(user)
53
54       put profile_links_path, :params => { :user => { :social_links_attributes => [{ :url => "" }] } }
55
56       assert_response :success
57       assert_template :show
58       assert_dom ".alert-danger", :text => "Couldn't update profile links."
59     end
60   end
61 end