Skip to content

Commit

Permalink
Merge pull request #71 from Christine-horrocks/master
Browse files Browse the repository at this point in the history
Add in the data alternates, request id and url to the home page
  • Loading branch information
cazwazacz committed Oct 3, 2018
2 parents b6202cc + b43c916 commit 2a72b8d
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class HomeController < ApplicationController
# This controller renders the home page serializer. It does not currently query the data base.
def index
render_page(PageSerializer::HomePageSerializer.new)
render_page(PageSerializer::HomePageSerializer.new(request_id: app_insights_request_id, request_original_url: request.original_url))
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(group: nil, request_id: nil, data_alternates: nil, request_origin
private

def meta
{ title: title }
super(title: title)
end

def title
Expand Down
6 changes: 4 additions & 2 deletions app/serializers/page_serializer/home_page_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ class HomePageSerializer < PageSerializer::BasePageSerializer
# Initialise a Home index page serializer.
#
# @param [String] opensearch_description_url a description url for the search.
def initialize(opensearch_description_url: nil)
def initialize(opensearch_description_url: nil, request_id: nil, request_original_url: nil)
@opensearch_description_url = opensearch_description_url

super(request_id: request_id, request_original_url: request_original_url)
end

private

attr_reader :opensearch_description_url

def meta
{ title: 'beta.parliament.uk' }
super(title: 'beta.parliament.uk')
end

def content
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/page_serializer/list_page_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(page_title: nil, list_components: nil, request_id: nil, data_alte
private

def meta
{ title: @page_title }
super(title: @page_title)
end

def content
Expand Down
23 changes: 23 additions & 0 deletions spec/fixtures/controllers/groups_controller/index/fixture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ layout:
template: layout
meta:
title: groups.index.title
request-id: 123456
data-alternates:
- type: application/n-triples
href: http://localhost:3030/group_index.nt
- type: text/turtle
href: http://localhost:3030/group_index.ttl
- type: text/tab-separated-values
href: http://localhost:3030/group_index.tsv
- type: text/csv
href: http://localhost:3030/group_index.csv
- type: application/json+rdf
href: http://localhost:3030/group_index.rj
- type: application/json+ld
href: http://localhost:3030/group_index.json
- type: application/rdf+xml
href: http://localhost:3030/group_index.xml
open-graph:
title: groups.index.title
original-url: http://www.example.com/groups
image-url: https://static.parliament.uk/assets-public/opengraph-oblong.png
image-width: '1200'
image-height: '630'
twitter-card: summary_large_image
header-components:
- name: link
data:
Expand Down
23 changes: 23 additions & 0 deletions spec/fixtures/controllers/groups_controller/show/fixture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ layout:
template: layout
meta:
title: groupName - 1
request-id: 123456
data-alternates:
- type: application/n-triples
href: http://localhost:3030/group_by_id.nt?group_id=0RNgrC4q
- type: text/turtle
href: http://localhost:3030/group_by_id.ttl?group_id=0RNgrC4q
- type: text/tab-separated-values
href: http://localhost:3030/group_by_id.tsv?group_id=0RNgrC4q
- type: text/csv
href: http://localhost:3030/group_by_id.csv?group_id=0RNgrC4q
- type: application/json+rdf
href: http://localhost:3030/group_by_id.rj?group_id=0RNgrC4q
- type: application/json+ld
href: http://localhost:3030/group_by_id.json?group_id=0RNgrC4q
- type: application/rdf+xml
href: http://localhost:3030/group_by_id.xml?group_id=0RNgrC4q
open-graph:
title: groupName - 1
original-url: http://www.example.com/groups/0RNgrC4q
image-url: https://static.parliament.uk/assets-public/opengraph-oblong.png
image-width: '1200'
image-height: '630'
twitter-card: summary_large_image
header-components:
- name: link
data:
Expand Down
9 changes: 9 additions & 0 deletions spec/fixtures/controllers/home_controller/index/fixture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ layout:
template: layout
meta:
title: beta.parliament.uk
request-id: 123456
data-alternates:
open-graph:
title: beta.parliament.uk
original-url: http://www.example.com/
image-url: https://static.parliament.uk/assets-public/opengraph-oblong.png
image-width: '1200'
image-height: '630'
twitter-card: summary_large_image
header-components:
- name: link
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ layout:
template: layout
meta:
title: proposed-negative-statutory-instruments.index.title
request-id: 123456
data-alternates:
- type: application/n-triples
href: http://localhost:3030/proposed_negative_statutory_instrument_index.nt
- type: text/turtle
href: http://localhost:3030/proposed_negative_statutory_instrument_index.ttl
- type: text/tab-separated-values
href: http://localhost:3030/proposed_negative_statutory_instrument_index.tsv
- type: text/csv
href: http://localhost:3030/proposed_negative_statutory_instrument_index.csv
- type: application/json+rdf
href: http://localhost:3030/proposed_negative_statutory_instrument_index.rj
- type: application/json+ld
href: http://localhost:3030/proposed_negative_statutory_instrument_index.json
- type: application/rdf+xml
href: http://localhost:3030/proposed_negative_statutory_instrument_index.xml
open-graph:
title: proposed-negative-statutory-instruments.index.title
original-url: http://www.example.com/proposed-negative-statutory-instruments
image-url: https://static.parliament.uk/assets-public/opengraph-oblong.png
image-width: '1200'
image-height: '630'
twitter-card: summary_large_image
header-components:
- name: link
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ layout:
template: layout
meta:
title: statutory-instruments.index.title
request-id: 123456
data-alternates:
- type: application/n-triples
href: http://localhost:3030/statutory_instrument_index.nt
- type: text/turtle
href: http://localhost:3030/statutory_instrument_index.ttl
- type: text/tab-separated-values
href: http://localhost:3030/statutory_instrument_index.tsv
- type: text/csv
href: http://localhost:3030/statutory_instrument_index.csv
- type: application/json+rdf
href: http://localhost:3030/statutory_instrument_index.rj
- type: application/json+ld
href: http://localhost:3030/statutory_instrument_index.json
- type: application/rdf+xml
href: http://localhost:3030/statutory_instrument_index.xml
open-graph:
title: statutory-instruments.index.title
original-url: http://www.example.com/statutory-instruments
image-url: https://static.parliament.uk/assets-public/opengraph-oblong.png
image-width: '1200'
image-height: '630'
twitter-card: summary_large_image
header-components:
- name: link
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ layout:
template: layout
meta:
title: Group Test
data-alternates:
open-graph:
title: Group Test
original-url:
image-url: https://static.parliament.uk/assets-public/opengraph-oblong.png
image-width: '1200'
image-height: '630'
twitter-card: summary_large_image
header-components:
- name: link
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ layout:
template: layout
meta:
title: Group Test
data-alternates:
open-graph:
title: Group Test
original-url:
image-url: https://static.parliament.uk/assets-public/opengraph-oblong.png
image-width: '1200'
image-height: '630'
twitter-card: summary_large_image
header-components:
- name: link
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ layout:
template: layout
meta:
title: beta.parliament.uk
data-alternates:
open-graph:
title: beta.parliament.uk
original-url:
image-url: https://static.parliament.uk/assets-public/opengraph-oblong.png
image-width: '1200'
image-height: '630'
twitter-card: summary_large_image
header-components:
- name: link
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ layout:
template: layout
meta:
title: Test page
data-alternates:
open-graph:
title: Test page
original-url:
image-url: https://static.parliament.uk/assets-public/opengraph-oblong.png
image-width: '1200'
image-height: '630'
twitter-card: summary_large_image
header-components:
- name: link
data:
Expand Down
4 changes: 3 additions & 1 deletion spec/integration/controllers/groups_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
context 'navigating to the index page' do
it 'renders expected JSON output' do
get '/groups'
filtered_response_body = filter_sensitive_data(response.body)

expected_json = get_fixture('index', 'fixture')

expect(JSON.parse(response.body).to_yaml).to eq(expected_json)
expect(JSON.parse(filtered_response_body).to_yaml).to eq(expected_json)
end
end
end
Expand All @@ -25,6 +26,7 @@
context 'navigating to the show page' do
it 'renders expected JSON output' do
get '/groups/0RNgrC4q'
filtered_response_body = filter_sensitive_data(response.body)

expected_json = get_fixture('show', 'fixture')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

context '#to_h' do
it 'produces a JSON hash' do

expected = get_fixture('fixture')

expect(subject.to_yaml).to eq expected
Expand Down

0 comments on commit 2a72b8d

Please sign in to comment.