Replace redirect_to :back with redirect_back

Also remove some unused html responses
This commit is contained in:
Benjamin Neff 2017-08-06 03:45:57 +02:00
parent b8ebb778bf
commit 80c241bc7a
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
13 changed files with 27 additions and 95 deletions

View file

@ -6,7 +6,7 @@
class AspectMembershipsController < ApplicationController
before_action :authenticate_user!
respond_to :html, :json
respond_to :json
def destroy
aspect = current_user.aspects.joins(:aspect_memberships).where(aspect_memberships: {id: params[:id]}).first
@ -33,15 +33,6 @@ class AspectMembershipsController < ApplicationController
render text: membership.errors.full_messages, status: 403
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
@ -58,22 +49,12 @@ class AspectMembershipsController < ApplicationController
AspectMembership.where(contact_id: @contact.id, aspect_id: @aspect.id).first)
.base_hash
end
format.all do
flash.now[:notice] = I18n.t("aspects.add_to_aspect.success")
redirect_to :back
end
end
else
respond_to do |format|
format.json do
render text: I18n.t("aspects.add_to_aspect.failure"), status: 409
end
format.all do
flash.now[:error] = I18n.t("aspects.add_to_aspect.failure")
render nothing: true, status: 409
end
end
end
end

View file

@ -1,33 +1,22 @@
class BlocksController < ApplicationController
before_action :authenticate_user!
respond_to :html, :json
respond_to :json
def create
block = current_user.blocks.new(block_params)
if block.save
disconnect_if_contact(block.person)
notice = {:notice => t('blocks.create.success')}
else
notice = {:error => t('blocks.create.failure')}
end
disconnect_if_contact(block.person) if block.save
respond_with do |format|
format.html{ redirect_to :back, notice }
format.json{ render :nothing => true, :status => 204 }
end
end
def destroy
if current_user.blocks.find(params[:id]).delete
notice = {:notice => t('blocks.destroy.success')}
else
notice = {:error => t('blocks.destroy.failure')}
end
current_user.blocks.find(params[:id]).delete
respond_with do |format|
format.html{ redirect_to :back, notice }
format.json{ render :nothing => true, :status => 204 }
end
end

View file

@ -64,7 +64,7 @@ class CommentsController < ApplicationController
def respond_destroy_success
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.json { render nothing: true, status: 204 }
end
@ -72,7 +72,7 @@ class CommentsController < ApplicationController
def respond_destroy_error
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.json { render nothing: true, status: 403 }
end

View file

@ -33,7 +33,7 @@ class HomeController < ApplicationController
def toggle_mobile
session[:mobile_view] = session[:mobile_view].nil? ? true : !session[:mobile_view]
redirect_to :back
redirect_back fallback_location: root_path
end
def force_mobile

View file

@ -42,7 +42,7 @@ class InvitationsController < ApplicationController
t("invitations.create.rejected", emails: invalid_emails.join(", "))
end
redirect_to :back
redirect_back fallback_location: stream_path
end
private
@ -55,7 +55,7 @@ class InvitationsController < ApplicationController
else
t("invitations.create.closed")
end
redirect_to :back
redirect_back fallback_location: stream_path
end
def valid_email?(email)

View file

@ -19,7 +19,7 @@ class PeopleController < ApplicationController
rescue_from Diaspora::AccountClosed do
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
end
end

View file

@ -1,18 +1,15 @@
class PollParticipationsController < ApplicationController
include ApplicationHelper
before_action :authenticate_user!
def create
answer = PollAnswer.find(params[:poll_answer_id])
poll_participation = current_user.participate_in_poll!(target, answer) if target
respond_to do |format|
format.html { redirect_to :back }
format.mobile { redirect_to stream_path }
format.json { render json: poll_participation, :status => 201 }
end
rescue ActiveRecord::RecordInvalid
respond_to do |format|
format.html { redirect_to :back }
format.mobile { redirect_to stream_path }
format.json { render :nothing => true, :status => 403 }
end

View file

@ -1,24 +1,24 @@
class SearchController < ApplicationController
before_action :authenticate_user!
def search
if search_query.starts_with?('#')
if search_query.length > 1
respond_to do |format|
respond_to do |format|
format.json {redirect_to tags_path(:q => search_query.delete("#."))}
format.any {redirect_to tag_path(:name => search_query.delete("#."))}
end
else
flash[:error] = I18n.t('tags.show.none', :name => search_query)
redirect_to :back
redirect_back fallback_location: stream_path
end
else
redirect_to people_path(:q => search_query)
end
end
end
private
def search_query
@search_query ||= (params[:q] || params[:term] || '').strip
end

View file

@ -49,7 +49,6 @@ class StatusMessagesController < ApplicationController
def create
status_message = StatusMessageCreationService.new(current_user).create(normalize_params)
respond_to do |format|
format.html { redirect_to :back }
format.mobile { redirect_to stream_path }
format.json { render json: PostPresenter.new(status_message, current_user), status: 201 }
end
@ -66,7 +65,6 @@ class StatusMessagesController < ApplicationController
def handle_create_error(error)
logger.debug error
respond_to do |format|
format.html { redirect_to :back }
format.mobile { redirect_to stream_path }
format.json { render text: error.message, status: 403 }
end

View file

@ -46,7 +46,7 @@ class UsersController < ApplicationController
flash[:error] = t("users.update.settings_not_updated")
end
redirect_to :back
redirect_back fallback_location: privacy_settings_path
end
def destroy
@ -60,7 +60,7 @@ class UsersController < ApplicationController
else
flash[:error] = t "users.destroy.no_password"
end
redirect_to :back
redirect_back fallback_location: edit_user_path
end
end

View file

@ -44,12 +44,6 @@ describe AspectMembershipsController, type: :controller do
}.by(1)
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
params = {format: :json, person_id: @person.id, aspect_id: @aspect0.id}
post :create, params
@ -84,14 +78,6 @@ describe AspectMembershipsController, type: :controller do
expect(@aspect1.contacts.to_a).not_to include @contact
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
delete :destroy, format: :json, id: 123
expect(response).not_to be_success

View file

@ -6,25 +6,18 @@ describe BlocksController, :type => :controller do
describe "#create" do
it "creates a block" do
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)
end
it "redirects back" do
post :create, :block => { :person_id => 2 }
expect(response).to be_redirect
end
it "notifies the user" do
post :create, :block => { :person_id => 2 }
expect(flash).not_to be_empty
it "responds with 204" do
post :create, format: :json, block: {person_id: eve.person.id}
expect(response.status).to eq(204)
end
it "calls #disconnect_if_contact" do
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
@ -33,14 +26,14 @@ describe BlocksController, :type => :controller do
@block = alice.blocks.create(:person => eve.person)
end
it "redirects back" do
delete :destroy, :id => @block.id
expect(response).to be_redirect
it "responds with 204" do
delete :destroy, format: :json, id: @block.id
expect(response.status).to eq(204)
end
it "removes a block" do
expect {
delete :destroy, :id => @block.id
delete :destroy, format: :json, id: @block.id
}.to change { alice.blocks.count }.by(-1)
end
end

View file

@ -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
post :create, status_message_hash.merge(:format => 'json')
expect(response.status).to eq(201)