-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from katylouise/katylouise/webdev-1015_houses…
…_laid_papers [WEBDEV-1015] houses laid papers
- Loading branch information
Showing
32 changed files
with
86,196 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/controllers/houses/made_available/availability_types/laid_papers_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Houses | ||
module MadeAvailable | ||
module AvailabilityTypes | ||
class LaidPapersController < ApplicationController | ||
before_action :build_request, :data_check | ||
|
||
ROUTE_MAP = { | ||
index: proc { |params| ParliamentHelper.parliament_request.house_laid_papers.set_url_params({ house_id: params[:house_id] }) } | ||
}.freeze | ||
|
||
def index | ||
@house, @laid_papers = FilterHelper.filter(@api_request, 'House', 'LaidThing') | ||
@house = @house.first | ||
|
||
list_components = LaidThingListComponentsFactory.sort_and_build_components(statutory_instruments: @laid_papers, type: :laid_thing, small: true) | ||
|
||
heading = ComponentSerializer::Heading1ComponentSerializer.new(heading: I18n.t('houses.made_available.availability_types.laid_papers.title', house: @house.try(:houseName)), subheading: @house.try(:houseName), subheading_link: house_path) | ||
|
||
serializer = PageSerializer::ListPageSerializer.new(request: request, heading_component: heading, list_components: list_components, data_alternates: @alternates) | ||
|
||
render_page(serializer) | ||
end | ||
end | ||
end | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
app/controllers/houses/made_available/availability_types_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Houses | ||
module MadeAvailable | ||
class AvailabilityTypesController < ApplicationController | ||
before_action :build_request, :data_check | ||
|
||
ROUTE_MAP = { | ||
index: proc { |params| ParliamentHelper.parliament_request.house_by_id.set_url_params({ house_id: params[:house_id] }) } | ||
}.freeze | ||
|
||
def index | ||
@house = FilterHelper.filter(@api_request, 'House') | ||
@house = @house.first | ||
|
||
list_components = [CardFactory.new(heading_text: 'houses.subsidiary-resources.laid-papers', heading_translation_url: house_made_available_availability_types_laid_papers_path).build_card] | ||
|
||
heading = ComponentSerializer::Heading1ComponentSerializer.new(heading: I18n.t('houses.made_available.availability_types.title', house: @house.try(:houseName)), subheading: @house.try(:houseName), subheading_link: house_path) | ||
|
||
serializer = PageSerializer::ListPageSerializer.new(request: request, heading_component: heading, list_components: list_components, data_alternates: @alternates) | ||
|
||
render_page(serializer) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Houses | ||
class MadeAvailableController < ApplicationController | ||
before_action :build_request, :data_check | ||
|
||
ROUTE_MAP = { | ||
index: proc { |params| ParliamentHelper.parliament_request.house_laid_papers.set_url_params({ house_id: params[:house_id] }) } | ||
}.freeze | ||
|
||
def index | ||
@house, @laid_papers = FilterHelper.filter(@api_request, 'House', 'LaidThing') | ||
@house = @house.first | ||
|
||
list_components = LaidThingListComponentsFactory.sort_and_build_components(statutory_instruments: @laid_papers, type: :laid_thing, small: true) | ||
|
||
heading = ComponentSerializer::Heading1ComponentSerializer.new(heading: I18n.t('houses.made_available.title', house: @house.try(:houseName)), subheading: @house.try(:houseName), subheading_link: house_path) | ||
|
||
serializer = PageSerializer::ListPageSerializer.new(request: request, heading_component: heading, list_components: list_components, data_alternates: @alternates) | ||
|
||
render_page(serializer) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
spec/controllers/houses/made_available/availability_types/laid_papers_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Houses::MadeAvailable::AvailabilityTypes::LaidPapersController, vcr: true do | ||
describe 'GET index' do | ||
let(:data_alternates) do | ||
[{ | ||
href: "#{ENV['PARLIAMENT_BASE_URL']}/house_laid_papers.nt?house_id=WkUWUBMx", | ||
type: 'application/n-triples' | ||
}, | ||
{ href: "#{ENV['PARLIAMENT_BASE_URL']}/house_laid_papers.ttl?house_id=WkUWUBMx", | ||
type: 'text/turtle' }, | ||
{ href: "#{ENV['PARLIAMENT_BASE_URL']}/house_laid_papers.tsv?house_id=WkUWUBMx", | ||
type: 'text/tab-separated-values' }, | ||
{ href: "#{ENV['PARLIAMENT_BASE_URL']}/house_laid_papers.csv?house_id=WkUWUBMx", | ||
type: 'text/csv' }, | ||
{ href: "#{ENV['PARLIAMENT_BASE_URL']}/house_laid_papers.rj?house_id=WkUWUBMx", | ||
type: 'application/json+rdf' }, | ||
{ href: "#{ENV['PARLIAMENT_BASE_URL']}/house_laid_papers.json?house_id=WkUWUBMx", | ||
type: 'application/json+ld' }, | ||
{ href: "#{ENV['PARLIAMENT_BASE_URL']}/house_laid_papers.xml?house_id=WkUWUBMx", | ||
type: 'application/rdf+xml' }] | ||
end | ||
|
||
let(:heading) { 'a heading component' } | ||
|
||
before(:each) do | ||
allow(PageSerializer::ListPageSerializer).to receive(:new) | ||
allow(ComponentSerializer::Heading1ComponentSerializer).to receive(:new) { heading } | ||
|
||
allow(controller.request).to receive(:env).and_return({ 'ApplicationInsights.request.id' => '|1234abcd.' }) | ||
|
||
get :index, params: { house_id: 'WkUWUBMx' } | ||
end | ||
|
||
it 'should have a response with http status ok (200)' do | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
context 'the correct instance variables' do | ||
it 'assigns @house' do | ||
expect(assigns(:house)).to be_a(Grom::Node) | ||
expect(assigns(:house).type).to include('https://id.parliament.uk/schema/House') | ||
end | ||
|
||
it 'assigns @laid_papers' do | ||
assigns(:laid_papers).each do |laid_paper| | ||
expect(laid_paper).to be_a(Grom::Node) | ||
expect(laid_paper.type).to include('https://id.parliament.uk/schema/LaidThing') | ||
end | ||
end | ||
end | ||
|
||
context 'calling the serializers correctly' do | ||
it 'calls the Heading1ComponentSerializer correctly' do | ||
expect(ComponentSerializer::Heading1ComponentSerializer).to have_received(:new).with(heading: 'houseName - 1 - laid papers', subheading: 'houseName - 1', subheading_link: '/houses/WkUWUBMx') | ||
end | ||
|
||
it 'calls the ListPageSerializer correctly' do | ||
list_components = [{ 'data' => | ||
{ 'heading' => | ||
{ 'data' => | ||
{ 'content' => | ||
"<a href=\"/statutory-instruments/HJ7BlYte\">laidThingName - 1</a>", | ||
'size' => 2 }, | ||
'name' => 'heading' }, | ||
'list-description' => | ||
{ 'data' => | ||
{ 'items' => | ||
[{ 'description' => [{ 'content' => 'shared.time-html', | ||
'data' => {"date"=>"8 May 2018", "datetime-value"=>"2018-05-08"}}], | ||
'term' => { 'content' => 'laid-thing.laid-date' } }, | ||
{"description"=>[{"content"=>"groupName - 1"}], | ||
"term"=>{"content"=>"laid-thing.laying-body"}}, | ||
{"description"=>[{"content"=>"procedureName - 1"}], | ||
"term"=>{"content"=>"laid-thing.procedure"}}]}, | ||
'name' => 'list__description' }, | ||
'small' => | ||
{ 'data' => { 'content' => 'Statutory instrument' }, | ||
'name' => 'partials__small' } }, | ||
'name' => 'card__generic' }, | ||
{ 'data' => | ||
{ 'heading' => | ||
{ 'data' => | ||
{ 'content' => | ||
"<a href=\"/statutory-instruments/xic2yu5i\">laidThingName - 2</a>", | ||
'size' => 2 }, | ||
'name' => 'heading' }, | ||
'list-description' => | ||
{ 'data' => | ||
{ 'items' => | ||
[{ 'description' => [{ 'content' => 'shared.time-html', | ||
'data' => {"date"=>"20 April 2018", "datetime-value"=>"2018-04-20"}}], | ||
'term' => { 'content' => 'laid-thing.laid-date' } }, | ||
{"description"=>[{"content"=>"groupName - 2"}], | ||
"term"=>{"content"=>"laid-thing.laying-body"}}, | ||
{"description"=>[{"content"=>"procedureName - 1"}], | ||
"term"=>{"content"=>"laid-thing.procedure"}}]}, | ||
'name' => 'list__description' }, | ||
'small' => | ||
{ 'data' => { 'content' => 'Statutory instrument' }, | ||
'name' => 'partials__small' } }, | ||
'name' => 'card__generic' } | ||
|
||
] | ||
|
||
expect(PageSerializer::ListPageSerializer).to have_received(:new).with(request: request, heading_component: heading, list_components: list_components, data_alternates: data_alternates) | ||
end | ||
end | ||
end | ||
end |
65 changes: 65 additions & 0 deletions
65
spec/controllers/houses/made_available/availability_types_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Houses::MadeAvailable::AvailabilityTypesController, vcr: true do | ||
describe 'GET index' do | ||
let(:data_alternates) do | ||
[{ | ||
href: "#{ENV['PARLIAMENT_BASE_URL']}/house_by_id.nt?house_id=WkUWUBMx", | ||
type: 'application/n-triples' | ||
}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/house_by_id.ttl?house_id=WkUWUBMx", | ||
type: 'text/turtle'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/house_by_id.tsv?house_id=WkUWUBMx", | ||
type: 'text/tab-separated-values'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/house_by_id.csv?house_id=WkUWUBMx", | ||
type: 'text/csv'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/house_by_id.rj?house_id=WkUWUBMx", | ||
type: 'application/json+rdf'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/house_by_id.json?house_id=WkUWUBMx", | ||
type: 'application/json+ld'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/house_by_id.xml?house_id=WkUWUBMx", | ||
type: 'application/rdf+xml'}] | ||
end | ||
|
||
let(:heading) {'a heading component'} | ||
|
||
before(:each) do | ||
allow(PageSerializer::ListPageSerializer).to receive(:new) | ||
allow(ComponentSerializer::Heading1ComponentSerializer).to receive(:new) {heading} | ||
|
||
allow(controller.request).to receive(:env).and_return({'ApplicationInsights.request.id' => '|1234abcd.'}) | ||
|
||
get :index, params: { house_id: 'WkUWUBMx' } | ||
end | ||
|
||
it 'should have a response with http status ok (200)' do | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
context 'the correct instance variables' do | ||
it 'assigns @house' do | ||
expect(assigns(:house)).to be_a(Grom::Node) | ||
expect(assigns(:house).type).to include('https://id.parliament.uk/schema/House') | ||
end | ||
end | ||
|
||
context 'calling the serializers correctly' do | ||
it 'calls the Heading1ComponentSerializer correctly' do | ||
expect(ComponentSerializer::Heading1ComponentSerializer).to have_received(:new).with(heading: 'houseName - 1 - made available by availability types', subheading: 'houseName - 1', subheading_link: '/houses/WkUWUBMx') | ||
end | ||
|
||
it 'calls the ListPageSerializer correctly' do | ||
list_components = [{"data" => | ||
{"heading" => | ||
{"data" => | ||
{"content" => "houses.subsidiary-resources.laid-papers", | ||
"data"=> {"link"=>"/houses/WkUWUBMx/made-available/availability-types/laid-papers"}, | ||
"size" => 2}, | ||
"name" => "heading"}}, | ||
"name" => "card__generic"}] | ||
|
||
expect(PageSerializer::ListPageSerializer).to have_received(:new).with(request: request, heading_component: heading, list_components: list_components, data_alternates: data_alternates) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.