Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #16 from alphagov/removing_the_need_to_specify_org…

…anisation

Removing the need to specify organisation
  • Loading branch information...
commit 06365b2aaf8945bfa5393681df2a191596d47583 2 parents fbf33a1 + 501bafa
@jamiecobbett jamiecobbett authored
Showing with 66 additions and 313 deletions.
  1. +0 −19 app/controllers/requests_controller.rb
  2. +1 −3 app/models/requester.rb
  3. +0 −2  app/views/support/_requester.html.erb
  4. +4 −4 features/campaign_requests.feature
  5. +4 −4 features/content_change_requests.feature
  6. +4 −4 features/create_new_user_requests.feature
  7. +4 −4 features/general_requests.feature
  8. +4 −4 features/new_feature_requests.feature
  9. +4 −4 features/remove_user_requests.feature
  10. +0 −1  features/step_definitions/request_steps.rb
  11. +0 −1  features/step_definitions/zendesk_steps.rb
  12. +0 −1  features/support/hooks.rb
  13. +0 −2  features/support/zendesk_helper.rb
  14. +3 −11 lib/campaign_request_zendesk_ticket.rb
  15. +0 −12 lib/content_change_request_zendesk_ticket.rb
  16. +0 −10 lib/create_new_user_request_zendesk_ticket.rb
  17. +3 −11 lib/general_request_zendesk_ticket.rb
  18. +0 −10 lib/new_feature_request_zendesk_ticket.rb
  19. +0 −10 lib/remove_user_request_zendesk_ticket.rb
  20. +2 −15 lib/zendesk_request.rb
  21. +4 −21 lib/zendesk_ticket.rb
  22. +2 −15 test/functional/content_change_requests_controller_test.rb
  23. +2 −12 test/functional/create_new_user_requests_controller_test.rb
  24. +2 −16 test/functional/general_requests_controller_test.rb
  25. +2 −12 test/functional/remove_user_requests_controller_test.rb
  26. +0 −2  test/functional/support_controller_test.rb
  27. +0 −20 test/test_data.rb
  28. +0 −1  test/test_helper.rb
  29. +0 −12 test/unit/models/requester_test.rb
  30. +21 −15 test/unit/zendesk/zendesk_ticket_test.rb
  31. +0 −21 test/zendesk_api_stubs.rb
  32. +0 −34 test/zendesk_organisation_list_helper.rb
