]> git.openstreetmap.org Git - rails.git/blob - test/controllers/profiles_controller_test.rb
Remove /edit from profile form path
[rails.git] / test / controllers / profiles_controller_test.rb
1 require "test_helper"
2
3 class ProfilesControllerTest < ActionDispatch::IntegrationTest
4   ##
5   # test all routes which lead to this controller
6   def test_routes
7     assert_routing(
8       { :path => "/profile", :method => :get },
9       { :controller => "profiles", :action => "show" }
10     )
11     assert_routing(
12       { :path => "/profile", :method => :put },
13       { :controller => "profiles", :action => "update" }
14     )
15
16     get "/profile/edit"
17     assert_redirected_to "/profile"
18   end
19
20   def test_update
21     user = create(:user)
22     session_for(user)
23
24     # Updating the description should work
25     put profile_path, :params => { :user => { :description => "new description" } }
26     assert_redirected_to user_path(user)
27     follow_redirect!
28     assert_response :success
29     assert_template :show
30     assert_select ".alert-success", /^Profile updated./
31     assert_select "div", "new description"
32
33     # Changing to an uploaded image should work
34     image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif")
35     put profile_path, :params => { :avatar_action => "new", :user => { :avatar => image, :description => user.description } }
36     assert_redirected_to user_path(user)
37     follow_redirect!
38     assert_response :success
39     assert_template :show
40     assert_select ".alert-success", /^Profile updated./
41     get profile_path
42     assert_select "form > fieldset > div > div.col-sm-10 > div.form-check > input[name=avatar_action][checked][value=?]", "keep"
43
44     # Changing to a gravatar image should work
45     put profile_path, :params => { :avatar_action => "gravatar", :user => { :description => user.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     get profile_path
52     assert_select "form > fieldset > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked][value=?]", "gravatar"
53
54     # Removing the image should work
55     put profile_path, :params => { :avatar_action => "delete", :user => { :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_path
62     assert_select "form > fieldset > div > div.col-sm-10 > div > input[name=avatar_action][checked]", false
63     assert_select "form > fieldset > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked]", false
64
65     # Updating social links should work
66     put profile_path, :params => { :user => { :description => user.description, :social_links_attributes => [{ :url => "https://test.com/test" }] } }
67     assert_redirected_to user_path(user)
68     follow_redirect!
69     assert_response :success
70     assert_template :show
71     assert_select ".alert-success", /^Profile updated./
72     assert_select "a", "test.com/test"
73   end
74 end