]> git.openstreetmap.org Git - rails.git/blob - test/controllers/profiles_controller_test.rb
Merge remote-tracking branch 'upstream/pull/4747'
[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/edit", :method => :get },
9       { :controller => "profiles", :action => "edit" }
10     )
11
12     assert_routing(
13       { :path => "/profile", :method => :put },
14       { :controller => "profiles", :action => "update" }
15     )
16   end
17
18   def test_update
19     user = create(:user)
20     session_for(user)
21
22     # Updating the description should work
23     put profile_path, :params => { :user => { :description => "new description" } }
24     assert_redirected_to user_path(user)
25     follow_redirect!
26     assert_response :success
27     assert_template :show
28     assert_select ".alert-success", /^Profile updated./
29     assert_select "div", "new description"
30
31     # Changing to an uploaded image should work
32     image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif")
33     put profile_path, :params => { :avatar_action => "new", :user => { :avatar => image, :description => user.description } }
34     assert_redirected_to user_path(user)
35     follow_redirect!
36     assert_response :success
37     assert_template :show
38     assert_select ".alert-success", /^Profile updated./
39     get edit_profile_path
40     assert_select "form > fieldset > div > div.col-sm-10 > div.form-check > input[name=avatar_action][checked][value=?]", "keep"
41
42     # Changing to a gravatar image should work
43     put profile_path, :params => { :avatar_action => "gravatar", :user => { :description => user.description } }
44     assert_redirected_to user_path(user)
45     follow_redirect!
46     assert_response :success
47     assert_template :show
48     assert_select ".alert-success", /^Profile updated./
49     get edit_profile_path
50     assert_select "form > fieldset > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked][value=?]", "gravatar"
51
52     # Removing the image should work
53     put profile_path, :params => { :avatar_action => "delete", :user => { :description => user.description } }
54     assert_redirected_to user_path(user)
55     follow_redirect!
56     assert_response :success
57     assert_template :show
58     assert_select ".alert-success", /^Profile updated./
59     get edit_profile_path
60     assert_select "form > fieldset > div > div.col-sm-10 > div > input[name=avatar_action][checked]", false
61     assert_select "form > fieldset > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked]", false
62   end
63 end