Module: GdsApi::TestHelpers::ContentStore
Instance Method Summary
collapse
alias_deprecated
#gone_content_item_for_base_path, #titleize_base_path
Instance Method Details
#content_item_for_base_path(base_path) ⇒ Object
86
87
88
|
# File 'lib/gds_api/test_helpers/content_store.rb', line 86
def content_item_for_base_path(base_path)
super.merge("base_path" => base_path)
end
|
#content_store_endpoint(draft = false) ⇒ Object
12
13
14
|
# File 'lib/gds_api/test_helpers/content_store.rb', line 12
def content_store_endpoint(draft = false)
draft ? Plek.current.find("draft-content-store") : Plek.current.find("content-store")
end
|
#stub_content_store_does_not_have_item(base_path, options = {}) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/gds_api/test_helpers/content_store.rb', line 39
def stub_content_store_does_not_have_item(base_path, options = {})
url = content_store_endpoint(options[:draft]) + "/content" + base_path
stub_request(:get, url).to_return(status: 404, headers: {})
url = content_store_endpoint(options[:draft]) + "/incoming-links" + base_path
stub_request(:get, url).to_return(status: 404, headers: {})
end
|
#stub_content_store_has_gone_item(base_path, body = gone_content_item_for_base_path(base_path), options = {}) ⇒ Object
Content store has gone item
Stubs a content item in the content store to respond with 410 HTTP Status Code and response body with ‘format’ set to ‘gone’.
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/gds_api/test_helpers/content_store.rb', line 71
def stub_content_store_has_gone_item(base_path, body = gone_content_item_for_base_path(base_path), options = {})
url = content_store_endpoint(options[:draft]) + "/content" + base_path
body = body.to_json unless body.is_a?(String)
stub_request(:get, url).to_return(
status: 410,
body: body,
headers: {},
)
end
|
#stub_content_store_has_incoming_links(base_path, links) ⇒ Object
90
91
92
93
94
95
|
# File 'lib/gds_api/test_helpers/content_store.rb', line 90
def stub_content_store_has_incoming_links(base_path, links)
url = content_store_endpoint + "/incoming-links" + base_path
body = links.to_json
stub_request(:get, url).to_return(body: body)
end
|
#stub_content_store_has_item(base_path, body = content_item_for_base_path(base_path), options = {}) ⇒ Object
Stubs a content item in the content store. The following options can be passed in:
:max_age will set the max-age of the Cache-Control header in the response. Defaults to 900
:private if true, the Cache-Control header will include the "private" directive. By default it
will include "public"
:draft will point to the draft content store if set to true
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/gds_api/test_helpers/content_store.rb', line 23
def stub_content_store_has_item(base_path, body = content_item_for_base_path(base_path), options = {})
max_age = options.fetch(:max_age, 900)
visibility = options[:private] ? "private" : "public"
url = content_store_endpoint(options[:draft]) + "/content" + base_path
body = body.to_json unless body.is_a?(String)
stub_request(:get, url).to_return(
status: 200,
body: body,
headers: {
cache_control: "#{visibility}, max-age=#{max_age}",
date: Time.now.httpdate,
},
)
end
|
#stub_content_store_isnt_available ⇒ Object
82
83
84
|
# File 'lib/gds_api/test_helpers/content_store.rb', line 82
def stub_content_store_isnt_available
stub_request(:any, /#{content_store_endpoint}\/.*/).to_return(status: 503)
end
|