Skip to content
Browse files

Merge pull request #15 from alphagov/last_part_of_rearchitecture

Last part of rearchitecture
  • Loading branch information...
2 parents d70a29a + ca8a66d commit fbf33a151db37f69a2ed8f2bb495b25b7817151d @jamiecobbett jamiecobbett committed Nov 28, 2012
View
16 app/controllers/campaign_requests_controller.rb
@@ -0,0 +1,16 @@
+require 'campaign_request_zendesk_ticket'
+
+class CampaignRequestsController < RequestsController
+ protected
+ def new_request
+ CampaignRequest.new(:requester => Requester.new, :campaign => Campaign.new)
+ end
+
+ def zendesk_ticket_class
+ CampaignRequestZendeskTicket
+ end
+
+ def parse_request_from_params
+ CampaignRequest.new(params[:campaign_request])
+ end
+end
View
24 app/controllers/requests_controller.rb
@@ -18,30 +18,6 @@ def create
end
private
-
- def on_get(template)
- load_client_and_organisations("zendesk_error_upon_new_form")
-
- @formdata = {}
- render :"#{template}", :layout => "application"
- end
-
- def on_post(params, route)
- load_client_and_organisations("zendesk_error_upon_submit")
- @formdata = params
-
- if @errors.empty?
- ticket = ZendeskRequest.raise_zendesk_request(@client, params, route)
- if ticket
- redirect_to '/acknowledge'
- else
- return render :"support/zendesk_error", :locals => {:error_string => "zendesk_error_upon_submit"}
- end
- else
- render :"#{@template}", :layout => "application", :status => 400
- end
- end
-
def raise_ticket(ticket)
load_client
View
13 app/controllers/support_controller.rb
@@ -1,17 +1,4 @@
-require "guard"
-
class SupportController < RequestsController
- def campaign
- if request.method == "GET"
- on_get("campaigns/campaign")
- elsif request.method == "POST"
- @template = "campaigns/campaign"
-
- @errors = Guard.validationsForCampaign(params)
- on_post(params, "campaign")
- end
- end
-
def landing
render :landing, :layout => "application"
end
View
8 app/models/campaign.rb
@@ -0,0 +1,8 @@
+require 'tableless_model'
+
+class Campaign < TablelessModel
+ attr_accessor :title, :erg_reference_number, :start_date, :description, :affiliated_group_or_company, :info_url
+
+ validates_presence_of :title, :erg_reference_number, :description
+ validates_date :start_date, :allow_nil => true, :allow_blank => true, :on_or_after => :today
+end
View
20 app/models/campaign_request.rb
@@ -0,0 +1,20 @@
+require 'tableless_model'
+require 'with_requester'
+
+class CampaignRequest < TablelessModel
+ include WithRequester
+
+ attr_accessor :campaign
+ validates_presence_of :campaign
+ validate do |request|
+ if request.campaign and not request.campaign.valid?
+ errors[:base] << "Campaign details are either not complete or invalid."
+ end
+ end
+
+ def campaign_attributes=(attr)
+ self.campaign = Campaign.new(attr)
+ end
+
+ attr_accessor :additional_comments
+end
View
14 app/views/campaign_requests/_campaign_details.html.erb
@@ -0,0 +1,14 @@
+<%= f.semantic_fields_for :campaign do |r| %>
+ <%= r.inputs :name => "Campaign details" do %>
+ <%= r.input :title, :label => "Campaign title", :required => true, :input_html => {:class => "span6", :"aria-required" => true} %>
+
+ <%= r.input :erg_reference_number, :label => "ERG reference number", :required => true, :input_html => {:class => "span6", :"aria-required" => true} %>
+
+ <%= r.input :start_date, :label => "Start date", :required => false, :input_html => {:"calendar-enabled" => true, :placeholder => "dd-mm-YYYY", :value => r.object.start_date} %>
+ <%= r.input :description, :as => :text, :label => "Campaign description", :required => true, :input_html => {:class => "span6", :rows => 6, :cols => 50, :"aria-required" => true } %>
+
+ <%= r.input :affiliated_group_or_company, :label => "Group or company affiliated with this campaign", :required => false, :input_html => {:class => "span6"} %>
+
+ <%= r.input :info_url, :label => "URL with more information", :required => false, :input_html => {:class => "span6"} %>
+ <% end %>
+<% end %>
View
15 app/views/campaign_requests/new.html.erb
@@ -0,0 +1,15 @@
+<%= content_for :page_title, "Campaign" %>
+<%= content_for :header, "Request GDS support for a campaign" %>
+
+<div class="well">
+ <%= semantic_form_for @request, :url => { :action => "create" }, :html => { :novalidate => false} do |f| %>
+
+ <%= render :partial => "support/requester", :locals => {:f => f} %>
+
+ <%= render :partial => "campaign_details", :locals => {:f => f} %>
+
+ <%= f.input :additional_comments, :as => :text, :label => "Additional comments", :input_html => {:class => "span6", :rows => 6, :cols => 50 } %>
+
+ <%= f.action :submit, :label => "Submit", :button_html => {:class => "btn btn-success"} %>
+ <% end %>
+</div>
View
50 app/views/campaigns/campaign.html.erb
@@ -1,50 +0,0 @@
-<%= content_for :page_title, "Campaign" %>
-<%= content_for :header, "Request GDS support for a campaign" %>
-
-<div class="well">
- <%= form_tag('/campaign', :method => :post) do %>
- <%= render "author" %>
-
- <section id="campaign">
- <header class="section-header">Campaign</header>
- <label for="name">Campaign title (required)</label>
- <input id="name" name="campaign_name" type="text" class="span6" required <%= render "assignvalue", {:param => @formdata[:campaign_name]} %>>
-
- <div>
- <label class="long" for="erg_number">ERG reference number (required)</label>
- <input id="erg_number" name="erg_number" type="text" class="span6" required aria-required="true" <%= render "assignvalue", {:param => @formdata[:erg_number]} %>>
- <%= render "errors", {errors: @errors, key: "Erg number"} %>
- </div>
-
- <%= render "date", {:title => "Start Date", :label => 'start', :day => @formdata[:start_day], :month => @formdata[:start_month], :year => @formdata[:start_year]} %>
- <%= render "errors", {errors: @errors, key: "Start date"} %>
-
- <div class="comments">
- <label for="description">Campaign description (required)</label>
- <textarea id="description" rows="6" cols="50" class="span6" name="description" type="text" required aria-required="true" ><%= @formdata[:description] %></textarea>
- <%= render "errors", {errors: @errors, key: "Description"} %>
- </div>
-
- <div>
- <label class="long" for="company">Group or company affiliated with this campaign</label>
- <input id="company" name="company" class="span6" type="text" <%= render "assignvalue", {:param => @formdata[:company]} %>>
- </div>
-
- <div style="clear:both;"></div>
-
- <div>
- <label class="long" for="target_url">URL with more information</label>
- <input id="target_url" name="url" type="text" class="span6" <%= render "assignvalue", {:param => @formdata[:url]} %>>
- </div>
-
- <fieldset>
- <div class="comments">
- <label for="comments">Additional comments</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">
- <% end %>
-</div>
View
2 app/views/layouts/application.html.erb
@@ -43,7 +43,7 @@
</ul>
<ul class="nav nav-list">
<li class="nav-header">Campaigns</li>
- <%= nav_link 'Campaign', '/campaign' %>
+ <%= nav_link 'Campaign', new_campaign_request_path %>
</ul>
<ul class="nav nav-list">
<li class="nav-header">Other Issues</li>
View
5 app/views/support/_assignvalue.erb
@@ -1,5 +0,0 @@
-<% if param %>
- value="<%= param %>"
-<% else %>
- <%= "" %>
-<% end %>
View
37 app/views/support/_author.erb
@@ -1,37 +0,0 @@
- <fieldset>
- <legend>Your details</legend>
-
- <div class="control-group">
-
- <label for="name">Name (required)</label>
- <input id="name" name="name" type="text" class="span6" required aria-required="true" <%= render "support/assignvalue", {:param => @formdata[:name]} %> >
- <%= render "support/errors", {key: "Name", errors: @errors} %>
- </div>
-
- <label for="email">Email (required)</label>
- <input id="email" name="email" type="email" class="span6" required aria-required="true" <%= render "support/assignvalue", {:param => @formdata[:email]} %> >
- <%= render "support/errors", {key: "Email", errors: @errors} %>
-
- <label for="job">Job title (required)</label>
- <input id="job" name="job" type="text" class="span6" required aria-required="true" <%= render "support/assignvalue", {:param => @formdata[:job]} %> >
- <%= render "support/errors", {key: "Job", errors: @errors} %>
-
- <label for="phone">Phone number</label>
- <input class="span6" id="phone" name="phone" pattern="([\d\s]*)" type="tel" <%= render "support/assignvalue", {:param => @formdata[:phone]} %> >
- <%= render "support/errors", {key: "Phone", errors: @errors} %>
-
- <label for="organisation_list">Organisation (required)</label>
- <select id="organisation_list" class="span6" name="organisation">
- <% @organisations.merge("Select Organisation" => "").each do |key, value| %>
- <% if value == @formdata["organisation"] %>
- <option selected="selected" value="<%= value %>"><%= key %> </option>
- <% else %>
- <option value="<%= value %>"><%= key %> </option>
- <% end %>
- <% end %>
- </select>
- <%= render "support/errors", {key: "organisation", errors: @errors} %>
-
- <label for="other_organisation">Please specify the organisation if you didn&rsquo;t find it in the list above</label>
- <input class="span6" id="other_organisation" name="other_organisation" type="text">
- </fieldset>
View
61 app/views/support/_date.erb
@@ -1,61 +0,0 @@
-<div class="form-inline">
- <fieldset>
- <legend
- <% if title.length > 10 %>
- class = "long date"
- <% else %>
- class = "date"
- <% end %>
- >
- <%= title %>
- </legend>
- <label class="visuallyhidden" for="<%= label %>_day">Day</label>
- <select id="<%= label %>_day" name="<%= label %>_day" class="input-small">
- <% if day %>
- <option value=""></option>
- <% else %>
- <option selected="selected" value=""></option>
- <% end %>
- <% for oneday in 1 .. 31 %>
- <% if oneday.to_s == day %>
- <option selected="selected" value="<%= oneday %>"><%= oneday %></option>
- <% else %>
- <option value="<%= oneday %>"><%= oneday %></option>
- <% end %>
- <% end %>
- </select>
-
- <label class="visuallyhidden" for="<%= label %>_month">Month</label>
- <select id="<%= label %>_month" name="<%= label %>_month" class="input-medium">
- <% months = {1 => "January", 2 => "February", 3 => "March", 4 => "April", 5 => "May", 6 => "June", 7 => "July", 8 => "August", 9 => "September", 10 => "October", 11 => "November", 12 => "December"} %>
- <% if month %>
- <option value=""></option>
- <% else %>
- <option selected="selected" value=""></option>
- <% end %>
- <% for onemonth in months %>
- <% if onemonth[0].to_s == month %>
- <option selected="selected" value= <%= onemonth[0] %>><%= onemonth[1] %></option>
- <% else %>
- <option value= <%= onemonth[0] %>><%= onemonth[1] %></option>
- <% end %>
- <% end %>
- </select>
-
- <label class="visuallyhidden" for="<%= label %>_year">Year</label>
- <select id="<%= label %>_year" name="<%= label %>_year" class="input-small">
- <% if year %>
- <option value=""></option>
- <% else %>
- <option selected="selected" value=""></option>
- <% end %>
- <% for oneyear in Time.now.year .. Time.now.year+5 %>
- <% if oneyear.to_s == year %>
- <option selected="selected" value= <%= oneyear %>><%= oneyear %></option>
- <% else %>
- <option value= <%= oneyear %>><%= oneyear %></option>
- <% end %>
- <% end %>
- </select>
- </fieldset>
-</div>
View
9 app/views/support/_errors.erb
@@ -1,9 +0,0 @@
-<% if errors && errors[key] %>
- <div class="control-group error">
- <% if @errors %>
- <span class="help-block">
- <%= @errors[key] %>
- </span>
- <% end %>
- </div>
-<% end %>
View
8 app/views/support/_header.erb
@@ -1,8 +0,0 @@
-<meta charset="utf-8" />
-<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
-<meta name="robots" content="noindex,nofollow">
-<META HTTP-EQUIV="Expires" CONTENT="-1">
-<!--[if lt IE 9]>
-<script src="/javascripts/html5shiv.js"></script>
-<![endif]-->
-<script type="text/javascript" src="/javascripts/jquery-1.7.2.js"></script>
View
7 app/views/support/_inside_government.html
@@ -1,7 +0,0 @@
-<fieldset>
- <label for="inside_government">Does this affect Inside Government?</label>
- <select id="inside_government" name="inside_government">
- <option selected="selected" value="no">No</option>
- <option value="yes">Yes</option>
- </select>
-</fieldset>
View
2 config/routes.rb
@@ -4,8 +4,8 @@
resource :remove_user_request, :only => [:new, :create]
resource :general_request, :only => [:new, :create]
resource :new_feature_request, :only => [:new, :create]
+ resource :campaign_request, :only => [:new, :create]
- match "campaign" => "support#campaign"
match "acknowledge" => "support#acknowledge"
root :to => 'support#landing'
end
View
41 features/campaign_requests.feature
@@ -0,0 +1,41 @@
+Feature: Campaign requests
+ In order to run a successful campaign
+ As a government employee
+ I want a means to request GDS support for a campaign
+
+ 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 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 |
+ And the ticket is tagged with "campaign"
+ And the comment on the ticket is:
+ """
+ [Campaign title]
+ Workplace pensions
+
+ [ERG reference number]
+ 123456
+
+ [Start date]
+ 01-01-2020
+
+ [Description]
+ Pensions
+
+ [Affiliated group or company]
+ AXA
+
+ [URL with more information]
+ https://www.gov.uk
+
+ [Additional comments]
+ Some comment
+ """
View
23 features/step_definitions/request_steps.rb
@@ -128,4 +128,27 @@
fill_in "MUST NOT be removed BEFORE", :with => @request_details["Not before date"]
step "the user submits the request successfully"
+end
+
+When /^the user submits the following campaign request:$/ do |request_details_table|
+ @request_details = request_details_table.hashes.first
+
+ visit '/'
+
+ click_on "Campaign"
+
+ assert page.has_content?("Request GDS support for a campaign")
+
+ step "the user fills out their details"
+
+ fill_in "Campaign title", :with => @request_details["Campaign title"]
+ fill_in "ERG reference number", :with => @request_details["ERG ref number"]
+ fill_in "Start date", :with => @request_details["Start date"]
+ fill_in "Campaign description", :with => @request_details["Description"]
+ fill_in "Group or company affiliated with this campaign", :with => @request_details["Affiliated group"]
+ fill_in "URL with more information", :with => @request_details["Info URL"]
+
+ fill_in "Additional comments", :with => @request_details["Additional comments"]
+
+ step "the user submits the request successfully"
end
View
36 lib/campaign_request_zendesk_ticket.rb
@@ -0,0 +1,36 @@
+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
+
+ 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,
+ label: "ERG reference number"),
+ CommentSnippet.new(on: @request.campaign, field: :start_date),
+ CommentSnippet.new(on: @request.campaign, field: :description),
+ 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) ]
+ end
+end
View
118 lib/guard.rb
@@ -1,118 +0,0 @@
-require "date"
-
-class Guard
- #Campaign validations
- def self.validationsForCampaign(form_data)
- @@errors = {}
- required = ["name", "email", "job", "campaign_name", "erg_number", "description"]
- validate(form_data, required, {"phone" => form_data["phone"]}, {"email" => form_data["email"]})
-
- self.checkOptionalDateFieldsAreComplete(form_data, [["Start date", "start_day", "start_month", "start_year"]])
-
- start_date = validate_date_in_valid_range("Start date", "start_day", "start_month", "start_year", form_data)
- self.validate_date_is_equal_or_greater_than_today("Start date", start_date, "Campaign start date can only be after today.")
-
- @@errors
- end
-
- private
-
- def self.validate(form_data, required, phone_fields, email_fields)
- self.checkRequiredFieldsHaveValues(required, form_data)
- self.validate_organisation_or_other_is_entered(form_data)
- self.checkPhoneIsValid(phone_fields)
- self.checkEmailIsValid(email_fields)
- end
-
- def self.checkRequiredFieldsHaveValues(required, form_data)
- required.each { |field|
- if form_data[field] && form_data[field].strip.empty?
- field = field.capitalize.gsub(/_/, " ")
- @@errors[field] = "#{field} is required for a valid request."
- end
- }
- end
-
- def self.checkPhoneIsValid(phone_fields)
- phone_fields.each do |field_name, field_value|
- if field_value && doesFieldHaveValue(field_value) && !(field_value =~ /^[\d|\s]+[\d|\s]*$/)
- field_name = field_name.capitalize.gsub(/_/, " ")
- @@errors[field_name] = "#{field_name} is a phone number field. Please enter only numbers and spaces."
- end
- end
- end
-
- def self.checkEmailIsValid(email_fields)
- email_fields.each do |field_name, field_value|
- if field_value && doesFieldHaveValue(field_value) && !(field_value =~ /^[\w\d]+[^@]*@[\w\d]+[^@]*\.[\w\d]+[^@]*$/)
- field_name = field_name.capitalize.gsub(/_/, " ")
- @@errors[field_name] = "#{field_name} is an email field. Please enter valid email like x@y.something."
- end
- end
- end
-
- def self.checkOptionalDateFieldsAreComplete(form_data, optional_date_fields)
- optional_date_fields.each do |arrayofday_month_year|
- day = form_data[arrayofday_month_year[1]]
- month = form_data[arrayofday_month_year[2]]
- year = form_data[arrayofday_month_year[3]]
-
- message = []
- if day.empty?
- message << arrayofday_month_year[1].capitalize.gsub(/_/, " ")
- end
- if month.empty?
- message << arrayofday_month_year[2].capitalize.gsub(/_/, " ")
- end
- if year.empty?
- message << arrayofday_month_year[3].capitalize.gsub(/_/, " ")
- end
-
- if message.length > 0 and message.length < 3
- fields_in_error_message = message.join(" and ")
- @@errors[arrayofday_month_year[0]] = "#{fields_in_error_message} not entered. Please enter complete date."
- end
- end
- end
-
- def self.doesFieldHaveValue(field_value)
- field_value && !field_value.strip.empty?
- end
-
- def self.validate_date_in_valid_range(date_field_name, day, month, year, form_data)
- if !form_data[day].empty? && !form_data[month].empty? && !form_data[year].empty?
- date_to_validate = form_data[day] + "-" + form_data[month] + "-" + form_data[year]
- begin
- Date.parse(date_to_validate)
- rescue
- @@errors[date_field_name] = "#{date_to_validate} is invalid. Please enter existing date."
- return nil
- end
- end
- end
-
- def self.validate_date_is_equal_or_greater_than_today(date_field_name, date, message)
- if date && date < Date.today
- @@errors[date_field_name] = message
- end
- end
-
- def self.validate_not_before_date_is_equal_or_greater_than_need_by(not_before, need_by, message)
- if not_before && need_by && not_before < need_by
- @@errors["Not before"] = message
- end
- end
-
- def self.validate_organisation_or_other_is_entered(form_data)
- other_organisation_is_required = form_data[:organisation].empty? || form_data[:organisation] == "other_organisation"
-
- if other_organisation_is_required &&
- (form_data[:other_organisation] && form_data[:other_organisation].strip.empty?)
- @@errors["organisation"] = "Organisation information is required for a valid request."
- end
-
- if not other_organisation_is_required
- form_data[:other_organisation] = ""
- end
- end
-end
View
81 lib/zendesk_ticket.rb
@@ -5,15 +5,6 @@
class ZendeskTicket
extend Forwardable
- @@in_comments = {"campaign" => [:other_organisation, :campaign_name, :erg_number, :company, :description, :url, :additional]
- }
-
- @@in_subject = {"campaign" => "Campaign",
- }
-
- @@in_tag = {"campaign" => "campaign",
- }
-
def initialize(request, from_route)
@request = request
@from_route = from_route
@@ -39,36 +30,21 @@ def phone
end
def comment
- if respond_to?(:comment_snippets)
- applicable_snippets = comment_snippets.select(&:applies?)
- applicable_snippets.collect(&:to_s).join("\n\n")
- else
- # TODO: remove this when the refactor is complete
- format_comment(@from_route, @request)
- end
- end
-
- def subject
- @@in_subject[@from_route]
+ applicable_snippets = comment_snippets.select(&:applies?)
+ applicable_snippets.collect(&:to_s).join("\n\n")
end
def not_before_date
- # TODO sort this mess out
if has_value?(:time_constraint) and has_value?(:not_before_date, @request.time_constraint)
@request.time_constraint.not_before_date
- elsif has_value?(:not_before_day)
- @request.not_before_day + "/" + @request.not_before_month + "/" + @request.not_before_year
else
nil
end
end
def needed_by_date
- # TODO sort this mess out
if has_value?(:time_constraint) and has_value?(:needed_by_date, @request.time_constraint)
@request.time_constraint.needed_by_date
- elsif has_value?(:need_by_day)
- @request.need_by_day + "/" + @request.need_by_month + "/" + @request.need_by_year
else
nil
end
@@ -97,61 +73,8 @@ def has_value?(param, target = nil)
target.respond_to?(param) and not target.send(param).blank?
end
- def format_comment(from_route, request)
- case from_route
- when "publish-tool" then
- format_comment_for_tech_issues(from_route, request)
- else
- comment = @@in_comments[from_route].map do |comment_param|
- if request.send(comment_param) && !request.send(comment_param).empty?
- "[" + comment_param.to_s.capitalize.gsub(/_/, " ") + "]\n" + request.send(comment_param)
- end
- end
-
- if !comment.join().empty?
- comment.join("\n\n")
- else
- comment.join
- end
- end
- end
-
- def format_comment_for_tech_issues(from_route, request)
- all_comments = @@in_comments[from_route].map do |comment_param|
- comment = ""
- if request.send(comment_param) && !request.send(comment_param).empty?
- comment = "[" + comment_param.to_s.capitalize.gsub(/_/, " ") + "]\n"
- if :url == comment_param
- comment += build_full_url_path(request.url)
- else
- comment += request.send(comment_param)
- end
- end
- comment
- end
-
- if !all_comments.join.empty?
- all_comments.join("\n\n")
- else
- all_comments.join
- end
- end
-
def remove_space_from_phone_number(number)
number.gsub(/\s+/, "")
end
-
- def build_full_url_path(partial_path)
- if partial_path && !partial_path.empty?
- "http://gov.uk/"+ partial_path
- else
- partial_path
- end
- end
-
- def doesFieldHaveValue(field_value)
- field_value && !field_value.strip.empty?
- end
-
end
View
40 test/functional/support_controller_test.rb
@@ -2,7 +2,6 @@
class SupportControllerTest < ActionController::TestCase
include ZendeskOrganisationListHelper
- include TestData
setup do
login_as_stub_user
@@ -16,43 +15,4 @@ class SupportControllerTest < ActionController::TestCase
assert_select "h1", /Welcome to GOV.UK Support/i
end
end
-
- context "GET campaign" do
- setup do
- stub_zendesk_organisation_list
- end
-
- should "render the form" do
- get :campaign
- assert_select "h1", /Campaign/i
- end
-
- should "use ZenDesk to populate the organisation dropdown" do
- get :campaign
- assert_select "select#organisation_list option", "Advocate General for Scotland"
- end
- end
-
- context "POST campaign" do
- setup do
- stub_zendesk_organisation_list
- end
-
- should "reject invalid requests" do
- params = valid_campaign_request_params.merge("organisation" => "")
- post :campaign, params
- assert_response 400
- assert_template "campaigns/campaign"
- assert_select ".help-block", /Organisation information is required/
- end
-
- should "submit it to ZenDesk" do
- params = valid_campaign_request_params
-
- post :campaign, params
-
- assert_equal ['campaign'], @zendesk_api.ticket.tags
- assert_redirected_to "/acknowledge"
- end
- end
end
View
8 test/unit/models/campaign_request_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class CampaignRequestTest < Test::Unit::TestCase
+ should validate_presence_of(:requester)
+ should validate_presence_of(:campaign)
+
+ should allow_value("a comment").for(:additional_comments)
+end
View
23 test/unit/models/campaign_test.rb
@@ -0,0 +1,23 @@
+require 'test_helper'
+
+class CampaignTest < Test::Unit::TestCase
+ def self.as_str(date)
+ date.strftime("%d-%m-%Y")
+ end
+
+ def as_str(date)
+ CampaignTest.as_str(date)
+ end
+
+ should validate_presence_of(:title)
+ should validate_presence_of(:erg_reference_number)
+ should validate_presence_of(:description)
+
+ should allow_value("some group or company").for(:affiliated_group_or_company)
+ should allow_value("http://www.google.com").for(:info_url)
+
+ should_not allow_value("xxx").for(:start_date)
+
+ should allow_value(as_str(Date.tomorrow)).for(:start_date)
+ should allow_value(as_str(Date.today)).for(:start_date)
+end
View
16 test/unit/zendesk/zendesk_ticket_test.rb
@@ -27,18 +27,6 @@ def new_ticket(attributes, type = nil)
assert_equal "123456", ticket.phone
end
- context "old design" do
- should "concatenate the needed_by_date correctly" do
- options = {need_by_day: "01", need_by_month: "02", need_by_year: "2012"}
- assert_equal "01/02/2012", new_ticket(options).needed_by_date
- end
-
- should "concatenate the not_before_date correctly" do
- options = {not_before_day: "01", not_before_month: "02", not_before_year: "2012"}
- assert_equal "01/02/2012", new_ticket(options).not_before_date
- end
- end
-
context "with time constraints" do
should "pass the need_by_date through" do
time_constraint = OpenStruct.new(needed_by_date: "03-02-2001")
@@ -51,10 +39,6 @@ def new_ticket(attributes, type = nil)
end
end
- should "set the subject according to request type" do
- assert_equal "Campaign", new_ticket({}, "campaign").subject
- end
-
should "remove spaces from the tel number" do
assert_equal "12345678", new_ticket(:phone => "1234 5678").phone
end

0 comments on commit fbf33a1

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