Skip to content

Commit

Permalink
converted the content change request form to capture the request context
Browse files Browse the repository at this point in the history
  • Loading branch information
benilovj committed Nov 26, 2012
1 parent 1bd840c commit 268b5f5
Show file tree
Hide file tree
Showing 21 changed files with 116 additions and 37 deletions.
4 changes: 2 additions & 2 deletions app/models/content_change_request.rb
@@ -1,12 +1,12 @@
require 'tableless_model'
require 'with_requester'
require 'with_time_constraint'
require 'with_inside_government'
require 'with_request_context'

class ContentChangeRequest < TablelessModel
include WithRequester
include WithTimeConstraint
include WithInsideGovernment
include WithRequestContext

attr_accessor :details_of_change, :url1, :url2, :url3
validates_presence_of :details_of_change
Expand Down
24 changes: 24 additions & 0 deletions app/models/with_request_context.rb
@@ -0,0 +1,24 @@
module WithRequestContext
attr_accessor :request_context

def self.included(base)
base.validates_presence_of :request_context
base.validates :request_context, :inclusion => {
:in => %w(mainstream inside_government detailed_guidance other),
:message => "%{value} is not valid option"
}
end

def inside_government_related?
%w{inside_government detailed_guidance}.include?(request_context)
end

def request_context_options
[
["Mainstream GOV.UK", "mainstream"],
["Inside Government", "inside_government"],
["Detailed Guidance", "detailed_guidance"],
["Other/Not sure", "other"]
]
end
end
2 changes: 2 additions & 0 deletions app/views/content_change_requests/_request_details.html.erb
@@ -1,3 +1,5 @@
<%= render :partial => "support/request_context", :locals => {:f => f} %>
<%= f.inputs :name => "URL(s) affected" do %>
<%= f.input :url1, :label => "URL 1", :input_html => {:class => "span6", :placeholder => "https://www.gov.uk/"} %>
<%= f.input :url2, :label => "URL 2", :input_html => {:class => "span6", :placeholder => "https://www.gov.uk/"} %>
Expand Down
2 changes: 0 additions & 2 deletions app/views/content_change_requests/new.html.erb
Expand Up @@ -23,8 +23,6 @@
<%= render :partial => "support/requester", :locals => {:f => f} %>
<%= render :partial => "support/inside_government_new", :locals => {:f => f} %>
<%= render :partial => "request_details", :locals => {:f => f} %>
<%= render :partial => "support/time_constraint", :locals => {:f => f} %>
Expand Down
3 changes: 3 additions & 0 deletions app/views/support/_request_context.html.erb
@@ -0,0 +1,3 @@
<div id="request-context">
<%= f.input :request_context, :as => :radio, :required => true, :label => "Which part of GOV.UK is this about?", :collection => f.object.request_context_options, :input_html => {:"aria-required" => true} %>
</div>
23 changes: 18 additions & 5 deletions features/content_change_requests.feature
Expand Up @@ -8,10 +8,10 @@ Feature: Content change requests
| Name | Email | Job title | Organisation | Phone |
| John Smith | john.smith@email.com | Developer | Cabinet Office | 12345 |

Scenario: successful request
Scenario: successful Mainstream content change request
When the user submits the following content change request:
| Details of change | URL 1 | URL 2 | Needed by date | Not before date | Reason |
| Out of date XX YY | http://gov.com/X | http://gov.uk/Y | 31-12-2012 | 01-12-2012 | New law |
| Context | Details of change | URL 1 | URL 2 | Needed by date | Not before date | Reason |
| Mainstream GOV.UK | Out of date XX YY | http://gov.uk/X | http://gov.uk/Y | 31-12-2012 | 01-12-2012 | New law |

