Module: GdsApi::TestHelpers::ContentStore
- Includes:
- CommonResponses
- Defined in:
- lib/gds_api/test_helpers/content_store.rb
Constant Summary
collapse
- CONTENT_STORE_ENDPOINT =
Plek.current.find('content-store')
Instance Method Summary
collapse
#acronymize_slug, #plural_response_base, #response_base, #titleize_slug
Instance Method Details
#assert_content_store_put_item(base_path, attributes = {}) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/gds_api/test_helpers/content_store.rb', line 47
def assert_content_store_put_item(base_path, attributes = {})
url = CONTENT_STORE_ENDPOINT + "/content" + base_path
if attributes.empty?
assert_requested(:put, url)
else
assert_requested(:put, url) do |req|
data = JSON.parse(req.body)
attributes.to_a.all? do |key, value|
data[key.to_s] == value
end
end
end
end
|
#content_store_does_not_have_item(base_path) ⇒ Object
18
19
20
21
|
# File 'lib/gds_api/test_helpers/content_store.rb', line 18
def content_store_does_not_have_item(base_path)
url = CONTENT_STORE_ENDPOINT + "/content" + base_path
stub_request(:get, url).to_return(status: 404, headers: {})
end
|
#content_store_has_item(base_path, body = item_for_base_path(base_path)) ⇒ Object
12
13
14
15
16
|
# File 'lib/gds_api/test_helpers/content_store.rb', line 12
def content_store_has_item(base_path, body = item_for_base_path(base_path))
url = CONTENT_STORE_ENDPOINT + "/content" + base_path
body = body.to_json unless body.is_a?(String)
stub_request(:get, url).to_return(status: 200, body: body, headers: {})
end
|
#item_for_base_path(base_path) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/gds_api/test_helpers/content_store.rb', line 33
def item_for_base_path(base_path)
{
"title" => titleize_slug(base_path),
"description" => "Description for #{base_path}",
"format" => "guide",
"need_ids" => ["100001"],
"public_updated_at" => "2014-05-06T12:01:00+00:00",
"base_path" => base_path,
"details" => {
"body" => "Some content for #{base_path}",
}
}
end
|
#stub_content_store_put_item(base_path, body = item_for_base_path(base_path)) ⇒ Object
23
24
25
26
27
|
# File 'lib/gds_api/test_helpers/content_store.rb', line 23
def stub_content_store_put_item(base_path, body = item_for_base_path(base_path))
url = CONTENT_STORE_ENDPOINT + "/content" + base_path
body = body.to_json unless body.is_a?(String)
stub_request(:put, url).with(body: body).to_return(status: 201, body: body, headers: {})
end
|
#stub_default_content_store_put ⇒ Object
29
30
31
|
# File 'lib/gds_api/test_helpers/content_store.rb', line 29
def stub_default_content_store_put()
stub_request(:put, %r{\A#{CONTENT_STORE_ENDPOINT}/content})
end
|