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

Return error when unlike failed

parent de789267
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -31,7 +31,12 @@ class LikesController < ApplicationController
  end

  def destroy
    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|
+2 −0
Original line number Diff line number Diff line
@@ -591,6 +591,8 @@ en:
  likes:
    create:
      error: "Failed to like."
    destroy:
      error: "Failed to unlike."

  notifications:
    started_sharing:
+3 −5
Original line number Diff line number Diff line
@@ -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