Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from alphagov/general_request_refactor
General request form refactoring
- Loading branch information
Showing
41 changed files
with
667 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
class GeneralRequest | ||
include ActiveAttr::Model | ||
require 'tableless_model' | ||
require 'requester' | ||
|
||
attribute :name | ||
attribute :email | ||
attribute :job | ||
attribute :phone | ||
attribute :organisation | ||
attribute :other_organisation | ||
attribute :url | ||
attribute :additional | ||
class GeneralRequest < TablelessModel | ||
attr_accessor :requester, :url, :additional, :user_agent | ||
|
||
validates_presence_of :name, :email, :job | ||
validates_presence_of :organisation, :message => "information is required for a valid request." | ||
validates :email, :format => {:with => /^[\w\d]+[^@]*@[\w\d]+[^@]*\.[\w\d]+[^@]*$/} | ||
validates_presence_of :other_organisation, :if => Proc.new {|request| request.organisation == "other_organisation"} | ||
validates_presence_of :requester | ||
validate do |request| | ||
if request.requester and not request.requester.valid? | ||
errors[:base] << "Requester details are either not complete or invalid." | ||
end | ||
end | ||
|
||
def requester_attributes=(attr) | ||
self.requester = Requester.new(attr) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'tableless_model' | ||
|
||
class Requester < TablelessModel | ||
attr_accessor :name, :email, :job, :phone, :organisation, :other_organisation | ||
|
||
validates_presence_of :name, :email, :job | ||
validates_presence_of :organisation, :message => "information is required for a valid request." | ||
validates :email, :format => {:with => /^[\w\d]+[^@]*@[\w\d]+[^@]*\.[\w\d]+[^@]*$/} | ||
validates_presence_of :other_organisation, :if => Proc.new {|request| request.organisation == "other_organisation"} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class TablelessModel | ||
include ActiveModel::Validations | ||
include ActiveModel::Conversion | ||
extend ActiveModel::Naming | ||
|
||
def initialize(attributes = {}) | ||
attributes.each do |key, value| | ||
if respond_to? "#{key}=" | ||
send("#{key}=", value) | ||
end | ||
end | ||
end | ||
|
||
def persisted? | ||
false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<%= f.semantic_fields_for :requester, :label => "Your details" do |r| %> | ||
<%= r.input :name, :label => "Name", :required => true, :input_html => {:"aria-required" => true, :class => "span6"} %> | ||
<%= r.input :email, :label => "Email", :as => :email, :required => true, :input_html => {:"aria-required" => true, :class => "span6"} %> | ||
<%= r.input :job, :label => "Job title", :required => true, :input_html => {:"aria-required" => true, :class => "span6"} %> | ||
<%= r.input :phone, :label => "Phone number", :as => :phone, :input_html => {:"aria-required" => true, :class => "span6"} %> | ||
<%= r.input :organisation, :label => "Organisation", :as => :select, :collection => @organisations, :include_blank => "Select Organisation", :input_html => {:"aria-required" => true, :class => "span6"} %> | ||
<%= r.input :other_organisation, :label => "Please specify the organisation if you didn't find it in the list above", :input_html => {:class => "span6"} %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<% | ||
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" | ||
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" | ||
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip" | ||
%> | ||
default: <%= std_opts %> features | ||
wip: --tags @wip:3 --wip features | ||
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Feature: General requests | ||
In order to provide GDS with feedback | ||
As a government employee | ||
I want a means to contact GDS in the cases when my request does not covered by the other forms | ||
|
||
Background: | ||
* the following user has SSO access: | ||
| Name | Email | Job title | Organisation | | ||
| John Smith | john.smith@email.com | Developer | Cabinet Office | | ||
|
||
Scenario: successful request | ||
When the user submits the following general request: | ||
| Details | URL | | ||
| The site is down | http://www.gov.uk | | ||
Then the following ticket is raised in ZenDesk: | ||
| Subject | Requester email | Requester name | Job title | Organisation | | ||
| Govt Agency General Issue | john.smith@email.com | John Smith | Developer | cabinet_office | | ||
And the ticket is tagged with "govt_agency_general" | ||
And the comment on the ticket is: | ||
""" | ||
[Url] | ||
http://www.gov.uk | ||
[Additional] | ||
The site is down | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
When /^the user submits the following general request:$/ do |request_details_table| | ||
request_details = request_details_table.hashes.first | ||
|
||
visit '/' | ||
|
||
click_on "General" | ||
|
||
assert page.has_content?("Report a problem") | ||
|
||
fill_in "Name", :with => @user_details["Name"] | ||
fill_in "Email", :with => @user_details["Email"] | ||
fill_in "Job title", :with => @user_details["Job title"] | ||
select @user_details["Organisation"], :from => 'Organisation' | ||
|
||
fill_in "Details", :with => request_details['Details'] | ||
fill_in "URL (if applicable)", :with => request_details['URL'] | ||
|
||
click_on "Submit" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Given /^the following user has SSO access:$/ do |user_details| | ||
user = stub_everything('user', :name => "user", :has_permission? => true) | ||
@user_details = user_details.hashes.first | ||
|
||
login_as user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Then /^the following ticket is raised in ZenDesk:$/ do |ticket_properties_table| | ||
expected_ticket_props = ticket_properties_table.hashes.first | ||
@raised_ticket = @zendesk_api.ticket | ||
|
||
assert_equal expected_ticket_props["Subject"], @raised_ticket.subject | ||
assert_equal expected_ticket_props["Requester email"], @raised_ticket.email | ||
assert_equal expected_ticket_props["Requester name"], @raised_ticket.name | ||
assert_equal expected_ticket_props["Job title"], @raised_ticket.job | ||
assert_equal expected_ticket_props["Organisation"], @raised_ticket.organisation | ||
end | ||
|
||
Then /^the ticket is tagged with "(.*?)"$/ do |expected_tags| | ||
assert_equal expected_tags, @raised_ticket.tags.join(" ") | ||
end | ||
|
||
Then /^the comment on the ticket is:$/ do |expected_comment_string| | ||
assert_equal expected_comment_string, @raised_ticket.comment | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'capybara/poltergeist' | ||
|
||
Capybara.register_driver :rack_test do |app| | ||
Capybara::RackTest::Driver.new(app, :browser => :chrome) | ||
end | ||
Capybara.register_driver :poltergeist do |app| | ||
Capybara::Poltergeist::Driver.new(app, timeout: 5, debug: true) | ||
end | ||
Capybara.javascript_driver = :poltergeist |
Oops, something went wrong.