]> git.openstreetmap.org Git - rails.git/blob - test/controllers/profiles/descriptions_controller_test.rb
Move profile image editing to image page
[rails.git] / test / controllers / profiles / descriptions_controller_test.rb
1 require "test_helper"
2
3 module Profiles
4   class DescriptionsControllerTest < ActionDispatch::IntegrationTest
5     ##
6     # test all routes which lead to this controller
7     def test_routes
8       assert_routing(
9         { :path => "/profile/description", :method => :get },
10         { :controller => "profiles/descriptions", :action => "show" }
11       )
12       assert_routing(
13         { :path => "/profile/description", :method => :put },
14         { :controller => "profiles/descriptions", :action => "update" }
15       )
16
17       get "/profile"
18       assert_redirected_to "/profile/description"
19
20       get "/profile/edit"
21       assert_redirected_to "/profile/description"
22     end
23
24     def test_show
25       user = create(:user)
26       session_for(user)
27
28       get profile_description_path
29
30       assert_response :success
31       assert_template :show
32     end
33
34     def test_show_unauthorized
35       get profile_description_path
36
37       assert_redirected_to login_path(:referer => profile_description_path)
38     end
39
40     def test_update
41       user = create(:user)
42       session_for(user)
43
44       # Updating the description should work
45       put profile_description_path, :params => { :user => { :description => "new description" } }
46       assert_redirected_to user_path(user)
47       follow_redirect!
48       assert_response :success
49       assert_template :show
50       assert_select ".alert-success", /^Profile updated./
51       assert_select "div", "new description"
52
53       # Updating social links should work
54       put profile_description_path, :params => { :user => { :description => user.description, :social_links_attributes => [{ :url => "https://test.com/test" }] } }
55       assert_redirected_to user_path(user)
56       follow_redirect!
57       assert_response :success
58       assert_template :show
59       assert_select ".alert-success", /^Profile updated./
60       assert_select "a", "test.com/test"
61     end
62
63     def test_update_empty_social_link
64       user = create(:user)
65       session_for(user)
66
67       put profile_description_path, :params => { :user => { :description => user.description, :social_links_attributes => [{ :url => "" }] } }
68
69       assert_response :success
70       assert_template :show
71       assert_dom ".alert-danger", :text => "Couldn't update profile."
72     end
73   end
74 end