diff --git a/app/controllers/aspect_memberships_controller.rb b/app/controllers/aspect_memberships_controller.rb index 68215bc37..77df0fe15 100644 --- a/app/controllers/aspect_memberships_controller.rb +++ b/app/controllers/aspect_memberships_controller.rb @@ -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 diff --git a/app/controllers/blocks_controller.rb b/app/controllers/blocks_controller.rb index dd5cb4ae9..d53ee579b 100644 --- a/app/controllers/blocks_controller.rb +++ b/app/controllers/blocks_controller.rb @@ -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 diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index bde3e2fbb..2e94ffd10 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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 diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 3c4a6b5ee..74c2b6532 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -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 diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb index 402ce7e4d..04927022c 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/invitations_controller.rb @@ -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) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 930ed0b7c..7c3d5a2e7 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -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 diff --git a/app/controllers/poll_participations_controller.rb b/app/controllers/poll_participations_controller.rb index 205f9c2b3..ae8eea835 100644 --- a/app/controllers/poll_participations_controller.rb +++ b/app/controllers/poll_participations_controller.rb @@ -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 diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index f3a320615..e1f754a43 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -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 diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 5033f5a66..5127cea84 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6b7502828..e6dbb3449 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/spec/controllers/aspect_memberships_controller_spec.rb b/spec/controllers/aspect_memberships_controller_spec.rb index 90e706e29..2ff406631 100644 --- a/spec/controllers/aspect_memberships_controller_spec.rb +++ b/spec/controllers/aspect_memberships_controller_spec.rb @@ -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 diff --git a/spec/controllers/blocks_controller_spec.rb b/spec/controllers/blocks_controller_spec.rb index de16662ea..3bf98930c 100644 --- a/spec/controllers/blocks_controller_spec.rb +++ b/spec/controllers/blocks_controller_spec.rb @@ -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 diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index 62fba474c..5d2dcd9ae 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -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)