Skip to content

Commit

Permalink
Allow global exports to optionally exclude spam
Browse files Browse the repository at this point in the history
This is the setting by default.
  • Loading branch information
neilvanbeinum committed Oct 5, 2016
1 parent 7bfff1c commit 6c455b7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
Expand Up @@ -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
8 changes: 7 additions & 1 deletion app/views/anonymous_feedback/explore/new.html.erb
Expand Up @@ -26,7 +26,7 @@
<% end %>
</div>
<% if can? :request, :global_export_request %>
<div class="col-md-8">
<div class="col-md-8 global-export-request">
<h2>Total quantity by day</h2>
<%= form_tag anonymous_feedback_global_export_requests_path, class: 'well formtastic' do %>
<div class="string input required form-group">
Expand All @@ -46,6 +46,12 @@
<input type="text" name="to_date" id="to-date" class="form-control input-sm" data-module="calendar" data-max-date="0" value="<%= params[:to_date]%>"/>
</span>
</div>

<div class="form-group">
<%= check_box_tag 'exclude_spam', 1, true %>
<%= label_tag 'exclude_spam', 'Exclude requests marked as spam' %>
</div>

<input type="submit" value="Export as CSV" class="btn btn-success" />
<% end %>
</div>
Expand Down
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions 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

0 comments on commit 6c455b7

Please sign in to comment.