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