From a4d1ad160c76d79227e8bf7e33637084abd31bec Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Wed, 16 Aug 2017 00:17:21 +0200 Subject: [PATCH 1/4] Fix stop ignoring from privacy settings and on mobile Fixes #7541 --- app/controllers/blocks_controller.rb | 13 ++++++++----- app/views/users/privacy_settings.mobile.haml | 4 ++++ spec/controllers/blocks_controller_spec.rb | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/controllers/blocks_controller.rb b/app/controllers/blocks_controller.rb index aa8f43cbb..38da40d14 100644 --- a/app/controllers/blocks_controller.rb +++ b/app/controllers/blocks_controller.rb @@ -1,23 +1,26 @@ class BlocksController < ApplicationController before_action :authenticate_user! - respond_to :json - def create block = current_user.blocks.new(block_params) disconnect_if_contact(block.person) if block.save - respond_with do |format| + respond_to do |format| format.json { head :no_content } end end def destroy - current_user.blocks.find(params[:id]).delete + notice = if current_user.blocks.find(params[:id]).delete + {notice: t("blocks.destroy.success")} + else + {error: t("blocks.destroy.failure")} + end - respond_with do |format| + respond_to do |format| format.json { head :no_content } + format.any { redirect_back notice.merge(fallback_location: privacy_settings_path) } end end diff --git a/app/views/users/privacy_settings.mobile.haml b/app/views/users/privacy_settings.mobile.haml index e37698db9..d4cca2637 100644 --- a/app/views/users/privacy_settings.mobile.haml +++ b/app/views/users/privacy_settings.mobile.haml @@ -2,6 +2,10 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. +- flash.each do |name, msg| + .alert{class: "alert-#{flash_class name}", role: "alert"} + = msg + - content_for :page_title do = t(".title") diff --git a/spec/controllers/blocks_controller_spec.rb b/spec/controllers/blocks_controller_spec.rb index 93970e892..31da9a9f6 100644 --- a/spec/controllers/blocks_controller_spec.rb +++ b/spec/controllers/blocks_controller_spec.rb @@ -26,11 +26,26 @@ describe BlocksController, :type => :controller do @block = alice.blocks.create(:person => eve.person) end - it "responds with 204" do + it "redirects back" do + delete :destroy, params: {id: @block.id} + expect(response).to be_redirect + end + + it "notifies the user" do + delete :destroy, params: {id: @block.id} + expect(flash).not_to be_empty + end + + it "responds with 204 with json" do delete :destroy, params: {id: @block.id}, format: :json expect(response.status).to eq(204) end + it "redirects back on mobile" do + delete :destroy, params: {id: @block.id}, format: :mobile + expect(response).to be_redirect + end + it "removes a block" do expect { delete :destroy, params: {id: @block.id}, format: :json From 2d06b2865fc3b97a06f0e7cb450c658f075168e0 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Wed, 16 Aug 2017 19:49:36 +0200 Subject: [PATCH 2/4] Handle when the block to delete doesn't exist closes #7542 --- app/controllers/blocks_controller.rb | 4 ++-- spec/controllers/blocks_controller_spec.rb | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/blocks_controller.rb b/app/controllers/blocks_controller.rb index 38da40d14..7ad4f2e1c 100644 --- a/app/controllers/blocks_controller.rb +++ b/app/controllers/blocks_controller.rb @@ -12,7 +12,7 @@ class BlocksController < ApplicationController end def destroy - notice = if current_user.blocks.find(params[:id]).delete + notice = if current_user.blocks.find_by(id: params[:id])&.delete {notice: t("blocks.destroy.success")} else {error: t("blocks.destroy.failure")} @@ -20,7 +20,7 @@ class BlocksController < ApplicationController respond_to do |format| format.json { head :no_content } - format.any { redirect_back notice.merge(fallback_location: privacy_settings_path) } + format.any { redirect_back fallback_location: privacy_settings_path, flash: notice } end end diff --git a/spec/controllers/blocks_controller_spec.rb b/spec/controllers/blocks_controller_spec.rb index 31da9a9f6..0a774da3a 100644 --- a/spec/controllers/blocks_controller_spec.rb +++ b/spec/controllers/blocks_controller_spec.rb @@ -33,7 +33,7 @@ describe BlocksController, :type => :controller do it "notifies the user" do delete :destroy, params: {id: @block.id} - expect(flash).not_to be_empty + expect(flash[:notice]).to eq(I18n.t("blocks.destroy.success")) end it "responds with 204 with json" do @@ -51,6 +51,11 @@ describe BlocksController, :type => :controller do delete :destroy, params: {id: @block.id}, format: :json }.to change { alice.blocks.count }.by(-1) end + + it "handles when the block to delete doesn't exist" do + delete :destroy, params: {id: -1} + expect(flash[:error]).to eq(I18n.t("blocks.destroy.failure")) + end end describe "#disconnect_if_contact" do From cdc3084990c59c9b29ce00b71706f680673fa909 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Wed, 16 Aug 2017 02:19:05 +0200 Subject: [PATCH 3/4] Wait for stream to load for invitation test --- features/desktop/invitations.feature | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/desktop/invitations.feature b/features/desktop/invitations.feature index eca4ef758..f01e194e3 100644 --- a/features/desktop/invitations.feature +++ b/features/desktop/invitations.feature @@ -52,7 +52,8 @@ Feature: Invitations Scenario: sends an invitation from the stream When I sign in as "alice@alice.alice" - And I press the first "a.invitations-link" within "#no_contacts" + Then I should see "There are no posts to display here yet." within ".no-posts-info" + When I press the first "a.invitations-link" within "#no_contacts" Then I should see "Invite someone to join diaspora*!" within "#invitationsModalLabel" And I fill in the following: | email_inviter_emails | alex@example.com | From b49b33675fc611b0d57606300b531d050b1335a9 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Wed, 16 Aug 2017 02:43:15 +0200 Subject: [PATCH 4/4] Wait for stream to load and deselect each aspect individually closes #7543 --- features/step_definitions/aspects_steps.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/features/step_definitions/aspects_steps.rb b/features/step_definitions/aspects_steps.rb index 8881cd946..39726a308 100644 --- a/features/step_definitions/aspects_steps.rb +++ b/features/step_definitions/aspects_steps.rb @@ -46,8 +46,13 @@ end When /^I select only "([^"]*)" aspect$/ do |aspect_name| click_link "My aspects" + expect(find("#aspect_stream_container")).to have_css(".loader.hidden", visible: false) within("#aspects_list") do - all(".selected").each {|node| node.find(:xpath, "..").click } + all(".selected").each do |node| + aspect_item = node.find(:xpath, "..") + aspect_item.click + expect(aspect_item).to have_no_css ".selected" + end expect(current_scope).to have_no_css ".selected" end step %Q(I select "#{aspect_name}" aspect as well)