Skip to content
Browse files

Merge pull request #12 from alphagov/moving_forms_to_new_architecture…

…_part1

Moving forms to new architecture part1
  • Loading branch information...
2 parents cdedd32 + 6cd279a commit 4aaa277e2f56bf77609306e314c2cd7eee589f0b @jamiecobbett jamiecobbett committed Nov 26, 2012
Showing with 422 additions and 215 deletions.
  1. +8 −8 app/controllers/content_change_requests_controller.rb
  2. +10 −7 app/controllers/create_new_user_requests_controller.rb
  3. +1 −1 app/controllers/general_requests_controller.rb
  4. +1 −0 app/controllers/new_feature_requests_controller.rb
  5. +13 −0 app/models/content_change_request.rb
  6. +12 −0 app/models/create_new_user_request.rb
  7. +3 −1 app/models/new_feature_request.rb
  8. +1 −1 app/models/time_constraint.rb
  9. +3 −0 app/models/with_inside_government.rb
  10. +6 −0 app/views/content_change_requests/_request_details.html.erb
  11. +7 −33 app/views/content_change_requests/new.html.erb
  12. +9 −0 app/views/create_new_user_requests/_request_details.html.erb
  13. +5 −20 app/views/create_new_user_requests/new.html.erb
  14. +5 −0 app/views/general_requests/_request_details.html.erb
  15. +1 −5 app/views/general_requests/new.html.erb
  16. +7 −0 app/views/new_feature_requests/_request_details.html.erb
  17. +2 −8 app/views/new_feature_requests/new.html.erb
  18. +1 −0 app/views/support/_inside_government_new.html.erb
  19. +3 −2 config/initializers/validates_timeliness.rb
  20. +34 −0 features/content_change_requests.feature
  21. +30 −0 features/create_new_user_requests.feature
  22. +40 −0 features/step_definitions/request_steps.rb
  23. +32 −9 lib/comment_snippet.rb
  24. +33 −0 lib/content_change_request_zendesk_ticket.rb
  25. +29 −0 lib/create_new_user_request_zendesk_ticket.rb
  26. +4 −4 lib/general_request_zendesk_ticket.rb
  27. +0 −24 lib/guard.rb
  28. +4 −5 lib/new_feature_request_zendesk_ticket.rb
  29. +5 −33 lib/zendesk_ticket.rb
  30. +4 −4 test/functional/content_change_requests_controller_test.rb
  31. +4 −4 test/functional/create_new_user_requests_controller_test.rb
  32. +20 −27 test/test_data.rb
  33. +50 −11 test/unit/comment_snippet_test.rb
  34. +18 −0 test/unit/models/content_change_request_test.rb
  35. +13 −0 test/unit/models/create_new_user_request_test.rb
  36. +0 −2 test/unit/models/general_request_test.rb
  37. +4 −0 test/unit/models/time_constraint_test.rb
  38. +0 −6 test/unit/zendesk_ticket_test.rb
