Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding cucumber test for the general request form

  • Loading branch information...
commit ad40e776aebd39056543ae0e07ef65ede54c7c0c 1 parent 0eedf1f
@benilovj benilovj authored
Showing with 433 additions and 95 deletions.
  1. +3 −0  Gemfile
  2. +46 −0 Gemfile.lock
  3. +8 −0 config/cucumber.yml
  4. +26 −0 features/general_requests.feature
  5. +19 −0 features/step_definitions/general_request_steps.rb
  6. +6 −0 features/step_definitions/user_steps.rb
  7. +18 −0 features/step_definitions/zendesk_steps.rb
  8. +9 −0 features/support/capybara.rb
  9. +59 −0 features/support/env.rb
  10. +9 −0 features/support/gds_sso_helper.rb
  11. +4 −0 features/support/hooks.rb
  12. +3 −0  features/support/webmock.rb
  13. +5 −0 features/support/zendesk_helper.rb
  14. +1 −1  lib/comment_snippet.rb
  15. +65 −0 lib/tasks/cucumber.rake
  16. +12 −5 lib/zendesk_request.rb
  17. +10 −0 script/cucumber
  18. 0  test/fixtures/.gitkeep
  19. +3 −3 test/functional/content_change_requests_controller_test.rb
  20. +3 −3 test/functional/create_new_user_requests_controller_test.rb
  21. +3 −3 test/functional/general_requests_controller_test.rb
  22. +3 −3 test/functional/remove_user_requests_controller_test.rb
  23. +2 −2 test/functional/support_controller_test.rb
  24. +3 −72 test/test_helper.rb
  25. +4 −3 test/unit/comment_snippet_test.rb
  26. +75 −0 test/zendesk_api_stubs.rb
  27. +34 −0 test/zendesk_organisation_list_helper.rb
