Replace redirect_to :back with redirect_back
Also remove some unused html responses
This commit is contained in:
parent
b8ebb778bf
commit
80c241bc7a
13 changed files with 27 additions and 95 deletions
|
|
@ -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
|
||||||
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
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,22 @@
|
||||||
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
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
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
|
||||||
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
|
||||||
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
|
||||||
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
|
||||||
|
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,15 @@
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ class SearchController < ApplicationController
|
||||||
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)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
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
|
||||||
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
|
||||||
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
|
||||||
}.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
|
||||||
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
|
||||||
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
|
||||||
@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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue