From 6c455b72de34370a8855b4f65dd481ef5fdd3ec4 Mon Sep 17 00:00:00 2001 From: Neil van Beinum Date: Tue, 20 Sep 2016 15:19:42 +0100 Subject: [PATCH] Allow global exports to optionally exclude spam This is the setting by default. --- .../global_export_requests_controller.rb | 6 ++++- .../anonymous_feedback/explore/new.html.erb | 8 ++++++- .../global_export_requests_controller_spec.rb | 3 ++- spec/features/global_export_request_spec.rb | 22 +++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 spec/features/global_export_request_spec.rb diff --git a/app/controllers/anonymous_feedback/global_export_requests_controller.rb b/app/controllers/anonymous_feedback/global_export_requests_controller.rb index 6e995cece..39cce3fde 100644 --- a/app/controllers/anonymous_feedback/global_export_requests_controller.rb +++ b/app/controllers/anonymous_feedback/global_export_requests_controller.rb @@ -11,10 +11,14 @@ def create private def export_request_params - params.permit(:from_date, :to_date).merge(notification_email: current_user.email) + params.permit(:from_date, :to_date).merge(notification_email: current_user.email, exclude_spam: exclude_spam?) end def support_api GdsApi::SupportApi.new(Plek.find("support-api")) end + + def exclude_spam? + !!params.permit(:exclude_spam) + end end diff --git a/app/views/anonymous_feedback/explore/new.html.erb b/app/views/anonymous_feedback/explore/new.html.erb index a8b428031..4f6e8e546 100644 --- a/app/views/anonymous_feedback/explore/new.html.erb +++ b/app/views/anonymous_feedback/explore/new.html.erb @@ -26,7 +26,7 @@ <% end %> <% if can? :request, :global_export_request %> -
+

Total quantity by day

<%= form_tag anonymous_feedback_global_export_requests_path, class: 'well formtastic' do %>
@@ -46,6 +46,12 @@
+ +
+ <%= check_box_tag 'exclude_spam', 1, true %> + <%= label_tag 'exclude_spam', 'Exclude requests marked as spam' %> +
+ <% end %>
diff --git a/spec/controllers/anonymous_feedback/global_export_requests_controller_spec.rb b/spec/controllers/anonymous_feedback/global_export_requests_controller_spec.rb index af68b8e69..7185a48b3 100644 --- a/spec/controllers/anonymous_feedback/global_export_requests_controller_spec.rb +++ b/spec/controllers/anonymous_feedback/global_export_requests_controller_spec.rb @@ -20,11 +20,12 @@ notification_email: user.email, from_date: "1 Aug 2016", to_date: "8 Aug 2016", + exclude_spam: true ) end it "makes a successful create request" do - post :create, from_date: "1 Aug 2016", to_date: "8 Aug 2016" + post :create, from_date: "1 Aug 2016", to_date: "8 Aug 2016", exclude_spam: '1' expect(stub_request).to have_been_made end diff --git a/spec/features/global_export_request_spec.rb b/spec/features/global_export_request_spec.rb new file mode 100644 index 000000000..900dc633d --- /dev/null +++ b/spec/features/global_export_request_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' +require 'gds_api/test_helpers/support_api' + +feature 'Exporting Global CSV of Feedback' do + let(:user) { create :user_who_can_access_everything } + + background do + stub_organisations_list + + login_as user + end + + scenario 'spam is marked to be removed by default' do + visit "/" + + click_link 'Feedback explorer' + + within('.global-export-request') do + expect(page.find(:css, 'input[name="exclude_spam"]')).to be_checked + end + end +end