View
16 app/controllers/content_change_requests_controller.rb
@@ -1,15 +1,15 @@
-require 'guard'
+require 'content_change_request_zendesk_ticket'
class ContentChangeRequestsController < RequestsController
- def new
- @formdata = {}
- prepopulate_organisation_list
+ def new_request
+ ContentChangeRequest.new(:requester => Requester.new, :time_constraint => TimeConstraint.new)
end
- def create
- @template = "content_change_requests/new"
+ def zendesk_ticket_class
+ ContentChangeRequestZendeskTicket
+ end
- @errors = Guard.validationsForAmendContent(params)
- on_post(params, "amend-content")
+ def parse_request_from_params
+ ContentChangeRequest.new(params[:content_change_request])
end
end
View
17 app/controllers/create_new_user_requests_controller.rb
@@ -1,13 +1,16 @@
+require 'create_new_user_request_zendesk_ticket'
+
class CreateNewUserRequestsController < RequestsController
- def new
- @formdata = {}
- prepopulate_organisation_list
+ protected
+ def new_request
+ CreateNewUserRequest.new(:requester => Requester.new)
end
- def create
- @template = "create_new_user_requests/new"
+ def zendesk_ticket_class
+ CreateNewUserRequestZendeskTicket
+ end
- @errors = Guard.validationsForCreateUser(params)
- on_post(params, "create-user")
+ def parse_request_from_params
+ CreateNewUserRequest.new(params[:create_new_user_request])
end
end
View
2 app/controllers/general_requests_controller.rb
@@ -1,7 +1,7 @@
require 'general_request_zendesk_ticket'
class GeneralRequestsController < RequestsController
-
+ protected
def new_request
GeneralRequest.new(:requester => Requester.new)
end
View
1 app/controllers/new_feature_requests_controller.rb
@@ -1,6 +1,7 @@
require 'new_feature_request_zendesk_ticket'
class NewFeatureRequestsController < RequestsController
+ protected
def new_request
NewFeatureRequest.new(:requester => Requester.new, :time_constraint => TimeConstraint.new)
end
View
13 app/models/content_change_request.rb
@@ -0,0 +1,13 @@
+require 'tableless_model'
+require 'with_requester'
+require 'with_time_constraint'
+require 'with_inside_government'
+
+class ContentChangeRequest < TablelessModel
+ include WithRequester
+ include WithTimeConstraint
+ include WithInsideGovernment
+
+ attr_accessor :details_of_change, :url1, :url2, :url3
+ validates_presence_of :details_of_change
+end
View
12 app/models/create_new_user_request.rb
@@ -0,0 +1,12 @@
+require 'tableless_model'
+require 'with_requester'
+require 'with_inside_government'
+
+class CreateNewUserRequest < TablelessModel
+ include WithRequester
+ include WithInsideGovernment
+
+ attr_accessor :user_name, :user_email, :additional_comments
+ validates_presence_of :user_name, :user_email
+ validates :user_email, :format => {:with => /@/}
+end
View
4 app/models/new_feature_request.rb
@@ -1,11 +1,13 @@
require 'tableless_model'
require 'with_requester'
require 'with_time_constraint'
+require 'with_inside_government'
class NewFeatureRequest < TablelessModel
include WithRequester
include WithTimeConstraint
+ include WithInsideGovernment
- attr_accessor :user_need, :url_of_example, :inside_government
+ attr_accessor :user_need, :url_of_example
validates_presence_of :user_need
end
View
2 app/models/time_constraint.rb
@@ -5,5 +5,5 @@ class TimeConstraint < TablelessModel
validates_date :needed_by_date, :allow_nil => true, :allow_blank => true, :on_or_after => :today
validates_date :not_before_date, :allow_nil => true, :allow_blank => true, :on_or_after => :today
- validates_date :not_before_date, :before => :needed_by_date, :unless => Proc.new { |c| c.needed_by_date.nil? || c.needed_by_date.blank? }
+ validates_date :not_before_date, :before => :needed_by_date, :unless => Proc.new { |c| c.needed_by_date.blank? || c.not_before_date.blank? }
end
View
3 app/models/with_inside_government.rb
@@ -0,0 +1,3 @@
+module WithInsideGovernment
+ attr_accessor :inside_government
+end
View
6 app/views/content_change_requests/_request_details.html.erb
@@ -0,0 +1,6 @@
+<%= f.inputs :name => "URL(s) affected" do %>
+ <%= f.input :url1, :label => "URL 1", :input_html => {:class => "span6", :placeholder => "http://www.gov.uk/"} %>
+ <%= f.input :url2, :label => "URL 2", :input_html => {:class => "span6", :placeholder => "http://www.gov.uk/"} %>
+ <%= f.input :url3, :label => "URL 3", :input_html => {:class => "span6", :placeholder => "http://www.gov.uk/"} %>
+ <%= f.input :details_of_change, :as => :text, :label => "Details of the requested change", :required => :true, :input_html => {:class => "span6", :rows => 6, :cols => 50, :"aria-required" => true } %>
+<% end %>
View
40 app/views/content_change_requests/new.html.erb
@@ -19,47 +19,21 @@
</div>
<div class="well">
- <%= form_tag(content_change_request_path) do %>
- <%= render "support/author" %>
+ <%= semantic_form_for @request, :url => { :action => "create" }, :html => { :novalidate => false } do |f| %>
- <%= render "support/inside_government" %>
+ <%= render :partial => "support/requester", :locals => {:f => f} %>
- <fieldset>
- <legend>URL(s) affected</legend>
+ <%= render :partial => "support/inside_government_new", :locals => {:f => f} %>
- <label class="visuallyhidden" for="target_url1">URL 1</label>
- <input class="span6 input-block-level" id="target_url1" name="url1" type="text" placeholder="http://www.gov.uk/" <%= render "support/assignvalue", {:param => @formdata[:url1]} %> >
+ <%= render :partial => "request_details", :locals => {:f => f} %>
- <label class="visuallyhidden" for="target_url2">URL 2</label>
- <input class="span6 input-block-level" id="target_url2" name="url2" type="text" placeholder="http://www.gov.uk/" <%= render "support/assignvalue", {:param => @formdata[:url2]} %> >
-
- <label class="visuallyhidden" for="target_url3">URL 3</label>
- <input class="span6 input-block-level" id="target_url3" name="url3" type="text" placeholder="http://www.gov.uk/" <%= render "support/assignvalue", {:param => @formdata[:url3]} %> >
-
- <div class="comments">
- <label for="add_content">Details of the requested change:</label>
- <textarea class="span6" id="add_content" name="add_content" rows="6" cols="70"><%= @formdata[:add_content] %></textarea>
- </div>
-
- </fieldset>
-
- <%= render "support/date", {:title => "MUST be published by (optional)", :label => 'need_by', :day => @formdata[:need_by_day], :month => @formdata[:need_by_month], :year => @formdata[:need_by_year]} %>
- <%= render "support/errors", {errors: @errors, key: "Need by"} %>
-
- <%= render "support/date", {:title => "MUST NOT be published BEFORE (optional)", :label => 'not_before', :day => @formdata[:not_before_day], :month => @formdata[:not_before_month], :year => @formdata[:not_before_year]} %>
- <%= render "support/errors", {errors: @errors, key: "Not before"} %>
-
- <fieldset>
- <div class="comments">
- <label for="comments">Reason for the above dates (optional):</label>
- <textarea class="span6" id="comments" rows="3" cols="70" name="additional"><%= @formdata[:additional] %></textarea>
- </div>
- </fieldset>
+ <%= render :partial => "support/time_constraint", :locals => {:f => f} %>
<div class="alert alert-info alert-block">
<p>If your request is urgent, please fill in this form then call 07827 992603 to let us know. (It's ONLY urgent when the public or the government is facing immediate and significant financial, legal or physical risk.)</p>
</div>
- <input class="btn btn-success" name="commit" type="submit" value="Submit">
+ <%= f.action :submit, :label => "Submit", :button_html => {:class => "btn btn-success"} %>
<% end %>
</div>
+
View
9 app/views/create_new_user_requests/_request_details.html.erb
@@ -0,0 +1,9 @@
+<div id="user_details" %>
+ <%= f.inputs "User details" do %>
+ <%= f.input :user_name, :label => "Name", :required => true, :input_html => {:class => "span6", :"aria-required" => true } %>
+
+ <%= f.input :user_email, :as => :email, :label => "Email", :required => true, :input_html => {:class => "span6", :"aria-required" => true } %>
+
+ <%= f.input :additional_comments, :as => :text, :label => "Additional comments (specify editor or writer as required for Inside Government)", :input_html => {:class => "span6", :rows => 6, :cols => 50 } %>
+ <% end %>
+</div>
View
25 app/views/create_new_user_requests/new.html.erb
@@ -2,29 +2,14 @@
<%= content_for :header, "Create a new user account" %>
<div class="well">
- <%= form_tag(create_new_user_request_path) do %>
- <%= render "support/author" %>
- <%= render "support/inside_government" %>
+ <%= semantic_form_for @request, :url => { :action => "create" }, :html => { :novalidate => false} do |f| %>
- <section id="user">
- <header class="section-header">User details</header>
+ <%= render :partial => "support/requester", :locals => {:f => f} %>
- <label for="user_name">Name (required)</label>
- <input id="user_name" name="user_name" class="span6" type="text" required aria-required="true" <%= render "support/assignvalue", {:param => @formdata[:user_name]} %>>
- <%= render "support/errors", {errors: @errors, key: "User name"} %>
+ <%= render :partial => "support/inside_government_new", :locals => {:f => f} %>
- <label for="email">Email (required)</label>
- <input id="email" name="user_email" class="span6" type="email" required aria-required="true" <%= render "support/assignvalue", {:param => @formdata[:user_email]} %>>
- <%= render "support/errors", {errors: @errors, key: "User email"} %>
+ <%= render :partial => "request_details", :locals => {:f => f} %>
- <fieldset>
- <div class="comments">
- <label for="comments">Additional comments (specify editor or writer as required for Inside Government)</label>
- <textarea id="comments" rows="6" cols="50" class="span6" name="additional"><%= @formdata[:additional] %></textarea>
- </div>
- </fieldset>
-
- </section>
- <input class="btn btn-success" name="commit" type="submit" value="Submit">
+ <%= f.action :submit, :label => "Submit", :button_html => {:class => "btn btn-success"} %>
<% end %>
</div>
View
5 app/views/general_requests/_request_details.html.erb
@@ -0,0 +1,5 @@
+<%= f.inputs "Details of your problem, request or suggestion" do %>
+ <%= f.input :additional, :as => :text, :label => "Details", :input_html => {:class => "span6", :rows => 6, :cols => 50 } %>
+
+ <%= f.input :url, :label => "URL (if applicable)", :input_html => {:class => "span6"} %>
+<% end %>
View
6 app/views/general_requests/new.html.erb
@@ -10,11 +10,7 @@
<%= render :partial => "support/requester", :locals => {:f => f} %>
- <%= f.inputs "Details of your problem, request or suggestion" do %>
- <%= f.input :additional, :as => :text, :label => "Details", :input_html => {:class => "span6", :rows => 6, :cols => 50 } %>
-
- <%= f.input :url, :label => "URL (if applicable)", :input_html => {:class => "span6"} %>
- <% end %>
+ <%= render :partial => "request_details", :locals => {:f => f} %>
<%= f.action :submit, :label => "Submit", :button_html => {:class => "btn btn-success"} %>
<% end %>
View
7 app/views/new_feature_requests/_request_details.html.erb
@@ -0,0 +1,7 @@
+<%= f.inputs :name => "Details of the new feature/need" do %>
+
+ <%= f.input :user_need, :as => :text, :required => :true, :label => "What is the user need/feature request?", :input_html => {:"aria-required" => true, :class => "span6", :rows => 6, :cols => 50 } %>
+
+ <%= f.input :url_of_example, :label => "Can you provide a link to an example of this feature?", :input_html => {:class => "span6", :placeholder => "http://www.example.com/"} %>
+
+<% end %>
View
10 app/views/new_feature_requests/new.html.erb
@@ -6,15 +6,9 @@
<%= render :partial => "support/requester", :locals => {:f => f} %>
- <%= f.inputs :name => "Details of the new feature/need" do %>
+ <%= render :partial => "support/inside_government_new", :locals => {:f => f} %>
- <%= f.input :user_need, :as => :text, :required => :true, :label => "What is the user need/feature request?", :input_html => {:"aria-required" => true, :class => "span6", :rows => 6, :cols => 50 } %>
-
- <%= f.input :url_of_example, :label => "Can you provide a link to an example of this feature?", :input_html => {:class => "span6", :placeholder => "http://www.example.com/"} %>
-
- <%= f.input :inside_government, :as => :select, :label => "Does this affect Inside Government?", :collection => [["No", "no"], ["Yes", "yes"]], :include_blank => false %>
-
- <% end %>
+ <%= render :partial => "request_details", :locals => {:f => f} %>
<%= render :partial => "support/time_constraint", :locals => {:f => f} %>
View
1 app/views/support/_inside_government_new.html.erb
@@ -0,0 +1 @@
+ <%= f.input :inside_government, :as => :select, :label => "Does this affect Inside Government?", :collection => [["No", "no"], ["Yes", "yes"]], :include_blank => false %>
View
5 config/initializers/validates_timeliness.rb
@@ -24,7 +24,7 @@
# )
#
# Use the plugin date/time parser which is stricter and extendable
- # config.use_plugin_parser = false
+ config.use_plugin_parser = true
#
# Add one or more formats making them valid. e.g. add_formats(:date, 'd(st|rd|th) of mmm, yyyy')
# config.parser.add_formats()
@@ -36,5 +36,6 @@
# config.parser.ambiguous_year_threshold = 30
#
# Treat ambiguous dates, such as 01/02/1950, as a Non-US date.
- # config.parser.remove_us_formats
+ config.parser.remove_us_formats
+ config.parser.use_euro_formats
end
View
34 features/content_change_requests.feature
@@ -0,0 +1,34 @@
+Feature: Content change requests
+ In order to update or fix the information on gov.uk
+ As a government employee
+ I want a means to inform GDS about a problem with content
+
+ Background:
+ * the following user has SSO access:
+ | Name | Email | Job title | Organisation | Phone |
+ | John Smith | john.smith@email.com | Developer | Cabinet Office | 12345 |
+
+ Scenario: successful 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 |
+
+ 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 |
+ And the time constraints on the ticket are:
+ | Need by date | Not before date |
+ | 31-12-2012 | 01-12-2012 |
+ And the ticket is tagged with "content_amend"
+ And the comment on the ticket is:
+ """
+ [URl(s) of content to be changed]
+ http://gov.com/X
+ http://gov.uk/Y
+
+ [Details of what should be added, amended or removed]
+ Out of date XX YY
+
+ [Time constraint reason]
+ New law
+ """
View
30 features/create_new_user_requests.feature
@@ -0,0 +1,30 @@
+Feature: Create new user requests
+ In order to allow new departments to submit requests to GDS
+ As well as to allow for existing departments to shift responsibilities around
+ As a government employee
+ I want a means to request GDS tool access for other users
+
+ Background:
+ * the following user has SSO access:
+ | Name | Email | Job title | Organisation | Phone |
+ | John Smith | john.smith@email.com | Developer | Cabinet Office | 12345 |
+
+ Scenario: successful request
+ When the user submits the following create user request:
+ | User's name | User's email | Additional comments |
+ | Bob Fields | bob@gov.uk | Editor |
+ 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 |
+ And the ticket is tagged with "new_user"
+ And the comment on the ticket is:
+ """
+ [User name]
+ Bob Fields
+
+ [User email]
+ bob@gov.uk
+
+ [Additional comments]
+ Editor
+ """
View
40 features/step_definitions/request_steps.rb
@@ -50,4 +50,44 @@
step "the user fills out the time constraints"
step "the user submits the request successfully"
+end
+
+When /^the user submits the following content change request:$/ do |request_details_table|
+ @request_details = request_details_table.hashes.first
+
+ visit '/'
+
+ click_on "Content change"
+
+ assert page.has_content?("Request a change")
+
+ step "the user fills out their details"
+
+ 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"]
+ fill_in "URL 3", :with => @request_details["URL 3"]
+
+ step "the user fills out the time constraints"
+ step "the user submits the request successfully"
+end
+
+When /^the user submits the following create user request:$/ do |request_details_table|
+ @request_details = request_details_table.hashes.first
+
+ visit '/'
+
+ click_on "Create new user"
+
+ assert page.has_content?("Create a new user account")
+
+ step "the user fills out their details"
+
+ within("#user_details") do
+ fill_in "Name", :with => @request_details["User's name"]
+ fill_in "Email", :with => @request_details["User's email"]
+ fill_in "Additional comments (specify editor or writer as required for Inside Government)", :with => @request_details["Additional comments"]
+ end
+
+ step "the user submits the request successfully"
end
View
41 lib/comment_snippet.rb
@@ -1,25 +1,48 @@
require 'active_support/inflector'
class CommentSnippet
- def initialize(data_provider, field_name)
- @data_provider = data_provider
- @field_name = field_name
+ def initialize(options)
+ @options = options
end
def to_s
- pretty_field_name + field_value
+ comment_label + comment_body
end
def applies?
- @data_provider.respond_to?(@field_name) && !field_value.nil? && !field_value.empty?
+ !applicable_fields.empty?
end
- def field_value
- @data_provider.send(@field_name)
+ protected
+ def comment_label
+ "[#{label_text}]\n"
+ end
+
+ def label_text
+ @options[:label] || pretty_field_name
end
- protected
def pretty_field_name
- "[#{@field_name.to_s.humanize}]\n"
+ @options[:field].to_s.humanize
+ end
+
+ def field_names
+ @options[:fields] || [@options[:field]]
+ end
+
+ def comment_body
+ applicable_fields.collect { |field_name| value_of(field_name) }.join("\n")
+ end
+
+ def applicable_fields
+ field_names.select { |field_name| field_name_applies?(field_name) }
+ end
+
+ def value_of(field_name)
+ @options[:on].send(field_name)
+ end
+
+ def field_name_applies?(field_name)
+ @options[:on].respond_to?(field_name) && !value_of(field_name).nil? && !value_of(field_name).empty?
end
end
View
33 lib/content_change_request_zendesk_ticket.rb
@@ -0,0 +1,33 @@
+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
+
+ def request_specific_tag
+ "content_amend"
+ 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, 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) ]
+ end
+end
View
29 lib/create_new_user_request_zendesk_ticket.rb
@@ -0,0 +1,29 @@
+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
+
+ def request_specific_tag
+ "new_user"
+ 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: :user_name),
+ CommentSnippet.new(on: @request, field: :user_email),
+ CommentSnippet.new(on: @request, field: :additional_comments) ]
+ end
+end
View
8 lib/general_request_zendesk_ticket.rb
@@ -21,9 +21,9 @@ def request_specific_tag
protected
def comment_snippets
- [ CommentSnippet.new(@request.requester, :other_organisation),
- CommentSnippet.new(@request, :url),
- CommentSnippet.new(@request, :user_agent),
- CommentSnippet.new(@request, :additional) ]
+ [ 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) ]
end
end
View
24 lib/guard.rb
@@ -2,31 +2,7 @@
class Guard
- #Content validations
- def self.validationsForAmendContent(form_data)
- @@errors = {}
- required = ["name", "email", "job"]
- validate(form_data, required, {"phone" => form_data["phone"]}, {"email" => form_data["email"]})
- self.checkOptionalDateFieldsAreComplete(form_data, [["Need by", "need_by_day", "need_by_month", "need_by_year"], ["Not before", "not_before_day", "not_before_month", "not_before_year"]])
-
- need_by = validate_date_in_valid_range("Need by", "need_by_day", "need_by_month", "need_by_year", form_data)
- not_before = validate_date_in_valid_range("Not before", "not_before_day", "not_before_month", "not_before_year", form_data)
-
- self.validate_date_is_equal_or_greater_than_today("Need by", need_by, "Changes can only be made after today.")
- self.validate_not_before_date_is_equal_or_greater_than_need_by(not_before, need_by, "Not before date should be the same or later than the date which the changes are required to be made on.")
-
- @@errors
- end
-
#User validations
- def self.validationsForCreateUser(form_data)
- @@errors = {}
- required = ["name", "email", "job", "user_name", "user_email"]
- validate(form_data, required, {"phone" => form_data["phone"]}, {"email" => form_data["email"]})
-
- @@errors
- end
-
def self.validationsForDeleteUser(form_data)
@@errors = {}
View
9 lib/new_feature_request_zendesk_ticket.rb
@@ -8,7 +8,6 @@ class NewFeatureRequestZendeskTicket < ZendeskTicket
def initialize(request)
super(request, nil)
@requester = request.requester
- @time_constraint = request.time_constraint
end
def subject
@@ -24,9 +23,9 @@ def request_specific_tag
protected
def comment_snippets
- [ CommentSnippet.new(@request.requester, :other_organisation),
- CommentSnippet.new(@request, :user_need),
- CommentSnippet.new(@request, :url_of_example),
- CommentSnippet.new(@request.time_constraint, :time_constraint_reason) ]
+ [ 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) ]
end
end
View
38 lib/zendesk_ticket.rb
@@ -1,26 +1,21 @@
require 'forwardable'
require 'date'
+require 'active_support'
class ZendeskTicket
extend Forwardable
- @@in_comments = {"amend-content" => [:other_organisation, :url1, :url2, :url3],
- "create-user" => [:other_organisation, :user_name, :user_email, :additional],
- "remove-user" => [:other_organisation, :user_name, :user_email, :additional],
+ @@in_comments = {"remove-user" => [:other_organisation, :user_name, :user_email, :additional],
"campaign" => [:other_organisation, :campaign_name, :erg_number, :company, :description, :url, :additional],
"publish-tool" => [:other_organisation, :username, :url, :user_agent, :additional]
}
- @@in_subject = {"amend-content" => "Content change request",
- "create-user" => "Create new user",
- "remove-user" => "Remove user",
+ @@in_subject = {"remove-user" => "Remove user",
"campaign" => "Campaign",
"publish-tool" => "Publishing Tool"
}
- @@in_tag = {"amend-content" => "content_amend",
- "create-user" => "new_user",
- "remove-user" => "remove_user",
+ @@in_tag = {"remove-user" => "remove_user",
"campaign" => "campaign",
"publish-tool" => "publishing_tool_tech"
}
@@ -105,13 +100,11 @@ def inside_government_tag
def has_value?(param, target = nil)
target ||= @request
- target.respond_to?(param) and not target.send(param).nil? and not target.send(param).to_s.strip.empty?
+ target.respond_to?(param) and not target.send(param).blank?
end
def format_comment(from_route, request)
case from_route
- when "amend-content" then
- format_comment_for_amend_content(request)
when "publish-tool" then
format_comment_for_tech_issues(from_route, request)
else
@@ -150,27 +143,6 @@ def format_comment_for_tech_issues(from_route, request)
end
end
- def format_comment_for_amend_content(request)
- comments_sections = {"[URl(s) of content to be changed]" => [build_full_url_path(request.url1), build_full_url_path(request.url2), build_full_url_path(request.url3)],
- "[Details of what should be added, amended or removed]" => [request.add_content],
- "[Additional Comments]" => [request.additional]
- }
-
- comments = comments_sections.map do |key, value|
- allvalues = value.join("\n")
- if !allvalues.chomp.strip.empty?
- key+"\n"+allvalues.chomp.strip
- end
- end
-
- if !comments.join.empty?
- comments.join("\n\n")
- else
- comments.join
- end
-
- end
-
def remove_space_from_phone_number(number)
number.gsub(/\s+/, "")
end
View
8 test/functional/content_change_requests_controller_test.rb
@@ -18,7 +18,7 @@ class ContentChangeRequestsControllerTest < ActionController::TestCase
should "use ZenDesk to populate the organisation dropdown" do
get :new
- assert_select "select#organisation_list option", "Advocate General for Scotland"
+ assert_select "select#content_change_request_requester_attributes_organisation option", "Advocate General for Scotland"
end
should "inform the user if ZenDesk is unreachable" do
@@ -31,11 +31,11 @@ class ContentChangeRequestsControllerTest < ActionController::TestCase
context "a submitted content change request" do
should "reject invalid change requests" do
- params = valid_content_change_request_params.merge("organisation" => "")
+ params = valid_content_change_request_params.tap {|p| p["content_change_request"]["requester_attributes"].merge!("organisation" => "")}
post :create, params
assert_response 400
assert_template "new"
- assert_select ".help-block", /Organisation information is required/
+ assert_select ".help-inline", /information is required/
end
should "submit it to ZenDesk" do
@@ -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.merge("inside_government" => "yes")
+ params = valid_content_change_request_params.tap {|p| p["content_change_request"].merge!("inside_government" => "yes")}
post :create, params
View
8 test/functional/create_new_user_requests_controller_test.rb
@@ -22,17 +22,17 @@ class CreateNewUserRequestsControllerTest < ActionController::TestCase
should "use ZenDesk to populate the organisation dropdown" do
get :new
- assert_select "select#organisation_list option", "Advocate General for Scotland"
+ 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.merge("organisation" => "")
+ params = valid_create_new_user_request_params.tap {|p| p["create_new_user_request"]["requester_attributes"].merge!("organisation" => "")}
post :create, params
assert_response 400
assert_template "new"
- assert_select ".help-block", /Organisation information is required/
+ assert_select ".help-inline", /information is required/
end
should "submit it to ZenDesk" do
@@ -46,7 +46,7 @@ class CreateNewUserRequestsControllerTest < ActionController::TestCase
context "concerning Inside Government" do
should "tag the ticket with an inside_government tag" do
- params = valid_create_new_user_request_params.merge("inside_government" => "yes")
+ params = valid_create_new_user_request_params.tap {|p| p["create_new_user_request"].merge!("inside_government" => "yes")}
post :create, params
View
47 test/test_data.rb
@@ -1,35 +1,21 @@
module TestData
def valid_content_change_request_params
- { "name"=>"Testing",
- "email"=>"testing@digital.cabinet-office.gov.uk",
- "job"=>"Dev",
- "phone"=>"",
- "organisation"=>"cabinet_office",
- "other_organisation"=>"",
- "inside_government" => "no",
- "url1"=>"",
- "url2"=>"",
- "url3"=>"",
- "add_content"=>"",
- "need_by_day"=>"",
- "need_by_month"=>"",
- "need_by_year"=>"",
- "not_before_day"=>"",
- "not_before_month"=>"",
- "not_before_year"=>"",
- "additional"=>"" }
+ {"content_change_request" =>
+ { "requester_attributes" => valid_requester_params,
+ "time_constraint_attributes" => valid_time_constraint_params,
+ "url1" => "http://www.gov.uk",
+ "details_of_change" => "Content is wrong"}
+ }
end
def valid_create_new_user_request_params
- { "name"=>"Testing",
- "email"=>"testing@digital.cabinet-office.gov.uk",
- "job"=>"dev",
- "phone"=>"",
- "organisation"=>"cabinet_office",
- "other_organisation"=>"",
- "user_name"=>"subject",
- "user_email"=>"subject@digital.cabinet-office.gov.uk",
- "additional"=>"" }
+ { "create_new_user_request" =>
+ { "requester_attributes" => valid_requester_params,
+ "user_name"=>"subject",
+ "user_email"=>"subject@digital.cabinet-office.gov.uk",
+ "inside_government" => "no",
+ "additional_comments"=>"" }
+ }
end
def valid_remove_user_request_params
@@ -82,4 +68,11 @@ def valid_requester_params
"other_organisation"=>"",
}
end
+
+ def valid_time_constraint_params
+ { "needed_by_date" => "01-01-2013",
+ "not_before_date" => "01-12-2012",
+ "time_constraint_reason" => "Legal requirement"
+ }
+ end
end
View
61 test/unit/comment_snippet_test.rb
@@ -4,21 +4,60 @@
require 'comment_snippet'
class CommentSnippetTest < Test::Unit::TestCase
- should "prettify the field name" do
- data_provider = OpenStruct.new(:my_field_name => "abc")
- assert_includes CommentSnippet.new(data_provider, :my_field_name).to_s, "[My field name]"
+ def snippet(opts)
+ CommentSnippet.new(opts)
end
- should "include the field value" do
- data_provider = OpenStruct.new(:my_field_name => "abc")
- assert_includes CommentSnippet.new(data_provider, :my_field_name).to_s, "abc"
+ def data(opts = {})
+ OpenStruct.new(opts)
end
- context "when the field isn't provided or is empty" do
- should "not apply" do
- data_provider = OpenStruct.new(:a_nil_field => nil, :an_empty_field => "")
- assert !CommentSnippet.new(data_provider, :a_nil_field).applies?
- assert !CommentSnippet.new(data_provider, :an_empty_field).applies?
+ context "with a single field" do
+ should "format the comment with the provided label" do
+ data_provider = data(my_field_name: "abc")
+ assert_includes snippet(on: data_provider, field: :my_field_name, label: "Abc").to_s, "[Abc]"
+ end
+
+ should "prettify the field name when no label is specified" do
+ data_provider = data(my_field_name: "abc")
+ assert_includes snippet(on: data_provider, field: :my_field_name).to_s, "[My field name]"
+ end
+
+ should "include the field value" do
+ data_provider = data(my_field_name: "abc")
+ assert_includes snippet(on: data_provider, field: :my_field_name).to_s, "abc"
+ end
+
+ should "not apply when the field is not defined" do
+ assert !snippet(on: data(), field: :non_existent_field).applies?
+ end
+
+ should "not apply when the field value is nil or empty" do
+ assert !snippet(on: data(a_nil_field: nil), field: :a_nil_field).applies?
+ assert !snippet(on: data(an_empty_field: ""), field: :an_empty_field).applies?
+ end
+ end
+
+ context "with multiple fields" do
+ should "apply only if one of the fields is set" do
+ assert snippet(on: data(f1: "abc"), fields: [:f1, :f2], label: "Fields").applies?
+ assert snippet(on: data(f1: "abc", f2: "xyz"), fields: [:f1, :f2], label: "Fields").applies?
+
+ assert !snippet(on: data(), fields: [:f1, :f2], label: "Fields").applies?
+ assert !snippet(on: data(f1: nil), fields: [:f1, :f2], label: "Fields").applies?
+ assert !snippet(on: data(f1: ""), fields: [:f1, :f2], label: "Fields").applies?
+ end
+
+ should "concatenate field values with newlines if multiple fields are specified" do
+ data_provider = data(f1: "abc", f2: "def", f3: "ghi")
+ snippet = snippet(on: data_provider, fields: [:f1, :f2, :f3], label: "Fields")
+ assert_includes snippet.to_s, "[Fields]\nabc\ndef\nghi"
+ end
+
+ should "concatenate only those field values that are defined" do
+ data_provider = data(f1: "abc", f2: nil, f3: "", f4: "def")
+ snippet = snippet(on: data_provider, fields: [:f1, :f2, :f3, :f4], label: "Fields")
+ assert_includes snippet.to_s, "[Fields]\nabc\ndef"
end
end
end
View
18 test/unit/models/content_change_request_test.rb
@@ -0,0 +1,18 @@
+require 'test_helper'
+
+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 allow_value("http://www.gov.uk").for(:url1)
+ should allow_value("http://www.gov.uk").for(:url2)
+ should allow_value("http://www.gov.uk").for(:url3)
+
+ should "allow time constraints" do
+ request = ContentChangeRequest.new(:time_constraint => stub("time constraint", :valid? => true))
+ request.valid?
+ assert_equal 0, request.errors[:time_constraint].size
+ end
+end
View
13 test/unit/models/create_new_user_request_test.rb
@@ -0,0 +1,13 @@
+require 'test_helper'
+
+class CreateNewUserRequestTest < Test::Unit::TestCase
+ should validate_presence_of(:requester)
+ should validate_presence_of(:user_name)
+ should validate_presence_of(:user_email)
+
+ should allow_value("ab@c.com").for(:user_email)
+ should_not allow_value("ab").for(:user_email)
+
+ should allow_value("a comment").for(:additional_comments)
+ should allow_value("yes").for(:inside_government)
+end
View
2 test/unit/models/general_request_test.rb
@@ -1,8 +1,6 @@
require 'test_helper'
class GeneralRequestTest < Test::Unit::TestCase
- include TestData
-
should validate_presence_of(:requester)
should allow_value("http://www.gov.uk").for(:url)
View
4 test/unit/models/time_constraint_test.rb
@@ -32,4 +32,8 @@ def as_str(date)
assert !constraint.valid?
assert constraint.errors[:not_before_date].size > 0
end
+
+ should "allow a blank not_before_date if the needed_by_date is set" do
+ assert TimeConstraint.new(:needed_by_date => as_str(Date.tomorrow)).valid?
+ end
end
View
6 test/unit/zendesk_ticket_test.rb
@@ -12,10 +12,6 @@ def new_ticket(attributes, type = nil)
include TestData
context "content change request" do
- should "set the tags correctly for content change requests" do
- assert_equal ['content_amend'], new_ticket({}, 'amend-content').tags
- end
-
should "set the tags correctly for valid inside govt tickets" do
assert_includes new_ticket(:inside_government => "yes").tags, 'inside_government'
end
@@ -60,8 +56,6 @@ def new_ticket(attributes, type = nil)
end
should "set the subject according to request type" do
- assert_equal "Content change request", new_ticket({}, "amend-content").subject
- assert_equal "Create new user", new_ticket({}, "create-user").subject
assert_equal "Remove user", new_ticket({}, "remove-user").subject
assert_equal "Campaign", new_ticket({}, "campaign").subject
assert_equal "Publishing Tool", new_ticket({}, "publish-tool").subject

0 comments on commit 4aaa277

Please sign in to comment.
Something went wrong with that request. Please try again.