-
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.
WEBDEV-1056_statutory-instruments/statutory-instrament/work-package
- Loading branch information
1 parent
78559ff
commit 9485f6d
Showing
24 changed files
with
1,246 additions
and
45 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
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
22 changes: 22 additions & 0 deletions
22
app/controllers/proposed_negative_statutory_instruments/work_packages_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,22 @@ | ||
module ProposedNegativeStatutoryInstruments | ||
class WorkPackagesController < ApplicationController | ||
before_action :build_request, :data_check | ||
|
||
ROUTE_MAP = { | ||
index: proc { |params| ParliamentHelper.parliament_request.proposed_negative_statutory_instrument_work_packages.set_url_params({ proposed_negative_statutory_instrument_id: params[:proposed_negative_statutory_instrument_id] }) } | ||
}.freeze | ||
|
||
def index | ||
@work_packaged_thing, @work_packages = FilterHelper.filter(@api_request, 'WorkPackagedThing', 'WorkPackage') | ||
@work_packaged_thing = @work_packaged_thing.first | ||
|
||
list_components = WorkPackageListComponentsFactory.sort_and_build_components(work_packages: @work_packages, date_type: :laying_date) | ||
|
||
heading = ComponentSerializer::Heading1ComponentSerializer.new(heading: I18n.t('statutory_instruments.work_packages.index.title', statutory_instrument: @work_packaged_thing.try(:workPackagedThingName)), subheading: @work_packaged_thing.try(:workPackagedThingName), subheading_link: proposed_negative_statutory_instrument_path) | ||
|
||
serializer = PageSerializer::ListPageSerializer.new(request: request, heading_component: heading, list_components: list_components, data_alternates: @alternates) | ||
|
||
render_page(serializer) | ||
end | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
app/controllers/statutory_instruments/work_packages_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,22 @@ | ||
module StatutoryInstruments | ||
class WorkPackagesController < ApplicationController | ||
before_action :build_request, :data_check | ||
|
||
ROUTE_MAP = { | ||
index: proc { |params| ParliamentHelper.parliament_request.statutory_instrument_work_packages.set_url_params({ statutory_instrument_id: params[:statutory_instrument_id] }) } | ||
}.freeze | ||
|
||
def index | ||
@work_packaged_thing, @work_packages = FilterHelper.filter(@api_request, 'WorkPackagedThing', 'WorkPackage') | ||
@work_packaged_thing = @work_packaged_thing.first | ||
|
||
list_components = WorkPackageListComponentsFactory.sort_and_build_components(work_packages: @work_packages, date_type: :laying_date) | ||
|
||
heading = ComponentSerializer::Heading1ComponentSerializer.new(heading: I18n.t('statutory_instruments.work_packages.index.title', statutory_instrument: @work_packaged_thing.try(:workPackagedThingName)), subheading: @work_packaged_thing.try(:workPackagedThingName), subheading_link: statutory_instrument_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
82 changes: 82 additions & 0 deletions
82
spec/controllers/proposed_negative_statutory_instruments/work_packages_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,82 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe ProposedNegativeStatutoryInstruments::WorkPackagesController, vcr: true do | ||
describe 'GET index' do | ||
let(:data_alternates) do | ||
[{ | ||
href: "#{ENV['PARLIAMENT_BASE_URL']}/proposed_negative_statutory_instrument_work_packages.nt?proposed_negative_statutory_instrument_id=XQq1bJo0", | ||
type: 'application/n-triples' | ||
}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/proposed_negative_statutory_instrument_work_packages.ttl?proposed_negative_statutory_instrument_id=XQq1bJo0", | ||
type: 'text/turtle'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/proposed_negative_statutory_instrument_work_packages.tsv?proposed_negative_statutory_instrument_id=XQq1bJo0", | ||
type: 'text/tab-separated-values'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/proposed_negative_statutory_instrument_work_packages.csv?proposed_negative_statutory_instrument_id=XQq1bJo0", | ||
type: 'text/csv'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/proposed_negative_statutory_instrument_work_packages.rj?proposed_negative_statutory_instrument_id=XQq1bJo0", | ||
type: 'application/json+rdf'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/proposed_negative_statutory_instrument_work_packages.json?proposed_negative_statutory_instrument_id=XQq1bJo0", | ||
type: 'application/json+ld'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/proposed_negative_statutory_instrument_work_packages.xml?proposed_negative_statutory_instrument_id=XQq1bJo0", | ||
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: {proposed_negative_statutory_instrument_id: 'XQq1bJo0'} | ||
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 @work_packaged_thing' do | ||
expect(assigns(:work_packaged_thing)).to be_a(Grom::Node) | ||
expect(assigns(:work_packaged_thing).type).to include('https://id.parliament.uk/schema/WorkPackagedThing') | ||
end | ||
|
||
it 'assigns @work_packages' do | ||
assigns(:work_packages).each do |work_package| | ||
expect(work_package).to be_a(Grom::Node) | ||
expect(work_package.type).to include('https://id.parliament.uk/schema/WorkPackage') | ||
end | ||
end | ||
end | ||
|
||
context 'calling the serializers correctly' do | ||
it 'calls the Heading1ComponentSerializer correctly' do | ||
expect(ComponentSerializer::Heading1ComponentSerializer).to have_received(:new).with(heading: 'workPackagedThingName - 1 - procedural activity', subheading: 'workPackagedThingName - 1', subheading_link: '/proposed-negative-statutory-instruments/XQq1bJo0') | ||
end | ||
|
||
it 'calls the ListPageSerializer correctly' do | ||
list_components = [{"data" => | ||
{"heading" => | ||
{"data" => | ||
{"content" => "<a href=\"/work-packages/V5iuO9gU\">workPackagedThingName - 1</a>", | ||
"size" => 2}, | ||
"name" => "heading"}, | ||
"list-description" => | ||
{"data" => | ||
{"items" => | ||
[{"description"=>[{"content"=>"procedureName - 1"}], | ||
"term"=>{"content"=>"laid-thing.procedure"}}, | ||
{"description" => [{"content" => "shared.time-html", | ||
"data"=>{"date"=>"5 December 2018", "datetime-value"=>"2018-12-05"}}], | ||
"term" => | ||
{"content" => | ||
"laid-thing.laid-date"}}]}, | ||
"name" => "list__description"}}, | ||
"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 |
82 changes: 82 additions & 0 deletions
82
spec/controllers/statutory_instruments/work_packages_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,82 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe StatutoryInstruments::WorkPackagesController, vcr: true do | ||
describe 'GET index' do | ||
let(:data_alternates) do | ||
[{ | ||
href: "#{ENV['PARLIAMENT_BASE_URL']}/statutory_instrument_work_packages.nt?statutory_instrument_id=8JaRgUlk", | ||
type: 'application/n-triples' | ||
}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/statutory_instrument_work_packages.ttl?statutory_instrument_id=8JaRgUlk", | ||
type: 'text/turtle'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/statutory_instrument_work_packages.tsv?statutory_instrument_id=8JaRgUlk", | ||
type: 'text/tab-separated-values'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/statutory_instrument_work_packages.csv?statutory_instrument_id=8JaRgUlk", | ||
type: 'text/csv'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/statutory_instrument_work_packages.rj?statutory_instrument_id=8JaRgUlk", | ||
type: 'application/json+rdf'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/statutory_instrument_work_packages.json?statutory_instrument_id=8JaRgUlk", | ||
type: 'application/json+ld'}, | ||
{href: "#{ENV['PARLIAMENT_BASE_URL']}/statutory_instrument_work_packages.xml?statutory_instrument_id=8JaRgUlk", | ||
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: {statutory_instrument_id: '8JaRgUlk'} | ||
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 @work_packaged_thing' do | ||
expect(assigns(:work_packaged_thing)).to be_a(Grom::Node) | ||
expect(assigns(:work_packaged_thing).type).to include('https://id.parliament.uk/schema/WorkPackagedThing') | ||
end | ||
|
||
it 'assigns @work_packages' do | ||
assigns(:work_packages).each do |work_package| | ||
expect(work_package).to be_a(Grom::Node) | ||
expect(work_package.type).to include('https://id.parliament.uk/schema/WorkPackage') | ||
end | ||
end | ||
end | ||
|
||
context 'calling the serializers correctly' do | ||
it 'calls the Heading1ComponentSerializer correctly' do | ||
expect(ComponentSerializer::Heading1ComponentSerializer).to have_received(:new).with(heading: 'workPackagedThingName - 1 - procedural activity', subheading: 'workPackagedThingName - 1', subheading_link: '/statutory-instruments/8JaRgUlk') | ||
end | ||
|
||
it 'calls the ListPageSerializer correctly' do | ||
list_components = [{"data" => | ||
{"heading" => | ||
{"data" => | ||
{"content" => "<a href=\"/work-packages/7T80P3Um\">workPackagedThingName - 1</a>", | ||
"size" => 2}, | ||
"name" => "heading"}, | ||
"list-description" => | ||
{"data" => | ||
{"items" => | ||
[{"description"=>[{"content"=>"procedureName - 1"}], | ||
"term"=>{"content"=>"laid-thing.procedure"}}, | ||
{"description" => [{"content" => "shared.time-html", | ||
"data"=>{"date"=>"3 December 2018", "datetime-value"=>"2018-12-03"}}], | ||
"term" => | ||
{"content" => | ||
"laid-thing.laid-date"}}]}, | ||
"name" => "list__description"}}, | ||
"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.