Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dry specialist publisher tests #3029

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/aaib_report.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class AaibReport < Document
apply_validations
validates :date_of_occurrence,
presence: true,
unless: lambda { |report|
Expand Down
1 change: 1 addition & 0 deletions app/models/ai_assurance_portfolio_technique.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class AiAssurancePortfolioTechnique < Document
apply_validations
Copy link
Contributor

@lauraghiorghisor-tw lauraghiorghisor-tw Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did not add apply_validations to models that simply did not have any validation. They did not have any presence checks, nor any date fields (the only schema validations we added).

I believe it is still redundant to add this. I understand the "completeness" aspect, but it might also read as, "ah this thing should have validations", but then you look in the schema and there are none 🕵🏻‍♀️ Up to you though.

FORMAT_SPECIFIC_FIELDS = format_specific_fields

attr_accessor(*FORMAT_SPECIFIC_FIELDS)
Expand Down
1 change: 1 addition & 0 deletions app/models/countryside_stewardship_grant.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class CountrysideStewardshipGrant < Document
apply_validations
FORMAT_SPECIFIC_FIELDS = format_specific_fields

attr_accessor(*FORMAT_SPECIFIC_FIELDS)
Expand Down
1 change: 1 addition & 0 deletions app/models/data_ethics_guidance_document.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class DataEthicsGuidanceDocument < Document
apply_validations
FORMAT_SPECIFIC_FIELDS = format_specific_fields

attr_accessor(*FORMAT_SPECIFIC_FIELDS)
Expand Down
1 change: 1 addition & 0 deletions app/models/drug_safety_update.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class DrugSafetyUpdate < Document
apply_validations
FORMAT_SPECIFIC_FIELDS = format_specific_fields

attr_accessor(*FORMAT_SPECIFIC_FIELDS)
Expand Down
1 change: 1 addition & 0 deletions app/models/esi_fund.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class EsiFund < Document
apply_validations
FORMAT_SPECIFIC_FIELDS = format_specific_fields

attr_accessor(*FORMAT_SPECIFIC_FIELDS)
Expand Down
1 change: 1 addition & 0 deletions app/models/international_development_fund.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class InternationalDevelopmentFund < Document
apply_validations
FORMAT_SPECIFIC_FIELDS = format_specific_fields

attr_accessor(*FORMAT_SPECIFIC_FIELDS)
Expand Down
1 change: 1 addition & 0 deletions app/models/marine_equipment_approved_recommendation.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class MarineEquipmentApprovedRecommendation < Document
apply_validations
validates :year_adopted, format: /\A$|[1-9][0-9]{3}\z/

FORMAT_SPECIFIC_FIELDS = format_specific_fields
Expand Down
1 change: 1 addition & 0 deletions app/models/service_standard_report.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class ServiceStandardReport < Document
apply_validations
FORMAT_SPECIFIC_FIELDS = format_specific_fields

attr_accessor(*FORMAT_SPECIFIC_FIELDS)
Expand Down
1 change: 1 addition & 0 deletions app/models/veterans_support_organisation.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class VeteransSupportOrganisation < Document
apply_validations
FORMAT_SPECIFIC_FIELDS = format_specific_fields

attr_accessor(*FORMAT_SPECIFIC_FIELDS)
Expand Down
2 changes: 1 addition & 1 deletion lib/documents/schemas/esi_funds.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
}
],
"filter": {
"format": "european_structural_investment_fund"
"format": "esi_fund"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't (easily) change this as this value is used in Search API too and is associated with all the ESI specialist documents.

Copy link
Contributor Author

@GDSNewt GDSNewt Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah was worried that might be the case, format was a convenient value to use from the schema to set the document type in the test. I'm trying to add a conditional, in the test, to do this but having some issues accessing DOM elements atm 😢

},
"name": "European Structural and Investment Funds (ESIF)",
"organisations": [
Expand Down
104 changes: 19 additions & 85 deletions spec/features/access_control_spec.rb
Original file line number Diff line number Diff line change
@@ -1,126 +1,60 @@
require "spec_helper"

RSpec.feature "Access control", type: :feature do
before do
stub_publishing_api_has_content([], hash_including(document_type: CmaCase.document_type))
stub_publishing_api_has_content([], hash_including(document_type: AaibReport.document_type))
stub_publishing_api_has_content([], hash_including(document_type: StatutoryInstrument.document_type))
stub_publishing_api_has_content([], hash_including(document_type: Organisation.document_type))
context "as an editor of an organisation that doesn't have access to the application" do
before do
log_in_as_editor(:incorrect_id_editor)
end

scenario "visiting homepage shows a permissions error" do
visit "/"

expect(page.status_code).to eq(200)
expect(page).to have_content("Sorry, you don't have permission to access this application")
expect(page).to have_content("Please contact your main GDS contact if you need access.")
end
end

context "as a CMA Editor" do
before do
stub_publishing_api_has_content([], hash_including(document_type: CmaCase.document_type))
stub_publishing_api_has_content([], hash_including(document_type: Organisation.document_type))
log_in_as_editor(:cma_editor)
end

scenario "visiting /cma-cases" do
scenario "visiting /cma-cases is allowed" do
visit "/cma-cases"

expect(page.status_code).to eq(200)
expect(page).to have_content("CMA Cases")
end

scenario "visiting admin/cma-cases" do
scenario "visiting admin/cma-cases is allowed" do
visit "admin/cma-cases"

expect(page.status_code).to eq(200)
expect(page).to have_content("CMA Case finder")
end

scenario "visiting /aaib-reports" do
scenario "visiting /aaib-reports is rejected" do
visit "/aaib-reports"

expect(page.current_path).to eq("/cma-cases")
expect(page).to have_content("You aren't permitted to access AAIB Reports")
end

scenario "visiting admin/aaib-reports" do
scenario "visiting admin/aaib-reports is rejected" do
visit "admin/aaib-reports"

expect(page.current_path).to eq("/cma-cases")
expect(page).to have_content("You aren't permitted to access AAIB Reports")
end

scenario "visiting a format which doesn't exist" do
scenario "visiting a format which doesn't exist gives an error message" do
visit "/a-format-which-doesnt-exist"

expect(page.current_path).to eq("/cma-cases")
expect(page).to have_content("That format doesn't exist.")
end
end

context "as an AAIB Editor" do
before do
log_in_as_editor(:aaib_editor)
end

scenario "visiting /aaib-reports" do
visit "/aaib-reports"

expect(page.status_code).to eq(200)
expect(page).to have_content("AAIB Reports")
end

scenario "visiting admin/aaib-reports" do
visit "admin/aaib-reports"

expect(page.status_code).to eq(200)
expect(page).to have_content("AAIB Report finder")
end

scenario "visiting /cma-cases" do
visit "/cma-cases"

expect(page.current_path).to eq("/aaib-reports")
expect(page).to have_content("You aren't permitted to access CMA Cases")
end

scenario "visiting admin/cma-cases" do
visit "admin/cma-cases"

expect(page.current_path).to eq("/aaib-reports")
expect(page).to have_content("You aren't permitted to access CMA Cases")
end
end

context "as a statutory instrument editor" do
before do
stub_publishing_api_has_content([], hash_including(document_type: Organisation.document_type))
log_in_as_editor(:statutory_instrument_editor)
end

scenario "visiting the statutory instruments format" do
visit "/eu-withdrawal-act-2018-statutory-instruments"

expect(page.status_code).to eq(200)
expect(page).to have_content("EU Withdrawal Act 2018 statutory instruments")
end

scenario "visiting another format" do
visit "/cma-cases"

expect(page.current_path).to eq("/eu-withdrawal-act-2018-statutory-instruments")
expect(page).to have_content("You aren't permitted to access CMA Cases")
end

scenario "visiting the home page" do
visit "/"

expect(page.current_path).to eq("/eu-withdrawal-act-2018-statutory-instruments")
end
end

context "as an editor with incorrect organisation_content_id" do
before do
log_in_as_editor(:incorrect_id_editor)
end

scenario "visiting /" do
visit "/"

expect(page.status_code).to eq(200)
expect(page).to have_content("Sorry, you don't have permission to access this application")
expect(page).to have_content("Please contact your main GDS contact if you need access.")
end
end
end
Loading