Module: GdsApi::TestHelpers::FactCave

Includes:
CommonResponses
Defined in:
lib/gds_api/test_helpers/fact_cave.rb

Constant Summary collapse

FACT_CAVE_ENDPOINT =
Plek.current.find('fact-cave')

Instance Method Summary collapse

Methods included from CommonResponses

#plural_response_base, #response_base, #titleize_slug

Instance Method Details

#fact_cave_does_not_have_a_fact(slug) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/gds_api/test_helpers/fact_cave.rb', line 20

def fact_cave_does_not_have_a_fact(slug)
  response = {
    "_response_info" => { "status" => "not found" }
  }

  stub_request(:get, "#{FACT_CAVE_ENDPOINT}/facts/#{slug}")
    .to_return(:body => response.to_json, :status => 404)
  stub_request(:get, "#{FACT_CAVE_ENDPOINT}/facts/#{slug}.json")
    .to_return(:body => response.to_json, :status => 404)
end

#fact_cave_has_a_fact(slug, value, extra_attrs = {}) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/gds_api/test_helpers/fact_cave.rb', line 11

def fact_cave_has_a_fact(slug, value, extra_attrs={})
  response = fact_for_slug(slug, value).merge(extra_attrs)

  stub_request(:get, "#{FACT_CAVE_ENDPOINT}/facts/#{slug}")
    .to_return(:body => response.to_json, :status => 200)
  stub_request(:get, "#{FACT_CAVE_ENDPOINT}/facts/#{slug}.json")
    .to_return(:body => response.to_json, :status => 200)
end

#fact_for_slug(slug, value = "Sample Value") ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gds_api/test_helpers/fact_cave.rb', line 31

def fact_for_slug(slug, value = "Sample Value")
  singular_response_base.merge({
    "id" => "#{FACT_CAVE_ENDPOINT}/facts/#{slug}",
    "details" => {
      "description" => "",
      "value" => value,
    },
    "name" => titleize_slug(slug),
    "updated_at" => Time.now.utc.xmlschema,
  })
end