slimmer 3.9.0 → 3.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,13 +12,13 @@ module Slimmer::Processors
12
12
  def filter(src, dest)
13
13
  custom_vars = []
14
14
  if @artefact
15
- custom_vars << set_custom_var(1, "Section", @artefact.primary_root_section["title"].downcase) if @artefact.primary_root_section
16
- custom_vars << set_custom_var(3, "NeedID", @artefact.need_id.downcase)
17
- custom_vars << set_custom_var(4, "Proposition", (@artefact.business_proposition ? 'business' : 'citizen')) unless @artefact.business_proposition.nil?
15
+ custom_vars << set_custom_var_downcase(1, "Section", @artefact.primary_root_section["title"]) if @artefact.primary_root_section
16
+ custom_vars << set_custom_var_downcase(3, "NeedID", @artefact.need_id)
17
+ custom_vars << set_custom_var_downcase(4, "Proposition", (@artefact.business_proposition ? 'business' : 'citizen')) unless @artefact.business_proposition.nil?
18
18
  custom_vars << set_custom_var(9, "Organisations", @artefact.organisations) unless @artefact.organisations.nil?
19
19
  end
20
- custom_vars << set_custom_var(2, "Format", @headers[Slimmer::Headers::FORMAT_HEADER].downcase)
21
- custom_vars << set_custom_var(5, "ResultCount", @headers[Slimmer::Headers::RESULT_COUNT_HEADER].downcase)
20
+ custom_vars << set_custom_var_downcase(2, "Format", @headers[Slimmer::Headers::FORMAT_HEADER])
21
+ custom_vars << set_custom_var_downcase(5, "ResultCount", @headers[Slimmer::Headers::RESULT_COUNT_HEADER])
22
22
 
23
23
  if dest.at_css("#ga-params")
24
24
  dest.at_css("#ga-params").content += custom_vars.compact.join("\n")
@@ -26,8 +26,12 @@ module Slimmer::Processors
26
26
  end
27
27
 
28
28
  private
29
- def set_custom_var(slot, name, value)
29
+ def set_custom_var_downcase(slot, name, value)
30
30
  return nil unless value
31
+ set_custom_var(slot, name, value.downcase)
32
+ end
33
+
34
+ def set_custom_var(slot, name, value)
31
35
  response = "_gaq.push(#{JSON.dump([ "_setCustomVar", slot, name, value, PAGE_LEVEL_EVENT])});\n"
32
36
  response + "GOVUK.Analytics.#{name} = \"#{value}\";"
33
37
  end
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = '3.9.0'
2
+ VERSION = '3.9.1'
3
3
  end
@@ -2,6 +2,7 @@ require_relative "../test_helper"
2
2
  require "v8"
3
3
 
4
4
  module GoogleAnalyticsTest
5
+ PAGE_LEVEL_EVENT = 3
5
6
 
6
7
  GENERIC_DOCUMENT = <<-END
7
8
  <html>
@@ -49,7 +50,6 @@ module GoogleAnalyticsTest
49
50
 
50
51
  class WithHeadersTest < SlimmerIntegrationTest
51
52
  include JavaScriptAssertions
52
- PAGE_LEVEL_EVENT = 3
53
53
 
54
54
  def setup
55
55
  super
@@ -97,7 +97,7 @@ module GoogleAnalyticsTest
97
97
  assert_custom_var 4, "Proposition", "business", PAGE_LEVEL_EVENT
98
98
  end
99
99
 
100
- def test_should_pass_proposition_to_GA
100
+ def test_should_pass_organisation_to_GA
101
101
  assert_custom_var 9, "Organisations", "<P1><D422>", PAGE_LEVEL_EVENT
102
102
  end
103
103
 
@@ -143,4 +143,29 @@ module GoogleAnalyticsTest
143
143
  refute_custom_var "ResultCount"
144
144
  end
145
145
  end
146
+
147
+ class WithNilHeaderTest < SlimmerIntegrationTest
148
+ include JavaScriptAssertions
149
+
150
+ def setup
151
+ super
152
+
153
+ artefact = artefact_for_slug_in_a_subsection("something", "rhubarb/in-puddings")
154
+ artefact["details"].merge!(
155
+ "need_id" => "42",
156
+ "business_proposition" => true,
157
+ "organisations" => "<P1><D422>"
158
+ )
159
+ headers = {
160
+ Slimmer::Headers::RESULT_COUNT_HEADER => "3",
161
+ Slimmer::Headers::ARTEFACT_HEADER => artefact.to_json
162
+ }
163
+
164
+ given_response 200, GENERIC_DOCUMENT, headers
165
+ end
166
+
167
+ def test_should_pass_organisation_to_GA_without_crashing
168
+ assert_custom_var 9, "Organisations", "<P1><D422>", PAGE_LEVEL_EVENT
169
+ end
170
+ end
146
171
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: slimmer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.9.0
5
+ version: 3.9.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ben Griffiths
@@ -246,7 +246,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
246
246
  requirements:
247
247
  - - ">="
248
248
  - !ruby/object:Gem::Version
249
- hash: -2824424653822310108
249
+ hash: -3564071849089416318
250
250
  segments:
251
251
  - 0
252
252
  version: "0"
@@ -255,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
255
  requirements:
256
256
  - - ">="
257
257
  - !ruby/object:Gem::Version
258
- hash: -2824424653822310108
258
+ hash: -3564071849089416318
259
259
  segments:
260
260
  - 0
261
261
  version: "0"