Commit 053b224390916db91f7e3742dc678fb8e463aa96

Authored by Andrey Subbota
1 parent 8e5a029c
Exists in master and in 1 other branch production

Unsubscribe from app. ref 14873

app/controllers/watchers_controller.rb 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +class WatchersController < ApplicationController
  2 + respond_to :html
  3 +
  4 + before_filter :find_watcher, :only => [:destroy]
  5 + before_filter :require_watcher_edit_priviledges, :only => [:destroy]
  6 +
  7 + def destroy
  8 + @app.watchers.delete(@watcher)
  9 + flash[:success] = "That's sad. #{@watcher.label} is no longer watcher."
  10 + redirect_to root_path
  11 + end
  12 +
  13 + protected
  14 +
  15 + def find_watcher
  16 + @app = App.find(params[:app_id])
  17 + @watcher = @app.watchers.find(params[:id])
  18 + end
  19 +
  20 + def require_watcher_edit_priviledges
  21 + can_edit = current_user == @watcher.user || current_user.admin?
  22 + redirect_to(root_path) and return(false) unless can_edit
  23 + end
  24 +
  25 +end
  26 +
... ...
app/views/apps/show.html.haml
... ... @@ -32,10 +32,14 @@
32 32 %thead
33 33 %tr
34 34 %th User or Email
  35 + %th
35 36 %tbody
36 37 - @app.watchers.each do |watcher|
37 38 %tr
38   - %td= watcher.label
  39 + %td
  40 + = watcher.label
  41 + %td
  42 + = link_to 'unsubscribe', app_watcher_path({:app_id => @app, :id => watcher.id}), :method => :delete, :class => 'button', :confirm => 'Are you sure?'
39 43 - if @app.watchers.none?
40 44 %tr
41 45 %td
... ...
config/routes.rb
... ... @@ -36,8 +36,8 @@ Errbit::Application.routes.draw do
36 36 delete :unlink_issue
37 37 end
38 38 end
39   -
40 39 resources :deploys, :only => [:index]
  40 + resources :watchers, :only => [:destroy]
41 41 end
42 42  
43 43 root :to => 'apps#index'
... ...
spec/controllers/watchers_controller_spec.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +require 'spec_helper'
  2 +
  3 +describe WatchersController do
  4 + let(:app) { Fabricate(:app_with_watcher) }
  5 +
  6 + describe "DELETE /apps/:app_id/watchers/:id/destroy" do
  7 + render_views
  8 +
  9 + before(:each) do
  10 + sign_in Fabricate(:admin)
  11 + end
  12 +
  13 + context "successful comment deletion" do
  14 + let(:problem) { Fabricate(:problem_with_comments) }
  15 + let(:watcher) { app.watchers.first }
  16 +
  17 + before(:each) do
  18 + delete :destroy, :app_id => app.id, :id => watcher.id.to_s
  19 + problem.reload
  20 + end
  21 +
  22 + it "should delete the watcher" do
  23 + app.watchers.detect{|w| w.id.to_s == watcher.id }.should == nil
  24 + end
  25 +
  26 + it "should redirect to index page" do
  27 + response.should redirect_to(root_path)
  28 + end
  29 + end
  30 + end
  31 +end
... ...