]> git.openstreetmap.org Git - rails.git/blob - test/controllers/profiles/images_controller_test.rb
Move profile image editing to image page
[rails.git] / test / controllers / profiles / images_controller_test.rb
1 require "test_helper"
2
3 module Profiles
4   class ImagesControllerTest < ActionDispatch::IntegrationTest
5     ##
6     # test all routes which lead to this controller
7     def test_routes
8       assert_routing(
9         { :path => "/profile/image", :method => :get },
10         { :controller => "profiles/images", :action => "show" }
11       )
12       assert_routing(
13         { :path => "/profile/image", :method => :put },
14         { :controller => "profiles/images", :action => "update" }
15       )
16     end
17
18     def test_show
19       user = create(:user)
20       session_for(user)
21
22       get profile_image_path
23
24       assert_response :success
25       assert_template :show
26     end
27
28     def test_show_unauthorized
29       get profile_image_path
30
31       assert_redirected_to login_path(:referer => profile_image_path)
32     end
33
34     def test_update
35       user = create(:user)
36       session_for(user)
37
38       # Changing to an uploaded image should work
39       image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif")
40       put profile_image_path, :params => { :avatar_action => "new", :user => { :avatar => image, :description => user.description } }
41       assert_redirected_to user_path(user)
42       follow_redirect!
43       assert_response :success
44       assert_template :show
45       assert_dom ".alert-success", :text => "Profile updated."
46       get profile_image_path
47       assert_dom "form > div > div.col-sm-10 > div.form-check > input[name=avatar_action][checked][value=?]", "keep"
48
49       # Changing to a gravatar image should work
50       put profile_image_path, :params => { :avatar_action => "gravatar", :user => { :description => user.description } }
51       assert_redirected_to user_path(user)
52       follow_redirect!
53       assert_response :success
54       assert_template :show
55       assert_dom ".alert-success", :text => "Profile updated."
56       get profile_image_path
57       assert_dom "form > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked][value=?]", "gravatar"
58
59       # Removing the image should work
60       put profile_image_path, :params => { :avatar_action => "delete", :user => { :description => user.description } }
61       assert_redirected_to user_path(user)
62       follow_redirect!
63       assert_response :success
64       assert_template :show
65       assert_dom ".alert-success", :text => "Profile updated."
66       get profile_image_path
67       assert_dom "form > div > div.col-sm-10 > div > input[name=avatar_action][checked]", false
68       assert_dom "form > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked]", false
69     end
70   end
71 end