Skip to content
Extraits de code Groupes Projets
Valider 07a344d0 rédigé par Steffen van Bergerem's avatar Steffen van Bergerem
Parcourir les fichiers

Disable auto follow back on aspect deletion

parent bec25085
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -44,14 +44,20 @@ class AspectsController < ApplicationController
end
def destroy
@aspect = current_user.aspects.where(:id => params[:id]).first
@aspect = current_user.aspects.where(id: params[:id]).first
begin
if current_user.auto_follow_back && @aspect.id == current_user.auto_follow_back_aspect.id
current_user.update(auto_follow_back: false, auto_follow_back_aspect: nil)
flash[:notice] = I18n.t "aspects.destroy.success_auto_follow_back", name: @aspect.name
else
flash[:notice] = I18n.t "aspects.destroy.success", name: @aspect.name
end
@aspect.destroy
flash[:notice] = I18n.t 'aspects.destroy.success', :name => @aspect.name
rescue ActiveRecord::StatementInvalid => e
flash[:error] = I18n.t 'aspects.destroy.failure', :name => @aspect.name
flash[:error] = I18n.t "aspects.destroy.failure", name: @aspect.name
end
if request.referer.include?('contacts')
redirect_to contacts_path
else
......
......@@ -215,7 +215,8 @@ en:
failure: "Aspect creation failed."
destroy:
success: "%{name} was successfully removed."
failure: "%{name} is not empty and could not be removed."
success_auto_follow_back: "%{name} was successfully removed. You used this aspect to automatically follow back users. Check your user settings to select a new auto follow back aspect."
failure: "%{name} could not be removed."
update:
success: "Your aspect, %{name}, has been successfully edited."
failure: "Your aspect, %{name}, had too long name to be saved."
......
......@@ -112,6 +112,54 @@ describe AspectsController, :type => :controller do
end
end
describe "#destroy" do
before do
@alices_aspect_1 = alice.aspects.create(name: "Contacts")
end
context "with no auto follow back aspect" do
it "destoys the aspect" do
expect(alice.aspects.to_a).to include @alices_aspect_1
post :destroy, id: @alices_aspect_1.id
expect(alice.reload.aspects.to_a).not_to include @alices_aspect_1
end
it "renders a flash message on success" do
post :destroy, id: @alices_aspect_1.id
expect(flash[:notice]).to eq(I18n.t("aspects.destroy.success", name: @alices_aspect_1.name))
expect(flash[:error]).to be_blank
end
end
context "with the aspect set as auto follow back" do
before do
alice.auto_follow_back = true
alice.auto_follow_back_aspect = @alices_aspect_1
alice.save
end
it "destoys the aspect" do
expect(alice.aspects.to_a).to include @alices_aspect_1
post :destroy, id: @alices_aspect_1.id
expect(alice.reload.aspects.to_a).not_to include @alices_aspect_1
end
it "disables auto follow back" do
expect(alice.auto_follow_back).to be(true)
expect(alice.auto_follow_back_aspect).to eq(@alices_aspect_1)
post :destroy, id: @alices_aspect_1.id
expect(alice.auto_follow_back).to be(false)
expect(alice.auto_follow_back_aspect).to eq(nil)
end
it "renders a flash message telling you to set a new auto follow back aspect" do
post :destroy, id: @alices_aspect_1.id
expect(flash[:notice]).to eq(I18n.t("aspects.destroy.success_auto_follow_back", name: @alices_aspect_1.name))
expect(flash[:error]).to be_blank
end
end
end
describe "#toggle_contact_visibility" do
it 'sets contacts visible' do
@alices_aspect_1.contacts_visible = false
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter