Class: GovukAbTesting::AcceptanceTests::ActiveSupport

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_ab_testing/acceptance_tests/active_support.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope) ⇒ ActiveSupport

Returns a new instance of ActiveSupport.



6
7
8
9
10
11
12
13
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 6

def initialize(scope)
  @request = scope.instance_variable_get(:@request)
  if @request.nil?
    raise "Couldn't find '@request' defined, are you using ActiveSupport test cases?"
  end
  @scope = scope
  @request_headers = {}
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



4
5
6
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 4

def request
  @request
end

#request_headersObject (readonly)

Returns the value of attribute request_headers.



4
5
6
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 4

def request_headers
  @request_headers
end

#scopeObject (readonly)

Returns the value of attribute scope.



4
5
6
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 4

def scope
  @scope
end

Instance Method Details

#analytics_meta_tagsObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 28

def analytics_meta_tags
  tags = scope.css_select(ANALYTICS_META_TAG_SELECTOR)

  tags.map do |tag|
    MetaTag.new(
      content: tag.attributes['content'].value,
      dimension: tag.attributes['data-analytics-dimension'].value
    )
  end
end

#analytics_meta_tags_for_test(ab_test_name) ⇒ Object



24
25
26
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 24

def analytics_meta_tags_for_test(ab_test_name)
  analytics_meta_tags.select { |tag| tag.for_ab_test?(ab_test_name) }
end

#set_header(name, value) ⇒ Object



15
16
17
18
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 15

def set_header(name, value)
  request.headers[name] = value
  @request_headers[name] = value
end

#vary_header(response) ⇒ Object



20
21
22
# File 'lib/govuk_ab_testing/acceptance_tests/active_support.rb', line 20

def vary_header(response)
  response.headers['Vary']
end