Skip to content

Instantly share code, notes, and snippets.

@fofr
Created January 19, 2018 15:52
Show Gist options
  • Select an option

  • Save fofr/3577308a00471bec435d55f523ad2f98 to your computer and use it in GitHub Desktop.

Select an option

Save fofr/3577308a00471bec435d55f523ad2f98 to your computer and use it in GitHub Desktop.
Random example before this week
# document_type can be set, otherwise it defaults to the same value as schema_type
def setup_and_visit_random_content_item(document_type: schema_type)
schema = GovukSchemas::Schema.find(frontend_schema: schema_type)
# The schema and random example is generated from schema_type
random_example = GovukSchemas::RandomExample.new(schema: schema)
# But the correct document type gets merged in
payload = random_example.merge_and_validate(document_type: document_type)
path = payload["base_path"]
stub_request(:get, %r{#{path}})
.to_return(status: 200, body: payload.to_json, headers: {})
visit path
end
# Override this method if your test file doesn't match the convention
def schema_type
self.class.to_s.gsub('Test', '').underscore
end
# For specialist_document:
# schema_type = specialist_document
# document_type = aaib_report
setup_and_visit_random_content_item(document_type: 'aaib_report')
# For specialist_document:
# schema_type = specialist_document
# document_type = specialist_document
setup_and_visit_random_content_item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment