3 class ProfilesControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/profile", :method => :get },
9 { :controller => "profiles", :action => "show" }
12 { :path => "/profile", :method => :put },
13 { :controller => "profiles", :action => "update" }
17 assert_redirected_to "/profile"
24 # Updating the description should work
25 put profile_path, :params => { :user => { :description => "new description" } }
26 assert_redirected_to user_path(user)
28 assert_response :success
30 assert_select ".alert-success", /^Profile updated./
31 assert_select "div", "new description"
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)
38 assert_response :success
40 assert_select ".alert-success", /^Profile updated./
42 assert_select "form > fieldset > div > div.col-sm-10 > div.form-check > input[name=avatar_action][checked][value=?]", "keep"
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)
48 assert_response :success
50 assert_select ".alert-success", /^Profile updated./
52 assert_select "form > fieldset > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked][value=?]", "gravatar"
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)
58 assert_response :success
60 assert_select ".alert-success", /^Profile updated./
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
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)
69 assert_response :success
71 assert_select ".alert-success", /^Profile updated./
72 assert_select "a", "test.com/test"