View
3  Gemfile
@@ -22,6 +22,9 @@ group :test do
gem "mocha", "0.12.6", require: false
gem "shoulda", "~> 3.3.2"
gem "webmock", "1.8.11"
+ gem 'capybara', '1.1.2'
+ gem 'poltergeist', '0.7.0'
+ gem 'cucumber-rails', '1.3.0', :require => false
end
gem 'unicorn', '4.3.1'
View
46 Gemfile.lock
@@ -37,6 +37,15 @@ GEM
mime-types
xml-simple
builder (3.0.4)
+ capybara (1.1.2)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ childprocess (0.3.5)
+ ffi (~> 1.0, >= 1.0.6)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
@@ -45,7 +54,18 @@ GEM
execjs
coffee-script-source (1.3.3)
crack (0.3.1)
+ cucumber (1.2.1)
+ builder (>= 2.1.2)
+ diff-lcs (>= 1.1.3)
+ gherkin (~> 2.11.0)
+ json (>= 1.4.6)
+ cucumber-rails (1.3.0)
+ capybara (>= 1.1.2)
+ cucumber (>= 1.1.8)
+ nokogiri (>= 1.5.0)
+ diff-lcs (1.1.3)
erubis (2.7.0)
+ eventmachine (1.0.0)
exception_notification (2.4.1)
execjs (1.4.0)
multi_json (~> 1.0)
@@ -53,6 +73,9 @@ GEM
multipart-post (~> 1.1)
faraday_middleware (0.8.8)
faraday (>= 0.7.4, < 0.9)
+ faye-websocket (0.4.6)
+ eventmachine (>= 0.12.0)
+ ffi (1.1.5)
formtastic (2.2.1)
actionpack (>= 3.0)
formtastic-bootstrap (2.0.0)
@@ -63,8 +86,11 @@ GEM
rack-accept (~> 0.4.4)
rails (>= 3.0.0)
warden (~> 1.2)
+ gherkin (2.11.2)
+ json (>= 1.4.6)
hashie (1.2.0)
hike (1.2.1)
+ http_parser.rb (0.5.3)
httpauth (0.2.0)
i18n (0.6.1)
inflection (1.0.0)
@@ -77,6 +103,8 @@ GEM
multi_json (>= 1.0)
kgio (2.7.4)
libv8 (3.3.10.4)
+ libwebsocket (0.1.5)
+ addressable
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -87,6 +115,7 @@ GEM
metaclass (~> 0.0.1)
multi_json (1.3.6)
multipart-post (1.1.5)
+ nokogiri (1.5.5)
oauth2 (0.8.0)
faraday (~> 0.8)
httpauth (~> 0.1)
@@ -103,6 +132,12 @@ GEM
omniauth (~> 1.0)
plek (0.5.0)
builder
+ poltergeist (0.7.0)
+ capybara (~> 1.1)
+ childprocess (~> 0.3)
+ faye-websocket (~> 0.4, >= 0.4.4)
+ http_parser.rb (~> 0.5.3)
+ multi_json (~> 1.0)
polyglot (0.3.3)
rack (1.4.1)
rack-accept (0.4.5)
@@ -132,11 +167,17 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
+ rubyzip (0.9.9)
sass (3.2.1)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
+ selenium-webdriver (2.25.0)
+ childprocess (>= 0.2.5)
+ libwebsocket (~> 0.1.3)
+ multi_json (~> 1.0)
+ rubyzip
shoulda (3.3.2)
shoulda-context (~> 1.0.1)
shoulda-matchers (~> 1.4.1)
@@ -168,6 +209,8 @@ GEM
addressable (>= 2.2.7)
crack (>= 0.1.7)
xml-simple (1.1.1)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
zendesk_api (0.1.2)
faraday (>= 0.8.0)
faraday_middleware (>= 0.8.7)
@@ -182,13 +225,16 @@ PLATFORMS
DEPENDENCIES
aws-ses
+ capybara (= 1.1.2)
coffee-rails (~> 3.2.1)
+ cucumber-rails (= 1.3.0)
exception_notification (~> 2.4.1)
formtastic-bootstrap (= 2.0.0)
gds-sso (= 2.1.0)
jquery-rails
mocha (= 0.12.6)
plek (= 0.5.0)
+ poltergeist (= 0.7.0)
rails (= 3.2.8)
sass-rails (~> 3.2.3)
shoulda (~> 3.3.2)
View
8 config/cucumber.yml
@@ -0,0 +1,8 @@
+<%
+rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
+rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
+std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
+%>
+default: <%= std_opts %> features
+wip: --tags @wip:3 --wip features
+rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
View
26 features/general_requests.feature
@@ -0,0 +1,26 @@
+Feature: General requests
+ In order to provide GDS with feedback
+ As a government employee
+ I want a means to contact GDS in the cases when my request does not covered by the other forms
+
+ Background:
+ * the following user has SSO access:
+ | Name | Email | Job title | Organisation |
+ | John Smith | john.smith@email.com | Developer | Cabinet Office |
+
+ Scenario: successful request
+ When the user submits the following general request:
+ | Details | URL |
+ | The site is down | http://www.gov.uk |
+ Then the following ticket is raised in ZenDesk:
+ | Subject | Requester email | Requester name | Job title | Organisation |
+ | Govt Agency General Issue | john.smith@email.com | John Smith | Developer | cabinet_office |
+ And the ticket is tagged with "govt_agency_general"
+ And the comment on the ticket is:
+ """
+ [Url]
+ http://www.gov.uk
+
+ [Additional]
+ The site is down
+ """
View
19 features/step_definitions/general_request_steps.rb
@@ -0,0 +1,19 @@
+When /^the user submits the following general request:$/ do |request_details_table|
+ request_details = request_details_table.hashes.first
+
+ visit '/'
+
+ click_on "General"
+
+ assert page.has_content?("Report a problem")
+
+ fill_in "Name", :with => @user_details["Name"]
+ fill_in "Email", :with => @user_details["Email"]
+ fill_in "Job title", :with => @user_details["Job title"]
+ select @user_details["Organisation"], :from => 'Organisation'
+
+ fill_in "Details", :with => request_details['Details']
+ fill_in "URL (if applicable)", :with => request_details['URL']
+
+ click_on "Submit"
+end
View
6 features/step_definitions/user_steps.rb
@@ -0,0 +1,6 @@
+Given /^the following user has SSO access:$/ do |user_details|
+ user = stub_everything('user', :name => "user", :has_permission? => true)
+ @user_details = user_details.hashes.first
+
+ login_as user
+end
View
18 features/step_definitions/zendesk_steps.rb
@@ -0,0 +1,18 @@
+Then /^the following ticket is raised in ZenDesk:$/ do |ticket_properties_table|
+ expected_ticket_props = ticket_properties_table.hashes.first
+ @raised_ticket = @zendesk_api.ticket
+
+ assert_equal expected_ticket_props["Subject"], @raised_ticket.subject
+ assert_equal expected_ticket_props["Requester email"], @raised_ticket.email
+ assert_equal expected_ticket_props["Requester name"], @raised_ticket.name
+ assert_equal expected_ticket_props["Job title"], @raised_ticket.job
+ assert_equal expected_ticket_props["Organisation"], @raised_ticket.organisation
+end
+
+Then /^the ticket is tagged with "(.*?)"$/ do |expected_tags|
+ assert_equal expected_tags, @raised_ticket.tags.join(" ")
+end
+
+Then /^the comment on the ticket is:$/ do |expected_comment_string|
+ assert_equal expected_comment_string, @raised_ticket.comment
+end
View
9 features/support/capybara.rb
@@ -0,0 +1,9 @@
+require 'capybara/poltergeist'
+
+Capybara.register_driver :rack_test do |app|
+ Capybara::RackTest::Driver.new(app, :browser => :chrome)
+end
+Capybara.register_driver :poltergeist do |app|
+ Capybara::Poltergeist::Driver.new(app, timeout: 5, debug: true)
+end
+Capybara.javascript_driver = :poltergeist
View
59 features/support/env.rb
@@ -0,0 +1,59 @@
+# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
+# It is recommended to regenerate this file in the future when you upgrade to a
+# newer version of cucumber-rails. Consider adding your own code to a new file
+# instead of editing this one. Cucumber will automatically load all features/**/*.rb
+# files.
+
+require 'cucumber/rails'
+
+# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
+# order to ease the transition to Capybara we set the default here. If you'd
+# prefer to use XPath just remove this line and adjust any selectors in your
+# steps to use the XPath syntax.
+Capybara.default_selector = :css
+
+# By default, any exception happening in your Rails application will bubble up
+# to Cucumber so that your scenario will fail. This is a different from how
+# your application behaves in the production environment, where an error page will
+# be rendered instead.
+#
+# Sometimes we want to override this default behaviour and allow Rails to rescue
+# exceptions and display an error page (just like when the app is running in production).
+# Typical scenarios where you want to do this is when you test your error pages.
+# There are two ways to allow Rails to rescue exceptions:
+#
+# 1) Tag your scenario (or feature) with @allow-rescue
+#
+# 2) Set the value below to true. Beware that doing this globally is not
+# recommended as it will mask a lot of errors for you!
+#
+ActionController::Base.allow_rescue = false
+
+# Remove/comment out the lines below if your app doesn't have a database.
+# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
+# begin
+# DatabaseCleaner.strategy = :transaction
+# rescue NameError
+# raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
+# end
+
+# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
+# See the DatabaseCleaner documentation for details. Example:
+#
+# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
+# # { :except => [:widgets] } may not do what you expect here
+# # as tCucumber::Rails::Database.javascript_strategy overrides
+# # this setting.
+# DatabaseCleaner.strategy = :truncation
+# end
+#
+# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
+# DatabaseCleaner.strategy = :transaction
+# end
+#
+
+# Possible values are :truncation and :transaction
+# The :transaction strategy is faster, but might give you threading problems.
+# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
+Cucumber::Rails::Database.javascript_strategy = :truncation
+
View
9 features/support/gds_sso_helper.rb
@@ -0,0 +1,9 @@
+require "warden/test/helpers"
+
+module GdsSsoHelper
+ def login_as(user)
+ GDS::SSO.test_user = user
+ end
+end
+
+World(GdsSsoHelper)
View
4 features/support/hooks.rb
@@ -0,0 +1,4 @@
+Before do
+ stub_zendesk_organisation_list
+ stub_zendesk_ticket_submission
+end
View
3  features/support/webmock.rb
@@ -0,0 +1,3 @@
+require 'webmock/cucumber'
+
+WebMock.disable_net_connect!(:allow_localhost => true)
View
5 features/support/zendesk_helper.rb
@@ -0,0 +1,5 @@
+require_relative '../../test/zendesk_organisation_list_helper'
+require_relative '../../test/zendesk_api_stubs'
+
+World(ZendeskOrganisationListHelper)
+World(ZendeskApiStubsHelper)
View
2  lib/comment_snippet.rb
@@ -11,7 +11,7 @@ def to_s
end
def applies?
- @data_provider.send("#{@field_name}") && !@data_provider.send("#{@field_name}").nil?
+ @data_provider.respond_to?(@field_name) && !field_value.nil? && !field_value.empty?
end
def field_value
View
65 lib/tasks/cucumber.rake
@@ -0,0 +1,65 @@
+# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
+# It is recommended to regenerate this file in the future when you upgrade to a
+# newer version of cucumber-rails. Consider adding your own code to a new file
+# instead of editing this one. Cucumber will automatically load all features/**/*.rb
+# files.
+
+
+unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
+
+vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
+$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
+
+begin
+ require 'cucumber/rake/task'
+
+ namespace :cucumber do
+ Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
+ t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
+ t.fork = true # You may get faster startup if you set this to false
+ t.profile = 'default'
+ end
+
+ Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
+ t.binary = vendored_cucumber_bin
+ t.fork = true # You may get faster startup if you set this to false
+ t.profile = 'wip'
+ end
+
+ Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
+ t.binary = vendored_cucumber_bin
+ t.fork = true # You may get faster startup if you set this to false
+ t.profile = 'rerun'
+ end
+
+ desc 'Run all features'
+ task :all => [:ok, :wip]
+
+ task :statsetup do
+ require 'rails/code_statistics'
+ ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
+ ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
+ end
+ end
+ desc 'Alias for cucumber:ok'
+ task :cucumber => 'cucumber:ok'
+
+ task :default => :cucumber
+
+ task :features => :cucumber do
+ STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
+ end
+
+ # In case we don't have ActiveRecord, append a no-op task that we can depend upon.
+ task 'db:test:prepare' do
+ end
+
+ task :stats => 'cucumber:statsetup'
+rescue LoadError
+ desc 'cucumber rake task not available (cucumber not installed)'
+ task :cucumber do
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
+ end
+end
+
+end
View
17 lib/zendesk_request.rb
@@ -2,6 +2,13 @@
require 'ostruct'
class ZendeskRequest
+ def self.field_ids
+ { organisation: "21494928",
+ job: "21487987",
+ phone: "21471291",
+ need_by_date: "21485833",
+ not_before_date: "21502036" }
+ end
def self.get_organisations(client)
organisations_hash = {}
@@ -19,11 +26,11 @@ def self.raise_ticket(client, ticket_to_raise)
:description => "Created via Govt API",
:priority => "normal",
:requester => {"locale_id" => 1, "name" => ticket_to_raise.name, "email" => ticket_to_raise.email},
- :fields => [{"id" => "21494928", "value" => ticket_to_raise.organisation},
- {"id" => "21487987", "value" => ticket_to_raise.job},
- {"id" => "21471291", "value" => ticket_to_raise.phone},
- {"id" => "21485833", "value" => ticket_to_raise.need_by_date},
- {"id" => "21502036", "value" => ticket_to_raise.not_before_date}],
+ :fields => [{"id" => ZendeskRequest.field_ids[:organisation], "value" => ticket_to_raise.organisation},
+ {"id" => ZendeskRequest.field_ids[:job], "value" => ticket_to_raise.job},
+ {"id" => ZendeskRequest.field_ids[:phone], "value" => ticket_to_raise.phone},
+ {"id" => ZendeskRequest.field_ids[:need_by_date], "value" => ticket_to_raise.need_by_date},
+ {"id" => ZendeskRequest.field_ids[:not_before_date], "value" => ticket_to_raise.not_before_date}],
:tags => ticket_to_raise.tags,
:comment => {:value => ticket_to_raise.comment})
end
View
10 script/cucumber
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+
+vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
+if vendored_cucumber_bin
+ load File.expand_path(vendored_cucumber_bin)
+else
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
+ require 'cucumber'
+ load Cucumber::BINARY
+end
View
0  test/fixtures/.gitkeep
No changes.
View
6 test/functional/content_change_requests_controller_test.rb
@@ -1,7 +1,7 @@
require "test_helper"
class ContentChangeRequestsControllerTest < ActionController::TestCase
- include ZenDeskOrganisationListHelper
+ include ZendeskOrganisationListHelper
include TestData
setup do
@@ -42,7 +42,7 @@ class ContentChangeRequestsControllerTest < ActionController::TestCase
params = valid_content_change_request_params
post :create, params
- assert_equal ['content_amend'], @zendesk_api.ticket.options[:tags]
+ assert_equal ['content_amend'], @zendesk_api.ticket.tags
assert_redirected_to "/acknowledge"
end
@@ -53,7 +53,7 @@ class ContentChangeRequestsControllerTest < ActionController::TestCase
post :create, params
- assert_includes @zendesk_api.ticket.options[:tags], 'inside_government'
+ assert_includes @zendesk_api.ticket.tags, 'inside_government'
assert_redirected_to "/acknowledge"
end
View
6 test/functional/create_new_user_requests_controller_test.rb
@@ -1,7 +1,7 @@
require "test_helper"
class CreateNewUserRequestsControllerTest < ActionController::TestCase
- include ZenDeskOrganisationListHelper
+ include ZendeskOrganisationListHelper
include TestData
setup do
@@ -40,7 +40,7 @@ class CreateNewUserRequestsControllerTest < ActionController::TestCase
post :create, params
- assert_equal ['new_user'], @zendesk_api.ticket.options[:tags]
+ assert_equal ['new_user'], @zendesk_api.ticket.tags
assert_redirected_to "/acknowledge"
end
@@ -50,7 +50,7 @@ class CreateNewUserRequestsControllerTest < ActionController::TestCase
post :create, params
- assert_includes @zendesk_api.ticket.options[:tags], 'inside_government'
+ assert_includes @zendesk_api.ticket.tags, 'inside_government'
assert_redirected_to "/acknowledge"
end
View
6 test/functional/general_requests_controller_test.rb
@@ -1,7 +1,7 @@
require 'test_helper'
class GeneralRequestsControllerTest < ActionController::TestCase
- include ZenDeskOrganisationListHelper
+ include ZendeskOrganisationListHelper
include TestData
setup do
@@ -46,7 +46,7 @@ class GeneralRequestsControllerTest < ActionController::TestCase
post :create, params
- assert_equal ['govt_agency_general'], @zendesk_api.ticket.options[:tags]
+ assert_equal ['govt_agency_general'], @zendesk_api.ticket.tags
assert_redirected_to "/acknowledge"
end
@@ -56,7 +56,7 @@ class GeneralRequestsControllerTest < ActionController::TestCase
post :create, params
- assert_includes @zendesk_api.ticket.options[:comment][:value], "Mozilla/5.0"
+ assert_includes @zendesk_api.ticket.comment, "Mozilla/5.0"
end
end
end
View
6 test/functional/remove_user_requests_controller_test.rb
@@ -1,7 +1,7 @@
require 'test_helper'
class RemoveUserRequestsControllerTest < ActionController::TestCase
- include ZenDeskOrganisationListHelper
+ include ZendeskOrganisationListHelper
include TestData
setup do
@@ -40,7 +40,7 @@ class RemoveUserRequestsControllerTest < ActionController::TestCase
post :create, params
- assert_equal ['remove_user'], @zendesk_api.ticket.options[:tags]
+ assert_equal ['remove_user'], @zendesk_api.ticket.tags
assert_redirected_to "/acknowledge"
end
@@ -50,7 +50,7 @@ class RemoveUserRequestsControllerTest < ActionController::TestCase
post :create, params
- assert_includes @zendesk_api.ticket.options[:tags], 'inside_government'
+ assert_includes @zendesk_api.ticket.tags, 'inside_government'
assert_redirected_to "/acknowledge"
end
View
4 test/functional/support_controller_test.rb
@@ -1,7 +1,7 @@
require "test_helper"
class SupportControllerTest < ActionController::TestCase
- include ZenDeskOrganisationListHelper
+ include ZendeskOrganisationListHelper
include TestData
setup do
@@ -51,7 +51,7 @@ class SupportControllerTest < ActionController::TestCase
post :campaign, params
- assert_equal ['campaign'], @zendesk_api.ticket.options[:tags]
+ assert_equal ['campaign'], @zendesk_api.ticket.tags
assert_redirected_to "/acknowledge"
end
end
View
75 test/test_helper.rb
@@ -8,6 +8,9 @@
require 'ostruct'
require_relative 'test_data'
+require 'zendesk_organisation_list_helper'
+require 'zendesk_api_stubs'
+
class ActiveSupport::TestCase
def setup
super
@@ -21,75 +24,3 @@ def login_as_stub_user
end
end
-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
-
-class ZenDeskAPITicketDouble
- attr_reader :options
-
- def create(options)
- @options = options
- end
-end
-
-class ZenDeskAPIClientDouble
- attr_reader :ticket
-
- 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
7 test/unit/comment_snippet_test.rb
@@ -14,10 +14,11 @@ class CommentSnippetTest < Test::Unit::TestCase
assert_includes CommentSnippet.new(data_provider, :my_field_name).to_s, "abc"
end
- context "when the field isn't provided" do
+ context "when the field isn't provided or is empty" do
should "not apply" do
- data_provider = OpenStruct.new(:my_field_name => nil, :my_field_name? => false)
- assert !CommentSnippet.new(data_provider, :my_field_name).applies?
+ 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?
end
end
end
View
75 test/zendesk_api_stubs.rb
@@ -0,0 +1,75 @@
+require 'zendesk_request'
+
+module ZendeskApiStubsHelper
+ def stub_zendesk_ticket_submission
+ @zendesk_api = ZenDeskAPIClientDouble.new
+ ZendeskClient.stubs(:get_client).returns(@zendesk_api)
+ end
+end
+
+class ZenDeskAPITicketDouble
+ attr_reader :options
+
+ def create(options)
+ @options = options
+ end
+
+ [:subject, :tags, :description].each do |property|
+ define_method(property) do
+ @options[property]
+ end
+ end
+
+ ZendeskRequest.field_ids.each do |field_name, field_id|
+ define_method(field_name) do
+ value_of_field_with_id(field_id)
+ end
+ end
+
+ def name
+ @options[:requester]["name"]
+ end
+
+ def email
+ @options[:requester]["email"]
+ end
+
+ def comment
+ @options[:comment][:value]
+ end
+
+ protected
+ def value_of_field_with_id(field_id)
+ correct_field = @options[:fields].detect {|field| field["id"] == field_id}
+ correct_field["value"]
+ end
+end
+
+class ZenDeskAPIClientDouble
+ attr_reader :ticket
+
+ 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
@@ -0,0 +1,34 @@
+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.