View
19 app/controllers/requests_controller.rb
@@ -4,7 +4,6 @@
class RequestsController < ApplicationController
def new
@request = new_request
- prepopulate_organisation_list
end
def create
@@ -12,7 +11,6 @@ def create
if @request.valid?
raise_ticket(zendesk_ticket_class.new(@request))
else
- prepopulate_organisation_list
render :new, :status => 400
end
end
@@ -30,24 +28,7 @@ def raise_ticket(ticket)
end
end
- def load_client_and_organisations(error_string)
- load_client
- load_organisations(error_string)
- end
-
def load_client
@client = ZendeskClient.get_client(logger)
end
-
- def load_organisations(error_string)
- begin
- @organisations = ZendeskRequest.get_organisations(@client)
- rescue ZendeskError
- return render :"support/zendesk_error", :locals => {:error_string => error_string}
- end
- end
-
- def prepopulate_organisation_list
- load_client_and_organisations("zendesk_error_upon_new_form")
- end
end
View
4 app/models/requester.rb
@@ -1,10 +1,8 @@
require 'tableless_model'
class Requester < TablelessModel
- attr_accessor :name, :email, :job, :phone, :organisation, :other_organisation
+ attr_accessor :name, :email, :job, :phone
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
View
2  app/views/support/_requester.html.erb
@@ -4,7 +4,5 @@
<%= 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 %>
<% end %>
View
8 features/campaign_requests.feature
@@ -5,16 +5,16 @@ Feature: Campaign requests
Background:
* the following user has SSO access:
- | Name | Email | Job title | Organisation | Phone |
- | John Smith | john.smith@email.com | Developer | Cabinet Office | 12345 |
+ | Name | Email | Job title | Phone |
+ | John Smith | john.smith@email.com | Developer | 12345 |
Scenario: successful campaign request
When the user submits the following campaign request:
| Campaign title | ERG ref number | Start date | Description | Affiliated group | Info URL | Additional comments |
| Workplace pensions | 123456 | 01-01-2020 | Pensions | AXA | https://www.gov.uk | Some comment |
Then the following ticket is raised in ZenDesk:
- | Subject | Requester email | Requester name | Phone | Job title | Organisation |
- | Campaign | john.smith@email.com | John Smith | 12345 | Developer | cabinet_office |
+ | Subject | Requester email | Requester name | Phone | Job title |
+ | Campaign | john.smith@email.com | John Smith | 12345 | Developer |
And the ticket is tagged with "campaign"
And the comment on the ticket is:
"""
View
8 features/content_change_requests.feature
@@ -5,8 +5,8 @@ Feature: Content change requests
Background:
* the following user has SSO access:
- | Name | Email | Job title | Organisation | Phone |
- | John Smith | john.smith@email.com | Developer | Cabinet Office | 12345 |
+ | Name | Email | Job title | Phone |
+ | John Smith | john.smith@email.com | Developer | 12345 |
Scenario: successful Mainstream content change request
When the user submits the following content change request:
@@ -14,8 +14,8 @@ Feature: Content change requests
| Mainstream (business/citizen) | Out of date XX YY | http://gov.uk/X | http://gov.uk/Y | 31-12-2020 | 01-12-2020 | New law |
Then the following ticket is raised in ZenDesk:
- | Subject | Requester email | Requester name | Phone | Job title | Organisation |
- | Content change request | john.smith@email.com | John Smith | 12345 | Developer | cabinet_office |
+ | Subject | Requester email | Requester name | Phone | Job title |
+ | Content change request | john.smith@email.com | John Smith | 12345 | Developer |
And the time constraints on the ticket are:
| Need by date | Not before date |
| 31-12-2020 | 01-12-2020 |
View
8 features/create_new_user_requests.feature
@@ -6,16 +6,16 @@ Feature: Create new user requests
Background:
* the following user has SSO access:
- | Name | Email | Job title | Organisation | Phone |
- | John Smith | john.smith@email.com | Developer | Cabinet Office | 12345 |
+ | Name | Email | Job title | Phone |
+ | John Smith | john.smith@email.com | Developer | 12345 |
Scenario: successful create user request for publisher
When the user submits the following create user request:
| Tool/Role | User's name | User's email | Additional comments |
| Departmental Contact Form | Bob Fields | bob@gov.uk | XXXX |
Then the following ticket is raised in ZenDesk:
- | Subject | Requester email | Requester name | Phone | Job title | Organisation |
- | Create new user | john.smith@email.com | John Smith | 12345 | Developer | cabinet_office |
+ | Subject | Requester email | Requester name | Phone | Job title |
+ | Create new user | john.smith@email.com | John Smith | 12345 | Developer |
And the ticket is tagged with "new_user"
And the comment on the ticket is:
"""
View
8 features/general_requests.feature
@@ -5,16 +5,16 @@ Feature: General requests
Background:
* the following user has SSO access:
- | Name | Email | Job title | Organisation | Phone |
- | John Smith | john.smith@email.com | Developer | Cabinet Office | 12345 |
+ | Name | Email | Job title | Phone |
+ | John Smith | john.smith@email.com | Developer | 12345 |
Scenario: successful request
When the user submits the following general request:
| Details | URL |
| The site is down | https://www.gov.uk |
Then the following ticket is raised in ZenDesk:
- | Subject | Requester email | Requester name | Phone | Job title | Organisation |
- | Govt Agency General Issue | john.smith@email.com | John Smith | 12345 | Developer | cabinet_office |
+ | Subject | Requester email | Requester name | Phone | Job title |
+ | Govt Agency General Issue | john.smith@email.com | John Smith | 12345 | Developer |
And the ticket is tagged with "govt_agency_general"
And the comment on the ticket is:
"""
View
8 features/new_feature_requests.feature
@@ -5,8 +5,8 @@ Feature: New feature requests
Background:
* the following user has SSO access:
- | Name | Email | Job title | Organisation | Phone |
- | John Smith | john.smith@email.com | Developer | Cabinet Office | 12345 |
+ | Name | Email | Job title | Phone |
+ | John Smith | john.smith@email.com | Developer | 12345 |
Scenario: successful request
When the user submits the following new feature request:
@@ -14,8 +14,8 @@ Feature: New feature requests
| Inside Government | Information on XYZ | http://www.example.com | 31-12-2020 | 01-12-2020 | Legal requirement |
Then the following ticket is raised in ZenDesk:
- | Subject | Requester email | Requester name | Phone | Job title | Organisation |
- | New Feature Request | john.smith@email.com | John Smith | 12345 | Developer | cabinet_office |
+ | Subject | Requester email | Requester name | Phone | Job title |
+ | New Feature Request | john.smith@email.com | John Smith | 12345 | Developer |
And the time constraints on the ticket are:
| Need by date | Not before date |
| 31-12-2020 | 01-12-2020 |
View
8 features/remove_user_requests.feature
@@ -5,16 +5,16 @@ Feature: Remove user requests
Background:
* the following user has SSO access:
- | Name | Email | Job title | Organisation | Phone |
- | John Smith | john.smith@email.com | Developer | Cabinet Office | 12345 |
+ | Name | Email | Job title | Phone |
+ | John Smith | john.smith@email.com | Developer | 12345 |
Scenario: successful remove user request for publisher
When the user submits the following remove user request:
| Tool/Role | User's name | User's email | Not before date | Additional comments |
| Departmental Contact Form | Bob Wasfired | bob@gov.uk | 31-12-2020 | XXXX |
Then the following ticket is raised in ZenDesk:
- | Subject | Requester email | Requester name | Phone | Job title | Organisation |
- | Remove user | john.smith@email.com | John Smith | 12345 | Developer | cabinet_office |
+ | Subject | Requester email | Requester name | Phone | Job title |
+ | Remove user | john.smith@email.com | John Smith | 12345 | Developer |
And the ticket is tagged with "remove_user"
And the time constraints on the ticket are:
| Not before date |
View
1  features/step_definitions/request_steps.rb
@@ -3,7 +3,6 @@
fill_in "Email", :with => @user_details["Email"]
fill_in "Job title", :with => @user_details["Job title"]
fill_in "Phone number", :with => @user_details["Phone"]
- select @user_details["Organisation"], :from => 'Organisation'
end
When /^the user fills out the time constraints$/ do
View
1  features/step_definitions/zendesk_steps.rb
@@ -6,7 +6,6 @@
assert_equal expected_ticket_props["Requester email"], @raised_ticket.email if expected_ticket_props["Requester email"]
assert_equal expected_ticket_props["Requester name"], @raised_ticket.name if expected_ticket_props["Requester name"]
assert_equal expected_ticket_props["Job title"], @raised_ticket.job if expected_ticket_props["Job title"]
- assert_equal expected_ticket_props["Organisation"], @raised_ticket.organisation if expected_ticket_props["Organisation"]
assert_equal expected_ticket_props["Phone"], @raised_ticket.phone if expected_ticket_props["Phone"]
end
View
1  features/support/hooks.rb
@@ -1,4 +1,3 @@
Before do
- stub_zendesk_organisation_list
stub_zendesk_ticket_submission
end
View
2  features/support/zendesk_helper.rb
@@ -1,5 +1,3 @@
-require_relative '../../test/zendesk_organisation_list_helper'
require_relative '../../test/zendesk_api_stubs'
-World(ZendeskOrganisationListHelper)
World(ZendeskApiStubsHelper)
View
14 lib/campaign_request_zendesk_ticket.rb
@@ -1,13 +1,7 @@
require 'zendesk_ticket'
-require 'forwardable'
require 'comment_snippet'
class CampaignRequestZendeskTicket < ZendeskTicket
- def initialize(request)
- super(request, nil)
- @requester = request.requester
- end
-
def subject
"Campaign"
end
@@ -16,12 +10,9 @@ def tags
["campaign"]
end
- # the following methods will be pushed down to the superclass as soon as everything is converted to ActiveModel
- def_delegators :@requester, :name, :email, :organisation, :job
-
protected
def comment_snippets
- [ CommentSnippet.new(on: @request.requester, field: :other_organisation),
+ [
CommentSnippet.new(on: @request.campaign, field: :title,
label: "Campaign title"),
CommentSnippet.new(on: @request.campaign, field: :erg_reference_number,
@@ -31,6 +22,7 @@ def comment_snippets
CommentSnippet.new(on: @request.campaign, field: :affiliated_group_or_company),
CommentSnippet.new(on: @request.campaign, field: :info_url,
label: "URL with more information"),
- CommentSnippet.new(on: @request, field: :additional_comments) ]
+ CommentSnippet.new(on: @request, field: :additional_comments)
+ ]
end
end
View
12 lib/content_change_request_zendesk_ticket.rb
@@ -1,15 +1,7 @@
require 'zendesk_ticket'
-require 'forwardable'
require 'comment_snippet'
class ContentChangeRequestZendeskTicket < ZendeskTicket
- attr_reader :time_constraint
-
- def initialize(request)
- super(request, nil)
- @requester = request.requester
- end
-
def subject
"Content change request"
end
@@ -18,15 +10,11 @@ def tags
["content_amend"] + inside_government_tag_if_needed
end
- # the following methods will be pushed down to the superclass as soon as everything is converted to ActiveModel
- def_delegators :@requester, :name, :email, :organisation, :job
-
protected
def comment_snippets
[
CommentSnippet.new(on: @request, field: :formatted_request_context,
label: "Which part of GOV.UK is this about?"),
- CommentSnippet.new(on: @request.requester, field: :other_organisation),
CommentSnippet.new(on: @request, fields: [:url1, :url2, :url3],
label: "URl(s) of content to be changed"),
CommentSnippet.new(on: @request, field: :details_of_change,
View
10 lib/create_new_user_request_zendesk_ticket.rb
@@ -1,13 +1,7 @@
require 'zendesk_ticket'
-require 'forwardable'
require 'comment_snippet'
class CreateNewUserRequestZendeskTicket < ZendeskTicket
- def initialize(request)
- super(request, nil)
- @requester = request.requester
- end
-
def subject
"Create new user"
end
@@ -16,15 +10,11 @@ def tags
["new_user"] + inside_government_tag_if_needed
end
- # the following methods will be pushed down to the superclass as soon as everything is converted to ActiveModel
- def_delegators :@requester, :name, :email, :organisation, :job
-
protected
def comment_snippets
[
CommentSnippet.new(on: @request, field: :formatted_tool_role,
label: "Tool/Role"),
- CommentSnippet.new(on: @request.requester, field: :other_organisation),
CommentSnippet.new(on: @request, field: :user_name),
CommentSnippet.new(on: @request, field: :user_email),
CommentSnippet.new(on: @request, field: :additional_comments)
View
14 lib/general_request_zendesk_ticket.rb
@@ -1,13 +1,7 @@
require 'zendesk_ticket'
-require 'forwardable'
require 'comment_snippet'
class GeneralRequestZendeskTicket < ZendeskTicket
- def initialize(request)
- super(request, nil)
- @requester = request.requester
- end
-
def subject
"Govt Agency General Issue"
end
@@ -16,14 +10,12 @@ def tags
["govt_agency_general"]
end
- # the following methods will be pushed down to the superclass as soon as everything is converted to ActiveModel
- def_delegators :@requester, :name, :email, :organisation, :job
-
protected
def comment_snippets
- [ CommentSnippet.new(on: @request.requester, field: :other_organisation),
+ [
CommentSnippet.new(on: @request, field: :url),
CommentSnippet.new(on: @request, field: :user_agent),
- CommentSnippet.new(on: @request, field: :additional) ]
+ CommentSnippet.new(on: @request, field: :additional)
+ ]
end
end
View
10 lib/new_feature_request_zendesk_ticket.rb
@@ -1,15 +1,9 @@
require 'zendesk_ticket'
-require 'forwardable'
require 'comment_snippet'
class NewFeatureRequestZendeskTicket < ZendeskTicket
attr_reader :time_constraint
- def initialize(request)
- super(request, nil)
- @requester = request.requester
- end
-
def subject
@request.inside_government_related? ? "New Feature Request" : "New Need Request"
end
@@ -19,15 +13,11 @@ def tags
specific_tag + inside_government_tag_if_needed
end
- # the following methods will be pushed down to the superclass as soon as everything is converted to ActiveModel
- def_delegators :@requester, :name, :email, :organisation, :job
-
protected
def comment_snippets
[
CommentSnippet.new(on: @request, field: :formatted_request_context,
label: "Which part of GOV.UK is this about?"),
- CommentSnippet.new(on: @request.requester, field: :other_organisation),
CommentSnippet.new(on: @request, field: :user_need),
CommentSnippet.new(on: @request, field: :url_of_example),
CommentSnippet.new(on: @request.time_constraint, field: :time_constraint_reason)
View
10 lib/remove_user_request_zendesk_ticket.rb
@@ -1,13 +1,7 @@
require 'zendesk_ticket'
-require 'forwardable'
require 'comment_snippet'
class RemoveUserRequestZendeskTicket < ZendeskTicket
- def initialize(request)
- super(request, nil)
- @requester = request.requester
- end
-
def subject
"Remove user"
end
@@ -16,15 +10,11 @@ def tags
["remove_user"] + inside_government_tag_if_needed
end
- # the following methods will be pushed down to the superclass as soon as everything is converted to ActiveModel
- def_delegators :@requester, :name, :email, :organisation, :job
-
protected
def comment_snippets
[
CommentSnippet.new(on: @request, field: :formatted_tool_role,
label: "Tool/Role"),
- CommentSnippet.new(on: @request.requester, field: :other_organisation),
CommentSnippet.new(on: @request, field: :user_name),
CommentSnippet.new(on: @request, field: :user_email),
CommentSnippet.new(on: @request, field: :additional_comments)
View
17 lib/zendesk_request.rb
@@ -1,33 +1,20 @@
require_relative "zendesk_ticket"
-require 'ostruct'
class ZendeskRequest
def self.field_ids
- { organisation: "21494928",
- job: "21487987",
+ { job: "21487987",
phone: "21471291",
needed_by_date: "21485833",
not_before_date: "21502036" }
end
- def self.get_organisations(client)
- organisations_hash = {}
- client.ticket_fields.find(:id => '21494928').custom_field_options.each { |tf| organisations_hash[tf.name] = tf.value }
- organisations_hash
- end
-
- def self.raise_zendesk_request(client, params, from_route)
- raise_ticket(client, ZendeskTicket.new(OpenStruct.new(params), from_route))
- end
-
def self.raise_ticket(client, ticket_to_raise)
client.ticket.create(
:subject => ticket_to_raise.subject,
:description => "Created via Govt API",
:priority => "normal",
:requester => {"locale_id" => 1, "name" => ticket_to_raise.name, "email" => ticket_to_raise.email},
- :fields => [{"id" => ZendeskRequest.field_ids[:organisation], "value" => ticket_to_raise.organisation},
- {"id" => ZendeskRequest.field_ids[:job], "value" => ticket_to_raise.job},
+ :fields => [{"id" => ZendeskRequest.field_ids[:job], "value" => ticket_to_raise.job},
{"id" => ZendeskRequest.field_ids[:phone], "value" => ticket_to_raise.phone},
{"id" => ZendeskRequest.field_ids[:needed_by_date], "value" => ticket_to_raise.needed_by_date},
{"id" => ZendeskRequest.field_ids[:not_before_date], "value" => ticket_to_raise.not_before_date}],
View
25 lib/zendesk_ticket.rb
@@ -5,28 +5,15 @@
class ZendeskTicket
extend Forwardable
- def initialize(request, from_route)
+ def initialize(request)
@request = request
- @from_route = from_route
+ @requester = request.requester
end
- def_delegators :@request, :name, :email, :organisation, :job
+ def_delegators :@requester, :name, :email, :job
def phone
- # TODO: solve this horrible mess when the refactor is done
- if instance_variable_defined?("@requester")
- if has_value?(:phone, @requester)
- remove_space_from_phone_number(@requester.phone)
- else
- nil
- end
- else
- if has_value?(:phone)
- remove_space_from_phone_number(@request.phone)
- else
- nil
- end
- end
+ remove_space_from_phone_number(@requester.phone)
end
def comment
@@ -54,10 +41,6 @@ def inside_government_tag_if_needed
@request.inside_government_related? ? ["inside_government"] : []
end
- def tags
- [@@in_tag[@from_route]]
- end
-
private
def inside_government_tag
View
17 test/functional/content_change_requests_controller_test.rb
@@ -1,7 +1,6 @@
require "test_helper"
class ContentChangeRequestsControllerTest < ActionController::TestCase
- include ZendeskOrganisationListHelper
include TestData
setup do
@@ -15,27 +14,15 @@ class ContentChangeRequestsControllerTest < ActionController::TestCase
get :new
assert_select "h1", /Request a change to existing GOV.UK content/i
end
-
- should "use ZenDesk to populate the organisation dropdown" do
- get :new
- assert_select "select#content_change_request_requester_attributes_organisation option", "Advocate General for Scotland"
- end
-
- should "inform the user if ZenDesk is unreachable" do
- @zendesk_api.should_raise_error
-
- get :new
- assert_template "support/zendesk_error"
- end
end
context "a submitted content change request" do
should "reject invalid change requests" do
- params = valid_content_change_request_params.tap {|p| p["content_change_request"]["requester_attributes"].merge!("organisation" => "")}
+ params = valid_content_change_request_params.tap {|p| p["content_change_request"]["requester_attributes"].merge!("email" => "")}
post :create, params
assert_response 400
assert_template "new"
- assert_select ".help-inline", /information is required/
+ assert_select ".help-inline", /can't be blank/
end
should "submit it to ZenDesk" do
View
14 test/functional/create_new_user_requests_controller_test.rb
@@ -1,7 +1,6 @@
require "test_helper"
class CreateNewUserRequestsControllerTest < ActionController::TestCase
- include ZendeskOrganisationListHelper
include TestData
setup do
@@ -11,28 +10,19 @@ class CreateNewUserRequestsControllerTest < ActionController::TestCase
end
context "new user creation request" do
- setup do
- stub_zendesk_organisation_list
- end
-
should "render the form" do
get :new
assert_select "h1", /Create a new user account/i
end
-
- should "use ZenDesk to populate the organisation dropdown" do
- get :new
- assert_select "select#create_new_user_request_requester_attributes_organisation option", "Advocate General for Scotland"
- end
end
context "submitted user creation request" do
should "reject invalid requests" do
- params = valid_create_new_user_request_params.tap {|p| p["create_new_user_request"]["requester_attributes"].merge!("organisation" => "")}
+ params = valid_create_new_user_request_params.tap {|p| p["create_new_user_request"]["requester_attributes"].merge!("email" => "")}
post :create, params
assert_response 400
assert_template "new"
- assert_select ".help-inline", /information is required/
+ assert_select ".help-inline", /can't be blank/
end
should "submit it to ZenDesk" do
View
18 test/functional/general_requests_controller_test.rb
@@ -1,7 +1,6 @@
require 'test_helper'
class GeneralRequestsControllerTest < ActionController::TestCase
- include ZendeskOrganisationListHelper
include TestData
setup do
@@ -11,34 +10,21 @@ class GeneralRequestsControllerTest < ActionController::TestCase
end
context "a new general request" do
- setup do
- stub_zendesk_organisation_list
- end
-
should "render the form" do
get :new
assert_select "h1", /Report a problem, request GDS support, or to make a suggestion/i
end
-
- should "use ZenDesk to populate the organisation dropdown" do
- get :new
- assert_select "select#general_request_requester_attributes_organisation option", "Advocate General for Scotland"
- end
end
context "a submitted general request" do
- setup do
- stub_zendesk_organisation_list
- end
-
should "reject invalid requests" do
- params = valid_general_request_params.tap {|p| p["general_request"]["requester_attributes"].merge!("organisation" => "")}
+ params = valid_general_request_params.tap {|p| p["general_request"]["requester_attributes"].merge!("email" => "")}
post :create, params
assert_response 400
assert_template :new
- assert_select ".help-inline", /information is required/
+ assert_select ".help-inline", /can't be blank/
end
should "submit it to ZenDesk" do
View
14 test/functional/remove_user_requests_controller_test.rb
@@ -1,7 +1,6 @@
require 'test_helper'
class RemoveUserRequestsControllerTest < ActionController::TestCase
- include ZendeskOrganisationListHelper
include TestData
setup do
@@ -11,28 +10,19 @@ class RemoveUserRequestsControllerTest < ActionController::TestCase
end
context "new remove user request" do
- setup do
- stub_zendesk_organisation_list
- end
-
should "render the form" do
get :new
assert_select "h1", /Remove User/i
end
-
- should "use ZenDesk to populate the organisation dropdown" do
- get :new
- assert_select "select#remove_user_request_requester_attributes_organisation option", "Advocate General for Scotland"
- end
end
context "submitted remove user request" do
should "reject invalid requests" do
- params = valid_remove_user_request_params.tap {|p| p["remove_user_request"]["requester_attributes"].merge!("organisation" => "")}
+ params = valid_remove_user_request_params.tap {|p| p["remove_user_request"]["requester_attributes"].merge!("email" => "")}
post :create, params
assert_response 400
assert_template "new"
- assert_select ".help-inline", /information is required/
+ assert_select ".help-inline", /can't be blank/
end
should "submit it to ZenDesk" do
View
2  test/functional/support_controller_test.rb
@@ -1,8 +1,6 @@
require "test_helper"
class SupportControllerTest < ActionController::TestCase
- include ZendeskOrganisationListHelper
-
setup do
login_as_stub_user
@zendesk_api = ZenDeskAPIClientDouble.new
View
20 test/test_data.rb
@@ -30,24 +30,6 @@ def valid_remove_user_request_params
}
end
- def valid_campaign_request_params
- { "name"=>"Testing",
- "email"=>"testing@digital.cabinet-office.gov.uk",
- "job"=>"doo",
- "phone"=>"",
- "organisation"=>"cabinet_office",
- "other_organisation"=>"",
- "campaign_name"=>"Testing",
- "erg_number"=>"1234",
- "start_day"=>"",
- "start_month"=>"",
- "start_year"=>"",
- "description"=>"Testing",
- "company"=>"",
- "url"=>"",
- "additional"=>"" }
- end
-
def valid_general_request_params
{"general_request" =>
{ "requester_attributes" => valid_requester_params,
@@ -61,8 +43,6 @@ def valid_requester_params
"email"=>"testing@digital.cabinet-office.gov.uk",
"job"=>"dev",
"phone"=>"",
- "organisation"=>"cabinet_office",
- "other_organisation"=>"",
}
end
View
1  test/test_helper.rb
@@ -8,7 +8,6 @@
require 'ostruct'
require_relative 'test_data'
-require 'zendesk_organisation_list_helper'
require 'zendesk_api_stubs'
class ActiveSupport::TestCase
View
12 test/unit/models/requester_test.rb
@@ -1,24 +1,12 @@
require 'test_helper'
class RequesterTest < Test::Unit::TestCase
- include TestData
-
should validate_presence_of(:name)
should validate_presence_of(:email)
should validate_presence_of(:job)
- should validate_presence_of(:organisation).with_message(/information is required/)
should allow_value("07911111").for(:phone)
- should allow_value("some other dept").for(:other_organisation)
-
should allow_value("ab@c.com").for(:email)
should_not allow_value("ab").for(:email)
-
- should "not allow a blank other_organisation if the organisation=other_organisation" do
- other_organisation_not_set = {"organisation" => "other_organisation", "other_organisation" => ""}
- request = Requester.new(valid_requester_params.merge(other_organisation_not_set))
- assert !request.valid?
- assert_not_empty request.errors[:other_organisation]
- end
end
View
36 test/unit/zendesk/zendesk_ticket_test.rb
@@ -1,46 +1,52 @@
require 'test/unit'
require 'shoulda/context'
require 'zendesk_ticket'
-require 'test_data'
require 'ostruct'
require 'date'
class ZendeskTicketTest < Test::Unit::TestCase
- def new_ticket(attributes, type = nil)
- ZendeskTicket.new(OpenStruct.new(attributes), type)
+ def new_ticket(attributes)
+ ZendeskTicket.new(OpenStruct.new(attributes))
+ end
+
+ def with_requester(attributes)
+ {requester: OpenStruct.new(attributes)}
+ end
+
+ def with_time_constraint(attributes)
+ {time_constraint: OpenStruct.new(attributes)}
end
- include TestData
context "content change request" do
should "set the requester details correctly" do
ticket = new_ticket(
- :name => "John Smith",
- :email => "ab@c.com",
- :organisation => "cabinet_office",
- :job => "Developer",
- :phone => "123456"
+ with_requester(
+ :name => "John Smith",
+ :email => "ab@c.com",
+ :job => "Developer",
+ :phone => "123456"
+ )
)
assert_equal "John Smith", ticket.name
assert_equal "ab@c.com", ticket.email
- assert_equal "cabinet_office", ticket.organisation
assert_equal "Developer", ticket.job
assert_equal "123456", ticket.phone
end
context "with time constraints" do
should "pass the need_by_date through" do
- time_constraint = OpenStruct.new(needed_by_date: "03-02-2001")
- assert_equal "03-02-2001", new_ticket(time_constraint: time_constraint).needed_by_date
+ assert_equal "03-02-2001",
+ new_ticket(with_time_constraint(needed_by_date: "03-02-2001")).needed_by_date
end
should "pass the not_before_date through" do
- time_constraint = OpenStruct.new(not_before_date: "03-02-2001")
- assert_equal "03-02-2001", new_ticket(time_constraint: time_constraint).not_before_date
+ assert_equal "03-02-2001",
+ new_ticket(with_time_constraint(not_before_date: "03-02-2001")).not_before_date
end
end
should "remove spaces from the tel number" do
- assert_equal "12345678", new_ticket(:phone => "1234 5678").phone
+ assert_equal "12345678", new_ticket(with_requester(:phone => "1234 5678")).phone
end
end
end
View
21 test/zendesk_api_stubs.rb
@@ -50,26 +50,5 @@ class ZenDeskAPIClientDouble
def initialize
@ticket = ZenDeskAPITicketDouble.new
- @should_raise_error = false
- end
-
- def should_raise_error
- @should_raise_error = true
- end
-
- def ticket_fields
- raise ZendeskError.new("zendesk is down", nil) if @should_raise_error
- self
- end
-
- def find(some_criteria)
- self
- end
-
- def custom_field_options
- [ {"name"=>"Advocate General for Scotland", "value"=>"advocate_general_for_scotland"},
- {"name"=>"Attorney General's Office", "value"=>"attorney_generals_office"},
- {"name"=>"Cabinet Office", "value"=>"cabinet_office"}
- ].collect {|params| OpenStruct.new(params)}
end
end
View
34 test/zendesk_organisation_list_helper.rb
@@ -1,34 +0,0 @@
-module ZendeskOrganisationListHelper
- def stub_zendesk_organisation_list
- url = %r{https://.*@govuk.zendesk.com/api/v2/ticket_fields/21494928}
- body = {
- "ticket_field" => {
- "url" => "https://govuk.zendesk.com/api/v2/ticket_fields/21494928.json",
- "id"=>21494928,
- "type"=>"tagger",
- "title"=>"Department",
- "description"=>"",
- "position"=>9999,
- "active"=>true,
- "required"=>false,
- "collapsed_for_agents"=>false,
- "regexp_for_validation"=>nil,
- "title_in_portal"=>"Department",
- "visible_in_portal"=>false,
- "editable_in_portal"=>false,
- "required_in_portal"=>false,
- "tag"=>nil,
- "created_at"=>"2012-08-07 08:06:33 UTC",
- "updated_at"=>"2012-08-07 08:06:33 UTC",
- "custom_field_options"=>[
- {"name"=>"Advocate General for Scotland", "value"=>"advocate_general_for_scotland"},
- {"name"=>"Attorney General's Office", "value"=>"attorney_generals_office"},
- {"name"=>"Cabinet Office", "value"=>"cabinet_office"}
- ]
- }
- }
-
- stub_request(:get, url).
- to_return(:status => 200, :body => body.to_json, :headers => {"Content-Type" => "application/json"})
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.