Skip to content

Commit

Permalink
Merge pull request #548 from alphagov/add-gathering-support-page
Browse files Browse the repository at this point in the history
Add gathering support page
  • Loading branch information
alanth authored Oct 18, 2016
2 parents 9f92255 + 8e6c635 commit af93a3e
Show file tree
Hide file tree
Showing 33 changed files with 106 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cache:
directories:
- /home/travis/.phantomjs
rvm:
- 2.2.4
- 2.2.5
services:
- memcached
before_install:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ group :development, :test do
gem 'rspec-rails'
gem 'jasmine-rails'
gem 'pry'
gem 'phantomjs', '~> 1.9.7.0'
gem 'phantomjs', '~> 2.1.1.0'
end

group :test do
Expand Down
20 changes: 9 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ GEM
hashdiff (0.2.3)
i18n (0.7.0)
ipaddress (0.8.2)
jasmine-core (2.3.4)
jasmine-rails (0.12.2)
jasmine-core (2.5.2)
jasmine-rails (0.14.1)
jasmine-core (>= 1.3, < 3.0)
phantomjs (>= 1.9)
railties (>= 3.2.0)
Expand Down Expand Up @@ -177,26 +177,24 @@ GEM
mime-types (2.99.2)
mimemagic (0.3.0)
mini_portile2 (2.1.0)
minitest (5.9.0)
minitest (5.9.1)
multi_json (1.11.2)
multi_test (0.1.2)
multipart-post (2.0.0)
net-http-persistent (2.9.4)
nokogiri (1.6.8)
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
paperclip (4.3.2)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
cocaine (~> 0.5.5)
mime-types
mimemagic (= 0.3.0)
pg (0.18.4)
phantomjs (1.9.7.1)
phantomjs (2.1.1.0)
pickle (0.5.1)
cucumber (>= 0.8)
rake
pkg-config (1.1.7)
poltergeist (1.8.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
Expand Down Expand Up @@ -236,7 +234,7 @@ GEM
activesupport (= 4.2.7.1)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (11.2.2)
rake (11.3.0)
request_store (1.2.1)
responders (2.1.0)
railties (>= 4.2.0, < 5)
Expand Down Expand Up @@ -275,7 +273,7 @@ GEM
sprockets (3.7.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.1.1)
sprockets-rails (3.2.0)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
Expand Down Expand Up @@ -339,7 +337,7 @@ DEPENDENCIES
nokogiri
paperclip
pg
phantomjs (~> 1.9.7.0)
phantomjs (~> 2.1.1.0)
pickle
poltergeist
pry
Expand All @@ -359,4 +357,4 @@ DEPENDENCIES
will_paginate

BUNDLED WITH
1.11.2
1.13.5
19 changes: 14 additions & 5 deletions app/controllers/petitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ class PetitionsController < ApplicationController
before_action :avoid_unknown_state_filters, only: :index
before_action :do_not_cache, except: %i[index show]

before_action :retrieve_petition, only: [:show, :count, :moderation_info]
before_action :redirect_to_moderation_info_url, if: :not_moderated?, only: :show
before_action :redirect_to_petition_url, if: :moderated?, only: :moderation_info
before_action :retrieve_petition, only: [:show, :count, :gathering_support, :moderation_info]
before_action :redirect_to_gathering_support_url, if: :collecting_sponsors?, only: [:moderation_info, :show]
before_action :redirect_to_moderation_info_url, if: :in_moderation?, only: [:gathering_support, :show]
before_action :redirect_to_petition_url, if: :moderated?, only: [:gathering_support, :moderation_info]

before_action :set_cors_headers, only: [:index, :show, :count], if: :json_request?

Expand Down Expand Up @@ -91,8 +92,16 @@ def avoid_unknown_state_filters
redirect_to url_for(params.merge(state: 'all')) unless public_petition_facets.include? params[:state].to_sym
end

def not_moderated?
!@petition.moderated?
def collecting_sponsors?
@petition.collecting_sponsors?
end

def redirect_to_gathering_support_url
redirect_to gathering_support_petition_url(@petition)
end

def in_moderation?
@petition.in_moderation?
end

def redirect_to_moderation_info_url
Expand Down
9 changes: 9 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ApplicationJob < ActiveJob::Base
before_perform :reload_site

private

def reload_site
Site.reload
end
end
2 changes: 1 addition & 1 deletion app/jobs/close_petitions_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ClosePetitionsJob < ActiveJob::Base
class ClosePetitionsJob < ApplicationJob
queue_as :high_priority

def perform(time)
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/debated_petitions_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DebatedPetitionsJob < ActiveJob::Base
class DebatedPetitionsJob < ApplicationJob
queue_as :high_priority

def perform(date)
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/deliver_debate_outcome_email_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DeliverDebateOutcomeEmailJob < ActiveJob::Base
class DeliverDebateOutcomeEmailJob < ApplicationJob
include EmailDelivery

def create_email
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/deliver_debate_scheduled_email_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DeliverDebateScheduledEmailJob < ActiveJob::Base
class DeliverDebateScheduledEmailJob < ApplicationJob
include EmailDelivery

def create_email
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/deliver_petition_email_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DeliverPetitionEmailJob < ActiveJob::Base
class DeliverPetitionEmailJob < ApplicationJob
include EmailDelivery

attr_reader :email
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/deliver_threshold_response_email_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DeliverThresholdResponseEmailJob < ActiveJob::Base
class DeliverThresholdResponseEmailJob < ApplicationJob
include EmailDelivery

def create_email
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/email_debate_outcomes_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class EmailDebateOutcomesJob < ActiveJob::Base
class EmailDebateOutcomesJob < ApplicationJob
include EmailAllPetitionSignatories

self.email_delivery_job_class = DeliverDebateOutcomeEmailJob
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/email_debate_scheduled_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class EmailDebateScheduledJob < ActiveJob::Base
class EmailDebateScheduledJob < ApplicationJob
include EmailAllPetitionSignatories

self.email_delivery_job_class = DeliverDebateScheduledEmailJob
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/email_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class EmailJob < ActiveJob::Base
class EmailJob < ApplicationJob
class_attribute :mailer, :email

PERMANENT_FAILURES = [
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/email_petitioners_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class EmailPetitionersJob < ActiveJob::Base
class EmailPetitionersJob < ApplicationJob
include EmailAllPetitionSignatories

self.email_delivery_job_class = DeliverPetitionEmailJob
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/email_threshold_reminder_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class EmailThresholdReminderJob < ActiveJob::Base
class EmailThresholdReminderJob < ApplicationJob
queue_as :high_priority

def perform
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/email_threshold_response_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class EmailThresholdResponseJob < ActiveJob::Base
class EmailThresholdResponseJob < ApplicationJob
include EmailAllPetitionSignatories

self.email_delivery_job_class = DeliverThresholdResponseEmailJob
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/fetch_country_register_job.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'faraday'

class FetchCountryRegisterJob < ActiveJob::Base
class FetchCountryRegisterJob < ApplicationJob
HOST = 'https://country.register.gov.uk'
ENDPOINT = '/records.json?page-size=500'
TIMEOUT = 5
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/invalidate_signatures_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class InvalidateSignaturesJob < ActiveJob::Base
class InvalidateSignaturesJob < ApplicationJob
queue_as :high_priority

rescue_from(ActiveJob::DeserializationError) do |exception|
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/notify_everyone_of_moderation_decision_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class NotifyEveryoneOfModerationDecisionJob < ActiveJob::Base
class NotifyEveryoneOfModerationDecisionJob < ApplicationJob
rescue_from StandardError do |exception|
Appsignal.send_exception exception
end
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/petition_count_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class PetitionCountJob < ActiveJob::Base
class PetitionCountJob < ApplicationJob
class InvalidSignatureCounts < RuntimeError; end

queue_as :high_priority
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/petition_signed_data_update_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class PetitionSignedDataUpdateJob < ActiveJob::Base
class PetitionSignedDataUpdateJob < ApplicationJob
queue_as :highest_priority

rescue_from(ActiveJob::DeserializationError) do |exception|
Expand Down
5 changes: 5 additions & 0 deletions app/views/petitions/gathering_support.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>This petition is gathering support</h1>

<p><%= @petition.creator_signature.name %>’s petition needs <%= Site.minimum_number_of_sponsors %> supporters before we will check that it meets the <%= link_to "petition standards", help_path(anchor: 'standards') %> and publish it.</p>

<p>Please try again in a few days.</p>
2 changes: 1 addition & 1 deletion app/views/petitions/moderation_info.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

<p><%= Site.minimum_number_of_sponsors %> people have already supported <%= @petition.creator_signature.name %>’s petition.</p>

<p>We need to check it meets the <%= link_to "petition standards", help_url(anchor: 'standards') %> before we publish it.</p>
<p>We need to check it meets the <%= link_to "petition standards", help_path(anchor: 'standards') %> before we publish it.</p>

<p>Please try again in a few days.</p>
8 changes: 4 additions & 4 deletions bin/install_phantomjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
set -x
set -e

if [ ! -e /home/travis/.phantomjs/1.9.7/x86_64-linux/bin/phantomjs ]; then
mkdir -p /home/travis/.phantomjs/1.9.7/x86_64-linux/bin
if [ ! -e /home/travis/.phantomjs/2.1.1/x86_64-linux/bin/phantomjs ]; then
mkdir -p /home/travis/.phantomjs/2.1.1/x86_64-linux/bin
pip install --user awscli
aws s3 cp s3://epetitions-ci/phantomjs /home/travis/.phantomjs/1.9.7/x86_64-linux/bin/phantomjs
chmod ugo+x /home/travis/.phantomjs/1.9.7/x86_64-linux/bin/phantomjs
aws s3 cp s3://epetitions-ci/2.1.1/phantomjs /home/travis/.phantomjs/2.1.1/x86_64-linux/bin/phantomjs
chmod ugo+x /home/travis/.phantomjs/2.1.1/x86_64-linux/bin/phantomjs
fi
3 changes: 2 additions & 1 deletion config/locales/page_titles.en-GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ en-GB:
check: "Start a petition - Petitions"
check_results: "Start a petition - Petitions"
create: "Start a petition - Petitions"
moderation_info: "%{petition} - has been already sent to moderation - Petitions"
gathering_support: "This petition is gathering support - Petitions"
moderation_info: "This petition has been sent to moderation - Petitions"
new: "Start a petition - Petitions"
resend_confirmation_email: "Confirmation email re-sent - Petitions"
show: "%{petition} - Petitions"
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
member do
get 'count', :action => :count, :as => :count
get 'thank-you', :action => :thank_you, :as => :thank_you
get 'gathering-support', :action => :gathering_support, :as => :gathering_support
get 'moderation-info', :action => :moderation_info, :as => :moderation_info
end

Expand Down
16 changes: 2 additions & 14 deletions features/laura_signs_charlies_petition_as_a_sponsor.feature
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,8 @@ Feature: As Laura, a sponsor of my friend Charlie's petition
When I visit the "sponsor this petition" url I was given
And I will see 404 error page

Scenario: Laura is the 21st sponsor that wants to sign the validated petition
Given the petition I want to sign has enough sponsors and is validated
When I visit the "sponsor this petition" url I was given
Then I should be connected to the server via an ssl connection
And I am redirected to the petition moderation info page

Scenario: Laura is the 21st sponsor that wants to sign the sponsored petition
Given the petition I want to sign has enough sponsors and is sponsored
When I visit the "sponsor this petition" url I was given
Then I should be connected to the server via an ssl connection
And I am redirected to the petition moderation info page

Scenario: Laura is the 21st sponsor that wants to sign the pending petition
Given the petition I want to sign has enough sponsors and is pending
Scenario: Laura is the 21st sponsor that wants to sign the petition
Given the petition I want to sign has enough sponsors
When I visit the "sponsor this petition" url I was given
Then I should be connected to the server via an ssl connection
And I am redirected to the petition moderation info page
Expand Down
4 changes: 2 additions & 2 deletions features/step_definitions/sponsor_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
expect(page.status_code).to eq 404
end

Given(/^the petition I want to sign has enough sponsors and is (validated|sponsored|pending)?$/) do |state|
@sponsor_petition = FactoryGirl.create(:open_petition, state: state, sponsor_count: Site.maximum_number_of_sponsors)
Given(/^the petition I want to sign has enough sponsors?$/) do
@sponsor_petition = FactoryGirl.create(:sponsored_petition, sponsor_count: Site.maximum_number_of_sponsors)
end

Then(/^I am redirected to the petition moderation info page$/) do
Expand Down
12 changes: 12 additions & 0 deletions features/suzie_views_a_petition.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ Feature: Suzie views a petition
As Suzie the signer
I want to view a petition of my choice from a list, seeing the vote count, closed and open dates, along with the reason for rejection if applicable

Scenario: Suzie views a petition gathering sponsors
Given a validated petition "Spend more money on Defence"
When I view the petition
Then I should see "This petition is gathering support"
And I should see a link called "petition standards" linking to "/help#standards"

Scenario: Suzie views a petition waiting to be moderated
Given a sponsored petition "Spend more money on Defence"
When I view the petition
Then I should see "We’re checking this petition"
And I should see a link called "petition standards" linking to "/help#standards"

Scenario: Suzie views an open petition
Given an open petition "Spend more money on Defence"
When I view the petition
Expand Down
1 change: 1 addition & 0 deletions spec/controllers/petitions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def do_post(options = {})
describe "show" do
let(:petition) { double }
it "assigns the given petition" do
allow(petition).to receive(:collecting_sponsors?).and_return(false)
allow(petition).to receive(:in_moderation?).and_return(false)
allow(petition).to receive(:moderated?).and_return(true)
allow(Petition).to receive_message_chain(:show, :find => petition)
Expand Down
8 changes: 6 additions & 2 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@
state Petition::VALIDATED_STATE

after(:create) do |petition, evaluator|
petition.sponsors.each do |sp|
sp.create_signature!(FactoryGirl.attributes_for(:validated_signature)) if evaluator.sponsors_signed
if evaluator.sponsors_signed
petition.sponsors.each do |sp|
sp.create_signature!(FactoryGirl.attributes_for(:validated_signature))
end

petition.update_signature_count!
end
end
end
Expand Down
19 changes: 19 additions & 0 deletions spec/jobs/application_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'rails_helper'

RSpec.describe ApplicationJob, type: :job do
class AnApplicationJob < ::ApplicationJob
def perform
logger.info "Performed application job"
end
end

before do
expect(Site).to receive(:reload).and_call_original
end

it "reloads the site instance" do
perform_enqueued_jobs {
AnApplicationJob.perform_later
}
end
end

0 comments on commit af93a3e

Please sign in to comment.