From 3fad6e131664f4bbbe52f1202cababc31cdc3e86 Mon Sep 17 00:00:00 2001 From: masarakki Date: Mon, 16 Apr 2018 18:22:19 +0900 Subject: [PATCH] fix-destroy-emoji --- app/controllers/api/v1/custom_emojis_controller.rb | 2 +- .../api/v1/custom_emojis_controller_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/custom_emojis_controller.rb b/app/controllers/api/v1/custom_emojis_controller.rb index 99a464657ce3e3..ba69d42feb4766 100644 --- a/app/controllers/api/v1/custom_emojis_controller.rb +++ b/app/controllers/api/v1/custom_emojis_controller.rb @@ -31,6 +31,6 @@ def resource_params end def set_custom_emoji - @custom_emoji = CustomEmoji.find(params[:id]) + @custom_emoji = CustomEmoji.local.find_by(shortcode: params[:id]) end end diff --git a/spec/controllers/api/v1/custom_emojis_controller_spec.rb b/spec/controllers/api/v1/custom_emojis_controller_spec.rb index 9f3522812b742e..33b26788d7e082 100644 --- a/spec/controllers/api/v1/custom_emojis_controller_spec.rb +++ b/spec/controllers/api/v1/custom_emojis_controller_spec.rb @@ -15,4 +15,16 @@ expect(response).to have_http_status(:success) end end + + describe 'DELETE #destroy' do + let(:user) { Fabricate(:user, admin: true) } + before { sign_in user } + let!(:custom_emoji) { Fabricate(:custom_emoji) } + subject { delete :destroy, params: { id: custom_emoji.shortcode } } + it { expect { subject }.to change { CustomEmoji.count }.by(-1) } + it do + subject + expect(response).to have_http_status(:success) + end + end end