Then the following ticket is raised in ZenDesk:
| Subject | Requester email | Requester name | Phone | Job title | Organisation |
Expand All @@ -22,13 +22,26 @@ Feature: Content change requests
And the ticket is tagged with "content_amend"
And the comment on the ticket is:
"""
[Which part of GOV.UK is this about?]
mainstream
[URl(s) of content to be changed]
http://gov.com/X
http://gov.uk/X
http://gov.uk/Y
[Details of what should be added, amended or removed]
Out of date XX YY
[Time constraint reason]
New law
"""
"""

Scenario: successful Inside Government content change request
When the user submits the following content change request:
| Context | Details of change |
| Inside Government | Out of date XX YY |

Then the following ticket is raised in ZenDesk:
| Subject |
| Content change request |
And the ticket is tagged with "content_amend inside_government"
4 changes: 4 additions & 0 deletions features/step_definitions/request_steps.rb
Expand Up @@ -63,6 +63,10 @@

step "the user fills out their details"

within "#request-context" do
choose @request_details["Context"]
end

fill_in "Details of the requested change", :with => @request_details["Details of change"]
fill_in "URL 1", :with => @request_details["URL 1"]
fill_in "URL 2", :with => @request_details["URL 2"]
Expand Down
12 changes: 6 additions & 6 deletions features/step_definitions/zendesk_steps.rb
Expand Up @@ -2,12 +2,12 @@
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
assert_equal expected_ticket_props["Phone"], @raised_ticket.phone
assert_equal expected_ticket_props["Subject"], @raised_ticket.subject if expected_ticket_props["Subject"]
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

Then /^the ticket is tagged with "(.*?)"$/ do |expected_tags|
Expand Down
11 changes: 7 additions & 4 deletions lib/content_change_request_zendesk_ticket.rb
Expand Up @@ -14,20 +14,23 @@ def subject
"Content change request"
end

def request_specific_tag
"content_amend"
def tags
["content_amend"] + (@request.inside_government_related? ? ["inside_government"] : [])
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: :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,
label: "Details of what should be added, amended or removed"),
CommentSnippet.new(on: @request.time_constraint, field: :time_constraint_reason) ]
CommentSnippet.new(on: @request.time_constraint, field: :time_constraint_reason)
]
end
end
4 changes: 2 additions & 2 deletions lib/create_new_user_request_zendesk_ticket.rb
Expand Up @@ -12,8 +12,8 @@ def subject
"Create new user"
end

def request_specific_tag
"new_user"
def tags
["new_user"]
end

# the following methods will be pushed down to the superclass as soon as everything is converted to ActiveModel
Expand Down
4 changes: 2 additions & 2 deletions lib/general_request_zendesk_ticket.rb
Expand Up @@ -12,8 +12,8 @@ def subject
"Govt Agency General Issue"
end

def request_specific_tag
"govt_agency_general"
def tags
["govt_agency_general"]
end

# the following methods will be pushed down to the superclass as soon as everything is converted to ActiveModel
Expand Down
4 changes: 2 additions & 2 deletions lib/new_feature_request_zendesk_ticket.rb
Expand Up @@ -14,8 +14,8 @@ def subject
"New Feature Request"
end

def request_specific_tag
"new_feature_request"
def tags
["new_feature_request"]
end

# the following methods will be pushed down to the superclass as soon as everything is converted to ActiveModel
Expand Down
6 changes: 1 addition & 5 deletions lib/zendesk_ticket.rb
Expand Up @@ -80,12 +80,8 @@ def needed_by_date
end
end

def request_specific_tag
@@in_tag[@from_route]
end

def tags
[request_specific_tag] + inside_government_tag
[@@in_tag[@from_route]]
end

private
Expand Down
2 changes: 1 addition & 1 deletion test/functional/content_change_requests_controller_test.rb
Expand Up @@ -49,7 +49,7 @@ class ContentChangeRequestsControllerTest < ActionController::TestCase

context "concerning Inside Government" do
should "tag the ticket with an inside_government tag" do
params = valid_content_change_request_params.tap {|p| p["content_change_request"].merge!("inside_government" => "yes")}
params = valid_content_change_request_params.tap {|p| p["content_change_request"].merge!("request_context" => "inside_government")}

post :create, params

Expand Down
3 changes: 2 additions & 1 deletion test/test_data.rb
Expand Up @@ -4,7 +4,8 @@ def valid_content_change_request_params
{ "requester_attributes" => valid_requester_params,
"time_constraint_attributes" => valid_time_constraint_params,
"url1" => "https://www.gov.uk",
"details_of_change" => "Content is wrong"}
"details_of_change" => "Content is wrong",
"request_context" => "mainstream" }
}
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/content_change_request_test.rb
Expand Up @@ -4,7 +4,7 @@ class ContentChangeRequestTest < Test::Unit::TestCase
should validate_presence_of(:requester)
should validate_presence_of(:details_of_change)

should allow_value("yes").for(:inside_government)
should validate_presence_of(:request_context)

should allow_value("https://www.gov.uk").for(:url1)
should allow_value("https://www.gov.uk").for(:url2)
Expand Down
Empty file.
23 changes: 23 additions & 0 deletions test/unit/models/with_request_context_test.rb
@@ -0,0 +1,23 @@
require 'tableless_model'
require 'with_request_context'
require 'test_helper'

class TestModelWithRequestContext < TablelessModel
include WithRequestContext
end

class TestModelWithRequestContextTest < Test::Unit::TestCase
should validate_presence_of(:request_context)
should allow_value("mainstream").for(:request_context)
should allow_value("inside_government").for(:request_context)
should allow_value("detailed_guidance").for(:request_context)
should allow_value("other").for(:request_context)
should_not allow_value("xxx").for(:request_context)

should "know if it's related to inside government or not" do
assert TestModelWithRequestContext.new(:request_context => "inside_government").inside_government_related?
assert TestModelWithRequestContext.new(:request_context => "detailed_guidance").inside_government_related?
assert !TestModelWithRequestContext.new(:request_context => "mainstream").inside_government_related?
assert !TestModelWithRequestContext.new(:request_context => "other").inside_government_related?
end
end
16 changes: 16 additions & 0 deletions test/unit/zendesk/content_change_request_zendesk_ticket_test.rb
@@ -0,0 +1,16 @@
require 'test/unit'
require 'shoulda/context'
require 'content_change_request_zendesk_ticket'
require 'ostruct'

class ContentChangeRequestZendeskTicketTest < Test::Unit::TestCase
def ticket_with(opts)
ContentChangeRequestZendeskTicket.new(stub_everything("request", opts))
end

context "an inside government request" do
should "be tagged with inside_government" do
assert_equal ["content_amend", "inside_government"], ticket_with(:inside_government_related? => true).tags
end
end
end
Expand Up @@ -12,10 +12,6 @@ def new_ticket(attributes, type = nil)

include TestData
context "content change request" do
should "set the tags correctly for valid inside govt tickets" do
assert_includes new_ticket(:inside_government => "yes").tags, 'inside_government'
end

should "set the requester details correctly" do
ticket = new_ticket(
:name => "John Smith",
Expand Down

0 comments on commit 268b5f5

Please sign in to comment.