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