Commit b08608b261f8c9c552d8957b6231c7725b9529ac

Authored by Drew Blessing
1 parent e411f3ba

Issue 5716 - Allow removal of avatar

Add class and style

Add spinach tests

Add entry to CHANGELOG

Add entry to CHANGELOG
CHANGELOG
... ... @@ -6,6 +6,7 @@ v 6.4.0
6 6 - Minimal password length increased to 8 symbols
7 7 - Side-by-side diff view (Steven Thonus)
8 8 - Internal projects (Jason Hollingsworth)
  9 + - Allow removal of avatar (Drew Blessing)
9 10  
10 11 v 6.3.0
11 12 - API for adding gitlab-ci service
... ...
app/assets/stylesheets/sections/profile.scss
... ... @@ -42,3 +42,7 @@
42 42 margin-right: 12px;
43 43 }
44 44  
  45 +.remove_avatar {
  46 + margin-top: 10px;
  47 +}
  48 +
... ...
app/controllers/profiles/avatars_controller.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class Profiles::AvatarsController < ApplicationController
  2 + layout "profile"
  3 +
  4 + def destroy
  5 + @user = current_user
  6 + @user.remove_avatar!
  7 +
  8 + @user.save
  9 + redirect_to profile_path
  10 + end
  11 +end
... ...
app/views/profiles/show.html.haml
... ... @@ -59,9 +59,14 @@
59 59 .clearfix
60 60 .profile-avatar-form-option
61 61 %p.light
62   - You can upload an avatar here
63   - %br
64   - or change it at #{link_to "gravatar.com", "http://gravatar.com"}
  62 + - if @user.avatar?
  63 + You can change your avatar here
  64 + %br
  65 + or remove the current avatar to revert to #{link_to "gravatar.com", "http://gravatar.com"}
  66 + - else
  67 + You can upload an avatar here
  68 + %br
  69 + or change it at #{link_to "gravatar.com", "http://gravatar.com"}
65 70 %hr
66 71 %a.choose-btn.btn.btn-small.js-choose-user-avatar-button
67 72 %i.icon-paper-clip
... ... @@ -70,6 +75,8 @@
70 75 %span.file_name.js-avatar-filename File name...
71 76 = f.file_field :avatar, class: "js-user-avatar-input hide"
72 77 %span.help-block The maximum file size allowed is 100KB.
  78 + - if @user.avatar?
  79 + = link_to 'Remove avatar', profile_avatar_path, confirm: "Avatar will be removed. Are you sure?", method: :delete, class: "btn btn-remove remove_avatar"
73 80  
74 81 .form-actions
75 82 - = f.submit 'Save changes', class: "btn btn-save"
  83 + = f.submit 'Save changes', class: "btn btn-save"
76 84 \ No newline at end of file
... ...
config/routes.rb
... ... @@ -127,6 +127,7 @@ Gitlab::Application.routes.draw do
127 127 delete :leave
128 128 end
129 129 end
  130 + resource :avatar, only: [:destroy]
130 131 end
131 132 end
132 133  
... ...
features/profile/profile.feature
... ... @@ -26,6 +26,14 @@ Feature: Profile
26 26 Given I visit profile page
27 27 Then I change my avatar
28 28 And I should see new avatar
  29 + And I should see the "Remove avatar" button
  30 +
  31 + Scenario: I remove my avatar
  32 + Given I visit profile page
  33 + And I have an avatar
  34 + When I remove my avatar
  35 + Then I should see my gravatar
  36 + And I should not see the "Remove avatar" button
29 37  
30 38 Scenario: My password is expired
31 39 Given my password is expired
... ...
features/steps/profile/profile.rb
... ... @@ -31,6 +31,29 @@ class Profile &lt; Spinach::FeatureSteps
31 31 @user.avatar.url.should == "/uploads/user/avatar/#{ @user.id }/gitlab_logo.png"
32 32 end
33 33  
  34 + step 'I should see the "Remove avatar" button' do
  35 + page.should have_link("Remove avatar")
  36 + end
  37 +
  38 + step 'I have an avatar' do
  39 + attach_file(:user_avatar, File.join(Rails.root, 'public', 'gitlab_logo.png'))
  40 + click_button "Save changes"
  41 + @user.reload
  42 + end
  43 +
  44 + step 'I remove my avatar' do
  45 + click_link "Remove avatar"
  46 + @user.reload
  47 + end
  48 +
  49 + step 'I should see my gravatar' do
  50 + @user.avatar?.should be_false
  51 + end
  52 +
  53 + step 'I should not see the "Remove avatar" button' do
  54 + page.should_not have_link("Remove avatar")
  55 + end
  56 +
34 57 step 'I try change my password w/o old one' do
35 58 within '.update-password' do
36 59 fill_in "user_password", with: "22233344"
... ...
spec/routing/routing_spec.rb
... ... @@ -185,6 +185,13 @@ describe Profiles::KeysController, &quot;routing&quot; do
185 185 end
186 186 end
187 187  
  188 +# profile_avatar DELETE /profile/avatar(.:format) profiles/avatars#destroy
  189 +describe Profiles::AvatarsController, "routing" do
  190 + it "to #destroy" do
  191 + delete("/profile/avatar").should route_to('profiles/avatars#destroy')
  192 + end
  193 +end
  194 +
188 195 # dashboard GET /dashboard(.:format) dashboard#show
189 196 # dashboard_issues GET /dashboard/issues(.:format) dashboard#issues
190 197 # dashboard_merge_requests GET /dashboard/merge_requests(.:format) dashboard#merge_requests
... ...