Class: GdsApi::TestHelpers::ContentApi::ArtefactStub

Inherits:
Object
  • Object
show all
Includes:
GdsApi::TestHelpers::ContentApi, WebMock::API
Defined in:
lib/gds_api/test_helpers/content_api/artefact_stub.rb

Constant Summary

Constants included from GdsApi::TestHelpers::ContentApi

CONTENT_API_ENDPOINT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GdsApi::TestHelpers::ContentApi

#artefact_for_slug, #artefact_for_slug_in_a_section, #artefact_for_slug_in_a_subsection, #artefact_for_slug_with_related_artefacts, #content_api_does_not_have_an_artefact, #content_api_has_an_archived_artefact, #content_api_has_an_artefact, #content_api_has_an_artefact_with_snac_code, #content_api_has_artefacts_in_a_section, #content_api_has_business_support_scheme, #content_api_has_licence, #content_api_has_root_sections, #content_api_has_section, #content_api_has_subsections, #content_api_has_unpublished_artefact, #content_api_licence_hash, #setup_content_api_business_support_schemes_stubs, #setup_content_api_licences_stubs, #stub_content_api_default_artefact, #tag_for_slug

Constructor Details

#initialize(slug) ⇒ ArtefactStub

Returns a new instance of ArtefactStub.



11
12
13
14
15
16
# File 'lib/gds_api/test_helpers/content_api/artefact_stub.rb', line 11

def initialize(slug)
  @slug = slug
  @query_parameters = {}
  @response_body = artefact_for_slug(slug)
  @response_status = 200
end

Instance Attribute Details

#query_parametersObject

Returns the value of attribute query_parameters.



9
10
11
# File 'lib/gds_api/test_helpers/content_api/artefact_stub.rb', line 9

def query_parameters
  @query_parameters
end

#response_bodyObject

Returns the value of attribute response_body.



9
10
11
# File 'lib/gds_api/test_helpers/content_api/artefact_stub.rb', line 9

def response_body
  @response_body
end

#response_statusObject

Returns the value of attribute response_status.



9
10
11
# File 'lib/gds_api/test_helpers/content_api/artefact_stub.rb', line 9

def response_status
  @response_status
end

#slugObject

Returns the value of attribute slug.



9
10
11
# File 'lib/gds_api/test_helpers/content_api/artefact_stub.rb', line 9

def slug
  @slug
end

Instance Method Details

#stubObject

Nothing is stubbed until this is called



34
35
36
37
38
# File 'lib/gds_api/test_helpers/content_api/artefact_stub.rb', line 34

def stub
  stub_request(:get, url_without_query)
      .with(query: hash_including(comparable_query_params))
      .to_return(status: @response_status, body: @response_body.to_json)
end

#with_query_parameters(hash) ⇒ Object



18
19
20
21
# File 'lib/gds_api/test_helpers/content_api/artefact_stub.rb', line 18

def with_query_parameters(hash)
  @query_parameters = hash
  self
end

#with_response_body(response_body) ⇒ Object



23
24
25
26
# File 'lib/gds_api/test_helpers/content_api/artefact_stub.rb', line 23

def with_response_body(response_body)
  @response_body = response_body
  self
end

#with_response_status(response_status) ⇒ Object



28
29
30
31
# File 'lib/gds_api/test_helpers/content_api/artefact_stub.rb', line 28

def with_response_status(response_status)
  @response_status = response_status
  self
end