Commit b8d3323d authored by Steffen van Bergerem's avatar Steffen van Bergerem Committed by Benjamin Neff

Return error when unlike failed

parent de789267
......@@ -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|
......
......@@ -591,6 +591,8 @@ en:
likes:
create:
error: "Failed to like."
destroy:
error: "Failed to unlike."
notifications:
started_sharing:
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment