diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 5c2c65789..8f9197c3c 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -31,7 +31,12 @@ class LikesController < ApplicationController end def destroy - @like = Like.find_by_id_and_author_id!(params[:id], current_user.person.id) + begin + @like = Like.find_by_id_and_author_id!(params[:id], current_user.person.id) + rescue ActiveRecord::RecordNotFound + render text: I18n.t("likes.destroy.error"), status: 404 + return + end current_user.retract(@like) respond_to do |format| diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 6fa0ba688..b41a72035 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -591,6 +591,8 @@ en: likes: create: error: "Failed to like." + destroy: + error: "Failed to unlike." notifications: started_sharing: diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index 2aa04680e..928b1f64c 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -133,14 +133,12 @@ describe LikesController, :type => :controller do it 'does not let a user destroy other likes' do like2 = eve.like!(@message) - like_count = Like.count - expect { - delete :destroy, :format => :json, id_field => like2.target_id, :id => like2.id - }.to raise_error(ActiveRecord::RecordNotFound) + delete :destroy, :format => :json, id_field => like2.target_id, :id => like2.id + expect(response.status).to eq(404) + expect(response.body).to eq(I18n.t("likes.destroy.error")) expect(Like.count).to eq(like_count) - end end end