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 get profile_description_path
30 assert_response :success
34 def test_show_unauthorized
35 get profile_description_path
37 assert_redirected_to login_path(:referer => profile_description_path)
44 # Updating the description should work
45 put profile_description_path, :params => { :user => { :description => "new description" } }
46 assert_redirected_to user_path(user)
48 assert_response :success
50 assert_select ".alert-success", /^Profile updated./
51 assert_select "div", "new description"
53 # Changing to an uploaded image should work
54 image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif")
55 put profile_description_path, :params => { :avatar_action => "new", :user => { :avatar => image, :description => user.description } }
56 assert_redirected_to user_path(user)
58 assert_response :success
60 assert_select ".alert-success", /^Profile updated./
61 get profile_description_path
62 assert_select "form > fieldset > div > div.col-sm-10 > div.form-check > input[name=avatar_action][checked][value=?]", "keep"
64 # Changing to a gravatar image should work
65 put profile_description_path, :params => { :avatar_action => "gravatar", :user => { :description => user.description } }
66 assert_redirected_to user_path(user)
68 assert_response :success
70 assert_select ".alert-success", /^Profile updated./
71 get profile_description_path
72 assert_select "form > fieldset > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked][value=?]", "gravatar"
74 # Removing the image should work
75 put profile_description_path, :params => { :avatar_action => "delete", :user => { :description => user.description } }
76 assert_redirected_to user_path(user)
78 assert_response :success
80 assert_select ".alert-success", /^Profile updated./
81 get profile_description_path
82 assert_select "form > fieldset > div > div.col-sm-10 > div > input[name=avatar_action][checked]", false
83 assert_select "form > fieldset > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked]", false
85 # Updating social links should work
86 put profile_description_path, :params => { :user => { :description => user.description, :social_links_attributes => [{ :url => "https://test.com/test" }] } }
87 assert_redirected_to user_path(user)
89 assert_response :success
91 assert_select ".alert-success", /^Profile updated./
92 assert_select "a", "test.com/test"
95 def test_update_empty_social_link
99 put profile_description_path, :params => { :user => { :description => user.description, :social_links_attributes => [{ :url => "" }] } }
101 assert_response :success
102 assert_template :show
103 assert_dom ".alert-danger", :text => "Couldn't update profile."