]> git.openstreetmap.org Git - rails.git/blob - test/controllers/profiles/descriptions_controller_test.rb
Move profile resource to profile/description
[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_update
25       user = create(:user)
26       session_for(user)
27
28       # Updating the description should work
29       put profile_description_path, :params => { :user => { :description => "new description" } }
30       assert_redirected_to user_path(user)
31       follow_redirect!
32       assert_response :success
33       assert_template :show
34       assert_select ".alert-success", /^Profile updated./
35       assert_select "div", "new description"
36
37       # Changing to an uploaded image should work
38       image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif")
39       put profile_description_path, :params => { :avatar_action => "new", :user => { :avatar => image, :description => user.description } }
40       assert_redirected_to user_path(user)
41       follow_redirect!
42       assert_response :success
43       assert_template :show
44       assert_select ".alert-success", /^Profile updated./
45       get profile_description_path
46       assert_select "form > fieldset > div > div.col-sm-10 > div.form-check > input[name=avatar_action][checked][value=?]", "keep"
47
48       # Changing to a gravatar image should work
49       put profile_description_path, :params => { :avatar_action => "gravatar", :user => { :description => user.description } }
50       assert_redirected_to user_path(user)
51       follow_redirect!
52       assert_response :success
53       assert_template :show
54       assert_select ".alert-success", /^Profile updated./
55       get profile_description_path
56       assert_select "form > fieldset > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked][value=?]", "gravatar"
57
58       # Removing the image should work
59       put profile_description_path, :params => { :avatar_action => "delete", :user => { :description => user.description } }
60       assert_redirected_to user_path(user)
61       follow_redirect!
62       assert_response :success
63       assert_template :show
64       assert_select ".alert-success", /^Profile updated./
65       get profile_description_path
66       assert_select "form > fieldset > div > div.col-sm-10 > div > input[name=avatar_action][checked]", false
67       assert_select "form > fieldset > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked]", false
68
69       # Updating social links should work
70       put profile_description_path, :params => { :user => { :description => user.description, :social_links_attributes => [{ :url => "https://test.com/test" }] } }
71       assert_redirected_to user_path(user)
72       follow_redirect!
73       assert_response :success
74       assert_template :show
75       assert_select ".alert-success", /^Profile updated./
76       assert_select "a", "test.com/test"
77
78       # Updating the company name should work
79       put profile_description_path, :params => { :user => { :company => "new company", :description => user.description } }
80       assert_redirected_to user_path(user)
81       follow_redirect!
82       assert_response :success
83       assert_template :show
84       assert_select ".alert-success", /^Profile updated./
85       user.reload
86       assert_equal "new company", user.company
87     end
88
89     def test_update_empty_social_link
90       user = create(:user)
91       session_for(user)
92
93       put profile_description_path, :params => { :user => { :description => user.description, :social_links_attributes => [{ :url => "" }] } }
94
95       assert_response :success
96       assert_template :show
97       assert_dom ".alert-danger", :text => "Couldn't update profile."
98     end
99   end
100 end