Skip to content

Commit

Permalink
WEBDEV-1056_statutory-instruments/statutory-instrament/work-package
Browse files Browse the repository at this point in the history
  • Loading branch information
Christine-horrocks committed Dec 12, 2018
1 parent 78559ff commit 9485f6d
Show file tree
Hide file tree
Showing 24 changed files with 1,246 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gem 'parliament-opensearch', '~> 0.4', require: false
gem 'parliament-grom-decorators', '~> 1.0.2'

# Parliament routing
gem 'parliament-routes', '~> 0.6'
gem 'parliament-routes', '~> 0.6.29'

gem 'parliament-ntriple', '~> 0.3', require: false

Expand Down
84 changes: 42 additions & 42 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (5.2.1.1)
actionpack (= 5.2.1.1)
actioncable (5.2.2)
actionpack (= 5.2.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailer (5.2.1.1)
actionpack (= 5.2.1.1)
actionview (= 5.2.1.1)
activejob (= 5.2.1.1)
actionmailer (5.2.2)
actionpack (= 5.2.2)
actionview (= 5.2.2)
activejob (= 5.2.2)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.2.1.1)
actionview (= 5.2.1.1)
activesupport (= 5.2.1.1)
actionpack (5.2.2)
actionview (= 5.2.2)
activesupport (= 5.2.2)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.1.1)
activesupport (= 5.2.1.1)
actionview (5.2.2)
activesupport (= 5.2.2)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.2.1.1)
activesupport (= 5.2.1.1)
activejob (5.2.2)
activesupport (= 5.2.2)
globalid (>= 0.3.6)
activemodel (5.2.1.1)
activesupport (= 5.2.1.1)
activerecord (5.2.1.1)
activemodel (= 5.2.1.1)
activesupport (= 5.2.1.1)
activemodel (5.2.2)
activesupport (= 5.2.2)
activerecord (5.2.2)
activemodel (= 5.2.2)
activesupport (= 5.2.2)
arel (>= 9.0)
activestorage (5.2.1.1)
actionpack (= 5.2.1.1)
activerecord (= 5.2.1.1)
activestorage (5.2.2)
actionpack (= 5.2.2)
activerecord (= 5.2.2)
marcel (~> 0.3.1)
activesupport (5.2.1.1)
activesupport (5.2.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
Expand Down Expand Up @@ -94,7 +94,7 @@ GEM
hamster (3.0.0)
concurrent-ruby (~> 1.0)
hashdiff (0.3.7)
i18n (1.1.1)
i18n (1.2.0)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.1)
json (2.1.0)
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.27)
parliament-routes (0.6.29)
parliament-ruby (0.10.2)
parser (2.5.3.0)
ast (~> 2.4.0)
Expand All @@ -141,20 +141,20 @@ GEM
rack-test (1.1.0)
rack (>= 1.0, < 3)
rack-timeout (0.5.1)
rails (5.2.1.1)
actioncable (= 5.2.1.1)
actionmailer (= 5.2.1.1)
actionpack (= 5.2.1.1)
actionview (= 5.2.1.1)
activejob (= 5.2.1.1)
activemodel (= 5.2.1.1)
activerecord (= 5.2.1.1)
activestorage (= 5.2.1.1)
activesupport (= 5.2.1.1)
rails (5.2.2)
actioncable (= 5.2.2)
actionmailer (= 5.2.2)
actionpack (= 5.2.2)
actionview (= 5.2.2)
activejob (= 5.2.2)
activemodel (= 5.2.2)
activerecord (= 5.2.2)
activestorage (= 5.2.2)
activesupport (= 5.2.2)
bundler (>= 1.3.0)
railties (= 5.2.1.1)
railties (= 5.2.2)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.3)
rails-controller-testing (1.0.4)
actionpack (>= 5.0.1.x)
actionview (>= 5.0.1.x)
activesupport (>= 5.0.1.x)
Expand All @@ -163,14 +163,14 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.2.1.1)
actionpack (= 5.2.1.1)
activesupport (= 5.2.1.1)
railties (5.2.2)
actionpack (= 5.2.2)
activesupport (= 5.2.2)
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rainbow (3.0.0)
rake (12.3.1)
rake (12.3.2)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
Expand All @@ -197,7 +197,7 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.60.0)
rubocop (0.61.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
Expand Down Expand Up @@ -266,7 +266,7 @@ DEPENDENCIES
parliament-grom-decorators (~> 1.0.2)
parliament-ntriple (~> 0.3)
parliament-opensearch (~> 0.4)
parliament-routes (~> 0.6)
parliament-routes (~> 0.6.29)
parliament-ruby (~> 0.8)
puma (~> 3.11)
rack-rewrite
Expand Down
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 app/controllers/statutory_instruments/work_packages_controller.rb
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
2 changes: 0 additions & 2 deletions app/factories/work_package_list_components_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ def date_description_list_item(work_package, date_type, grouping_block)
'laid-thing.laid-date'
when DateType::BUSINESS_ITEM_DATE
'procedure-steps.subsidiary-resources.actualised-date'
else
nil
end

create_date_description_list_item(translation_string, date) if date && translation_string
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ en:
type: "Statutory instrument"
index:
title: "Statutory instruments"
work_packages:
index:
title: "%{statutory_instrument} - procedural activity"
proposed_negative_statutory_instruments:
type: "Proposed negative statutory instrument"
index:
Expand Down
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
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
Loading

0 comments on commit 9485f6d

Please sign in to comment.