Skip to content
Extraits de code Groupes Projets
Non vérifiée Valider 80c241bc rédigé par Benjamin Neff's avatar Benjamin Neff
Parcourir les fichiers

Replace `redirect_to :back` with `redirect_back`

Also remove some unused html responses
parent b8ebb778
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 27 ajouts et 95 suppressions
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
class AspectMembershipsController < ApplicationController class AspectMembershipsController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
respond_to :html, :json respond_to :json
def destroy def destroy
aspect = current_user.aspects.joins(:aspect_memberships).where(aspect_memberships: {id: params[:id]}).first aspect = current_user.aspects.joins(:aspect_memberships).where(aspect_memberships: {id: params[:id]}).first
...@@ -33,15 +33,6 @@ class AspectMembershipsController < ApplicationController ...@@ -33,15 +33,6 @@ class AspectMembershipsController < ApplicationController
render text: membership.errors.full_messages, status: 403 render text: membership.errors.full_messages, status: 403
end end
end end
format.all do
if success
flash.now[:notice] = I18n.t "aspect_memberships.destroy.success"
else
flash.now[:error] = I18n.t "aspect_memberships.destroy.failure"
end
redirect_to :back
end
end end
end end
...@@ -58,22 +49,12 @@ class AspectMembershipsController < ApplicationController ...@@ -58,22 +49,12 @@ class AspectMembershipsController < ApplicationController
AspectMembership.where(contact_id: @contact.id, aspect_id: @aspect.id).first) AspectMembership.where(contact_id: @contact.id, aspect_id: @aspect.id).first)
.base_hash .base_hash
end end
format.all do
flash.now[:notice] = I18n.t("aspects.add_to_aspect.success")
redirect_to :back
end
end end
else else
respond_to do |format| respond_to do |format|
format.json do format.json do
render text: I18n.t("aspects.add_to_aspect.failure"), status: 409 render text: I18n.t("aspects.add_to_aspect.failure"), status: 409
end end
format.all do
flash.now[:error] = I18n.t("aspects.add_to_aspect.failure")
render nothing: true, status: 409
end
end end
end end
end end
......
class BlocksController < ApplicationController class BlocksController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
respond_to :html, :json respond_to :json
def create def create
block = current_user.blocks.new(block_params) block = current_user.blocks.new(block_params)
if block.save disconnect_if_contact(block.person) if block.save
disconnect_if_contact(block.person)
notice = {:notice => t('blocks.create.success')}
else
notice = {:error => t('blocks.create.failure')}
end
respond_with do |format| respond_with do |format|
format.html{ redirect_to :back, notice }
format.json{ render :nothing => true, :status => 204 } format.json{ render :nothing => true, :status => 204 }
end end
end end
def destroy def destroy
if current_user.blocks.find(params[:id]).delete current_user.blocks.find(params[:id]).delete
notice = {:notice => t('blocks.destroy.success')}
else
notice = {:error => t('blocks.destroy.failure')}
end
respond_with do |format| respond_with do |format|
format.html{ redirect_to :back, notice }
format.json{ render :nothing => true, :status => 204 } format.json{ render :nothing => true, :status => 204 }
end end
end end
......
...@@ -64,7 +64,7 @@ class CommentsController < ApplicationController ...@@ -64,7 +64,7 @@ class CommentsController < ApplicationController
def respond_destroy_success def respond_destroy_success
respond_to do |format| respond_to do |format|
format.mobile { redirect_to :back } format.mobile { redirect_back fallback_location: stream_path }
format.js { render nothing: true, status: 204 } format.js { render nothing: true, status: 204 }
format.json { render nothing: true, status: 204 } format.json { render nothing: true, status: 204 }
end end
...@@ -72,7 +72,7 @@ class CommentsController < ApplicationController ...@@ -72,7 +72,7 @@ class CommentsController < ApplicationController
def respond_destroy_error def respond_destroy_error
respond_to do |format| respond_to do |format|
format.mobile { redirect_to :back } format.mobile { redirect_back fallback_location: stream_path }
format.js { render nothing: true, status: 403 } format.js { render nothing: true, status: 403 }
format.json { render nothing: true, status: 403 } format.json { render nothing: true, status: 403 }
end end
......
...@@ -33,7 +33,7 @@ class HomeController < ApplicationController ...@@ -33,7 +33,7 @@ class HomeController < ApplicationController
def toggle_mobile def toggle_mobile
session[:mobile_view] = session[:mobile_view].nil? ? true : !session[:mobile_view] session[:mobile_view] = session[:mobile_view].nil? ? true : !session[:mobile_view]
redirect_to :back redirect_back fallback_location: root_path
end end
def force_mobile def force_mobile
......
...@@ -42,7 +42,7 @@ class InvitationsController < ApplicationController ...@@ -42,7 +42,7 @@ class InvitationsController < ApplicationController
t("invitations.create.rejected", emails: invalid_emails.join(", ")) t("invitations.create.rejected", emails: invalid_emails.join(", "))
end end
redirect_to :back redirect_back fallback_location: stream_path
end end
private private
...@@ -55,7 +55,7 @@ class InvitationsController < ApplicationController ...@@ -55,7 +55,7 @@ class InvitationsController < ApplicationController
else else
t("invitations.create.closed") t("invitations.create.closed")
end end
redirect_to :back redirect_back fallback_location: stream_path
end end
def valid_email?(email) def valid_email?(email)
......
...@@ -19,7 +19,7 @@ class PeopleController < ApplicationController ...@@ -19,7 +19,7 @@ class PeopleController < ApplicationController
rescue_from Diaspora::AccountClosed do rescue_from Diaspora::AccountClosed do
respond_to do |format| respond_to do |format|
format.any { redirect_to :back, :notice => t("people.show.closed_account") } format.any { redirect_back fallback_location: root_path, notice: t("people.show.closed_account") }
format.json { render :nothing => true, :status => 410 } # 410 GONE format.json { render :nothing => true, :status => 410 } # 410 GONE
end end
end end
......
class PollParticipationsController < ApplicationController class PollParticipationsController < ApplicationController
include ApplicationHelper
before_action :authenticate_user! before_action :authenticate_user!
def create def create
answer = PollAnswer.find(params[:poll_answer_id]) answer = PollAnswer.find(params[:poll_answer_id])
poll_participation = current_user.participate_in_poll!(target, answer) if target poll_participation = current_user.participate_in_poll!(target, answer) if target
respond_to do |format| respond_to do |format|
format.html { redirect_to :back }
format.mobile { redirect_to stream_path } format.mobile { redirect_to stream_path }
format.json { render json: poll_participation, :status => 201 } format.json { render json: poll_participation, :status => 201 }
end end
rescue ActiveRecord::RecordInvalid rescue ActiveRecord::RecordInvalid
respond_to do |format| respond_to do |format|
format.html { redirect_to :back }
format.mobile { redirect_to stream_path } format.mobile { redirect_to stream_path }
format.json { render :nothing => true, :status => 403 } format.json { render :nothing => true, :status => 403 }
end end
......
class SearchController < ApplicationController class SearchController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
def search def search
if search_query.starts_with?('#') if search_query.starts_with?('#')
if search_query.length > 1 if search_query.length > 1
respond_to do |format| respond_to do |format|
format.json {redirect_to tags_path(:q => search_query.delete("#."))} format.json {redirect_to tags_path(:q => search_query.delete("#."))}
format.any {redirect_to tag_path(:name => search_query.delete("#."))} format.any {redirect_to tag_path(:name => search_query.delete("#."))}
end end
else else
flash[:error] = I18n.t('tags.show.none', :name => search_query) flash[:error] = I18n.t('tags.show.none', :name => search_query)
redirect_to :back redirect_back fallback_location: stream_path
end end
else else
redirect_to people_path(:q => search_query) redirect_to people_path(:q => search_query)
end end
end end
private private
def search_query def search_query
@search_query ||= (params[:q] || params[:term] || '').strip @search_query ||= (params[:q] || params[:term] || '').strip
end end
......
...@@ -49,7 +49,6 @@ class StatusMessagesController < ApplicationController ...@@ -49,7 +49,6 @@ class StatusMessagesController < ApplicationController
def create def create
status_message = StatusMessageCreationService.new(current_user).create(normalize_params) status_message = StatusMessageCreationService.new(current_user).create(normalize_params)
respond_to do |format| respond_to do |format|
format.html { redirect_to :back }
format.mobile { redirect_to stream_path } format.mobile { redirect_to stream_path }
format.json { render json: PostPresenter.new(status_message, current_user), status: 201 } format.json { render json: PostPresenter.new(status_message, current_user), status: 201 }
end end
...@@ -66,7 +65,6 @@ class StatusMessagesController < ApplicationController ...@@ -66,7 +65,6 @@ class StatusMessagesController < ApplicationController
def handle_create_error(error) def handle_create_error(error)
logger.debug error logger.debug error
respond_to do |format| respond_to do |format|
format.html { redirect_to :back }
format.mobile { redirect_to stream_path } format.mobile { redirect_to stream_path }
format.json { render text: error.message, status: 403 } format.json { render text: error.message, status: 403 }
end end
......
...@@ -46,7 +46,7 @@ class UsersController < ApplicationController ...@@ -46,7 +46,7 @@ class UsersController < ApplicationController
flash[:error] = t("users.update.settings_not_updated") flash[:error] = t("users.update.settings_not_updated")
end end
redirect_to :back redirect_back fallback_location: privacy_settings_path
end end
def destroy def destroy
...@@ -60,7 +60,7 @@ class UsersController < ApplicationController ...@@ -60,7 +60,7 @@ class UsersController < ApplicationController
else else
flash[:error] = t "users.destroy.no_password" flash[:error] = t "users.destroy.no_password"
end end
redirect_to :back redirect_back fallback_location: edit_user_path
end end
end end
......
...@@ -44,12 +44,6 @@ describe AspectMembershipsController, type: :controller do ...@@ -44,12 +44,6 @@ describe AspectMembershipsController, type: :controller do
}.by(1) }.by(1)
end end
it "failure flashes error" do
expect(alice).to receive(:share_with).and_return(nil)
post :create, format: :mobile, person_id: @person.id, aspect_id: @aspect0.id
expect(flash[:error]).not_to be_blank
end
it "does not 500 on a duplicate key error" do it "does not 500 on a duplicate key error" do
params = {format: :json, person_id: @person.id, aspect_id: @aspect0.id} params = {format: :json, person_id: @person.id, aspect_id: @aspect0.id}
post :create, params post :create, params
...@@ -84,14 +78,6 @@ describe AspectMembershipsController, type: :controller do ...@@ -84,14 +78,6 @@ describe AspectMembershipsController, type: :controller do
expect(@aspect1.contacts.to_a).not_to include @contact expect(@aspect1.contacts.to_a).not_to include @contact
end end
it "does not 500 on an html request" do
membership = alice.add_contact_to_aspect(@contact, @aspect1)
delete :destroy, id: membership.id
expect(response).to redirect_to :back
@aspect1.reload
expect(@aspect1.contacts.to_a).not_to include @contact
end
it "aspect membership does not exist" do it "aspect membership does not exist" do
delete :destroy, format: :json, id: 123 delete :destroy, format: :json, id: 123
expect(response).not_to be_success expect(response).not_to be_success
......
...@@ -6,25 +6,18 @@ describe BlocksController, :type => :controller do ...@@ -6,25 +6,18 @@ describe BlocksController, :type => :controller do
describe "#create" do describe "#create" do
it "creates a block" do it "creates a block" do
expect { expect {
post :create, :block => {:person_id => eve.person.id} post :create, format: :json, block: {person_id: eve.person.id}
}.to change { alice.blocks.count }.by(1) }.to change { alice.blocks.count }.by(1)
end end
it "redirects back" do it "responds with 204" do
post :create, :block => { :person_id => 2 } post :create, format: :json, block: {person_id: eve.person.id}
expect(response.status).to eq(204)
expect(response).to be_redirect
end
it "notifies the user" do
post :create, :block => { :person_id => 2 }
expect(flash).not_to be_empty
end end
it "calls #disconnect_if_contact" do it "calls #disconnect_if_contact" do
expect(@controller).to receive(:disconnect_if_contact).with(bob.person) expect(@controller).to receive(:disconnect_if_contact).with(bob.person)
post :create, :block => {:person_id => bob.person.id} post :create, format: :json, block: {person_id: bob.person.id}
end end
end end
...@@ -33,14 +26,14 @@ describe BlocksController, :type => :controller do ...@@ -33,14 +26,14 @@ describe BlocksController, :type => :controller do
@block = alice.blocks.create(:person => eve.person) @block = alice.blocks.create(:person => eve.person)
end end
it "redirects back" do it "responds with 204" do
delete :destroy, :id => @block.id delete :destroy, format: :json, id: @block.id
expect(response).to be_redirect expect(response.status).to eq(204)
end end
it "removes a block" do it "removes a block" do
expect { expect {
delete :destroy, :id => @block.id delete :destroy, format: :json, id: @block.id
}.to change { alice.blocks.count }.by(-1) }.to change { alice.blocks.count }.by(-1)
end end
end end
......
...@@ -55,18 +55,6 @@ describe StatusMessagesController, :type => :controller do ...@@ -55,18 +55,6 @@ describe StatusMessagesController, :type => :controller do
} }
} }
it 'creates with valid html' do
post :create, status_message_hash
expect(response.status).to eq(302)
expect(response).to be_redirect
end
it 'creates with invalid html' do
post :create, status_message_hash.merge(:status_message => { :text => "0123456789" * 7000 })
expect(response.status).to eq(302)
expect(response).to be_redirect
end
it 'creates with valid json' do it 'creates with valid json' do
post :create, status_message_hash.merge(:format => 'json') post :create, status_message_hash.merge(:format => 'json')
expect(response.status).to eq(201) expect(response.status).to eq(201)
......
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