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.



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

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.



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

def query_parameters
  @query_parameters
end

#response_bodyObject

Returns the value of attribute response_body.



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

def response_body
  @response_body
end

#response_statusObject

Returns the value of attribute response_status.



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

def response_status
  @response_status
end

#slugObject

Returns the value of attribute slug.



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

def slug
  @slug
end

Instance Method Details

#stubObject

Nothing is stubbed until this is called



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

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



20
21
22
23
# File 'lib/gds_api/test_helpers/content_api/artefact_stub.rb', line 20

def with_query_parameters(hash)
  @query_parameters = hash
  self
end

#with_response_body(response_body) ⇒ Object



25
26
27
28
# File 'lib/gds_api/test_helpers/content_api/artefact_stub.rb', line 25

def with_response_body(response_body)
  @response_body = response_body
  self
end

#with_response_status(response_status) ⇒ Object



30
31
32
33
# File 'lib/gds_api/test_helpers/content_api/artefact_stub.rb', line 30

def with_response_status(response_status)
  @response_status = response_status
  self
end