diff --git a/Changelog.md b/Changelog.md index bbcab03c5..3de3e3bd8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -78,6 +78,7 @@ This is disabled by default since it requires the installation of additional pac * Replace `opengraph_parser` with `open_graph_reader` [#5462](https://github.com/diaspora/diaspora/pull/5462) * Make sure conversations without any visibilities left are deleted [#5478](https://github.com/diaspora/diaspora/pull/5478) * Change tooltip for delete button in conversations view [#5477](https://github.com/diaspora/diaspora/pull/5477) +* Replace a modifier-rescue with a specific rescue [#5491](https://github.com/diaspora/diaspora/pull/5491) ## Bug fixes * orca cannot see 'Add Contact' button [#5158](https://github.com/diaspora/diaspora/pull/5158) diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index c5750bee5..adf92827e 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -11,7 +11,13 @@ class LikesController < ApplicationController :json def create - @like = current_user.like!(target) if target rescue ActiveRecord::RecordInvalid + begin + @like = if target + current_user.like!(target) + end + rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid => e + # do nothing + end if @like respond_to do |format| diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index 7cc8d3d39..406116a1c 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -72,6 +72,22 @@ describe LikesController, :type => :controller do expect(response.code).to eq('422') end end + + context "when an the exception is raised" do + it "should be catched when it means that the target is not found" do + allow(@target).to receive(:id).and_return(-1) + post :create, like_hash.merge(:format => :json) + expect(response.code).to eq('422') + end + + it "should not be catched when it is unexpected" do + @target = alice.post :status_message, :text => "AWESOME", :to => @alices_aspect.id + @target = alice.comment!(@target, "hey") if class_const == Comment + allow(alice).to receive(:like!).and_raise("something") + allow(@controller).to receive(:current_user).and_return(alice) + expect { post :create, like_hash.merge(:format => :json) }.to raise_error("something") + end + end end describe '#index' do