Skip to content

Commit

Permalink
Merge pull request #131 from katylouise/katylouise/webdev-1015_houses…
Browse files Browse the repository at this point in the history
…_laid_papers

[WEBDEV-1015] houses laid papers
  • Loading branch information
mattrayner authored Nov 21, 2018
2 parents 7f84d5e + 1265159 commit fde6577
Show file tree
Hide file tree
Showing 32 changed files with 86,196 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ GEM
msgpack (~> 1.0)
builder (3.2.3)
byebug (10.0.2)
capybara (3.10.1)
capybara (3.11.1)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand Down Expand Up @@ -129,7 +129,7 @@ GEM
parliament-opensearch (0.7.0)
activesupport (>= 5.0.0.1)
feedjira (~> 2.1, >= 2.1.2)
parliament-routes (0.6.26)
parliament-routes (0.6.27)
parliament-ruby (0.10.2)
parser (2.5.3.0)
ast (~> 2.4.0)
Expand Down Expand Up @@ -179,7 +179,7 @@ GEM
link_header (~> 0.0, >= 0.0.8)
rdf-vocab (2.2.9)
rdf (>= 2.2, < 4.0)
regexp_parser (1.2.0)
regexp_parser (1.3.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.2)
Expand Down Expand Up @@ -235,7 +235,7 @@ GEM
thor (0.19.4)
thread_safe (0.3.6)
timecop (0.9.1)
tins (1.20.0)
tins (1.20.2)
tzinfo (1.2.5)
thread_safe (~> 0.1)
tzinfo-data (1.2018.7)
Expand Down
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
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
22 changes: 22 additions & 0 deletions app/controllers/houses/made_available_controller.rb
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
4 changes: 2 additions & 2 deletions app/services/laid_thing_list_components_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def description_hash(item, statutory_instrument)
def description_list_content(statutory_instrument)
[].tap do |items|
items << date_description_item(statutory_instrument) if statutory_instrument&.laying&.date
items << create_description_list_item(term: 'laid-thing.laying-body', descriptions: [statutory_instrument&.laying&.body.try(:groupName)]) if statutory_instrument&.laying&.body
items << create_description_list_item(term: 'laid-thing.procedure', descriptions: [statutory_instrument&.work_package&.procedure.try(:procedureName)]) if statutory_instrument.try(:work_package).try(:procedure)
items << create_description_list_item(term: 'laid-thing.laying-body', descriptions: [statutory_instrument.laying.body.try(:groupName)]) if statutory_instrument.try(:laying).try(:body)
items << create_description_list_item(term: 'laid-thing.procedure', descriptions: [statutory_instrument.work_package.procedure.try(:procedureName)]) if statutory_instrument.try(:work_package).try(:procedure)
end
end

Expand Down
10 changes: 10 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,13 @@ en:
current:
si_title: "Current procedural activity for statutory instruments"
psni_title: "Current procedural activity for proposed negative statutory instruments"
houses:
made_available:
title: "%{house} - made available"
availability_types:
title: "%{house} - made available by availability types"
laid_papers:
title: "%{house} - laid papers"
laid_papers:
index:
title: "Laid papers"
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
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
Loading

0 comments on commit fde6577

Please sign in to comment.