4 class DescriptionsControllerTest < ActionDispatch::IntegrationTest
6 # test all routes which lead to this controller
9 { :path => "/profile/description", :method => :get },
10 { :controller => "profiles/descriptions", :action => "show" }
13 { :path => "/profile/description", :method => :put },
14 { :controller => "profiles/descriptions", :action => "update" }
18 assert_redirected_to "/profile/description"
21 assert_redirected_to "/profile/description"
28 # Updating the description should work
29 put profile_description_path, :params => { :user => { :description => "new description" } }
30 assert_redirected_to user_path(user)
32 assert_response :success
34 assert_select ".alert-success", /^Profile updated./
35 assert_select "div", "new description"
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)
42 assert_response :success
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"
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)
52 assert_response :success
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"
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)
62 assert_response :success
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
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)
73 assert_response :success
75 assert_select ".alert-success", /^Profile updated./
76 assert_select "a", "test.com/test"
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)
82 assert_response :success
84 assert_select ".alert-success", /^Profile updated./
86 assert_equal "new company", user.company
89 def test_update_empty_social_link
93 put profile_description_path, :params => { :user => { :description => user.description, :social_links_attributes => [{ :url => "" }] } }
95 assert_response :success
97 assert_dom ".alert-danger", :text => "Couldn't update profile."