]> git.openstreetmap.org Git - rails.git/blob - test/controllers/profiles/descriptions_controller_test.rb
Move profile company editing to company 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       # Changing to an uploaded image should work
54       image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif")
55       put profile_description_path, :params => { :avatar_action => "new", :user => { :avatar => image, :description => user.description } }
56       assert_redirected_to user_path(user)
57       follow_redirect!
58       assert_response :success
59       assert_template :show
60       assert_select ".alert-success", /^Profile updated./
61       get profile_description_path
62       assert_select "form > fieldset > div > div.col-sm-10 > div.form-check > input[name=avatar_action][checked][value=?]", "keep"
63
64       # Changing to a gravatar image should work
65       put profile_description_path, :params => { :avatar_action => "gravatar", :user => { :description => user.description } }
66       assert_redirected_to user_path(user)
67       follow_redirect!
68       assert_response :success
69       assert_template :show
70       assert_select ".alert-success", /^Profile updated./
71       get profile_description_path
72       assert_select "form > fieldset > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked][value=?]", "gravatar"
73
74       # Removing the image should work
75       put profile_description_path, :params => { :avatar_action => "delete", :user => { :description => user.description } }
76       assert_redirected_to user_path(user)
77       follow_redirect!
78       assert_response :success
79       assert_template :show
80       assert_select ".alert-success", /^Profile updated./
81       get profile_description_path
82       assert_select "form > fieldset > div > div.col-sm-10 > div > input[name=avatar_action][checked]", false
83       assert_select "form > fieldset > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked]", false
84
85       # Updating social links should work
86       put profile_description_path, :params => { :user => { :description => user.description, :social_links_attributes => [{ :url => "https://test.com/test" }] } }
87       assert_redirected_to user_path(user)
88       follow_redirect!
89       assert_response :success
90       assert_template :show
91       assert_select ".alert-success", /^Profile updated./
92       assert_select "a", "test.com/test"
93     end
94
95     def test_update_empty_social_link
96       user = create(:user)
97       session_for(user)
98
99       put profile_description_path, :params => { :user => { :description => user.description, :social_links_attributes => [{ :url => "" }] } }
100
101       assert_response :success
102       assert_template :show
103       assert_dom ".alert-danger", :text => "Couldn't update profile."
104     end
105   end
106 end