Add toggle_subscription action to Groups::LabelsController
This commit is contained in:
parent
0aac2e0706
commit
198fe1bfc2
|
@ -1,4 +1,6 @@
|
||||||
class Groups::LabelsController < Groups::ApplicationController
|
class Groups::LabelsController < Groups::ApplicationController
|
||||||
|
include ToggleSubscriptionAction
|
||||||
|
|
||||||
before_action :label, only: [:edit, :update, :destroy]
|
before_action :label, only: [:edit, :update, :destroy]
|
||||||
before_action :authorize_admin_labels!, only: [:new, :create, :edit, :update, :destroy]
|
before_action :authorize_admin_labels!, only: [:new, :create, :edit, :update, :destroy]
|
||||||
before_action :save_previous_label_path, only: [:edit]
|
before_action :save_previous_label_path, only: [:edit]
|
||||||
|
@ -69,6 +71,11 @@ class Groups::LabelsController < Groups::ApplicationController
|
||||||
def label
|
def label
|
||||||
@label ||= @group.labels.find(params[:id])
|
@label ||= @group.labels.find(params[:id])
|
||||||
end
|
end
|
||||||
|
alias_method :subscribable_resource, :label
|
||||||
|
|
||||||
|
def subscribable_project
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
def label_params
|
def label_params
|
||||||
params.require(:label).permit(:title, :description, :color)
|
params.require(:label).permit(:title, :description, :color)
|
||||||
|
|
|
@ -30,7 +30,10 @@ scope(path: 'groups/:group_id', module: :groups, as: :group) do
|
||||||
|
|
||||||
resource :avatar, only: [:destroy]
|
resource :avatar, only: [:destroy]
|
||||||
resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :update, :new, :create]
|
resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :update, :new, :create]
|
||||||
resources :labels, except: [:show], constraints: { id: /\d+/ }
|
|
||||||
|
resources :labels, except: [:show], constraints: { id: /\d+/ } do
|
||||||
|
post :toggle_subscription, on: :member
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Must be last route in this file
|
# Must be last route in this file
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Groups::LabelsController do
|
||||||
|
let(:group) { create(:group) }
|
||||||
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
group.add_owner(user)
|
||||||
|
|
||||||
|
sign_in(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'POST #toggle_subscription' do
|
||||||
|
it 'allows user to toggle subscription on group labels' do
|
||||||
|
label = create(:group_label, group: group)
|
||||||
|
|
||||||
|
post :toggle_subscription, group_id: group.to_param, id: label.to_param
|
||||||
|
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue