Skip to content

Commit

Permalink
Merge pull request #2343 from alphagov/allow-blank-will-continue-on-text
Browse files Browse the repository at this point in the history
Skip validation for licence with link but no text
  • Loading branch information
1pretz1 committed Jul 11, 2023
2 parents 1602963 + 9b61574 commit a6408cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/validators/link_or_identifier_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def will_continue_on_exists_and_link_blank?(record)
end

def will_continue_on_blank_and_link_exists?(record)
record.licence_transaction_will_continue_on.blank? && record.licence_transaction_continuation_link.present?
# TODO: remove after licences have been imported, currently ~40 licences don't have will
# continue on text but do have a link. Next time these licences are edited, they will need
# the link text to save and publish
unless record.imported
record.licence_transaction_will_continue_on.blank? && record.licence_transaction_continuation_link.present?
end
end
end
17 changes: 16 additions & 1 deletion spec/validators/link_or_identifier_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ class LicenceTransaction
include ActiveModel::API
attr_accessor :licence_transaction_continuation_link,
:licence_transaction_will_continue_on,
:licence_transaction_licence_identifier
:licence_transaction_licence_identifier,
:imported
end

RSpec.describe LinkOrIdentifierValidator do
let(:imported) { false }
let(:record) do
LicenceTransaction.new(
{
licence_transaction_continuation_link: link,
licence_transaction_will_continue_on: will_continue_on,
licence_transaction_licence_identifier: identifier,
imported:,
},
)
end
Expand Down Expand Up @@ -42,6 +45,18 @@ class LicenceTransaction
end
end

context "when a link exists without will continue on text for an imported licence" do
let(:link) { "https://www.gov.uk" }
let(:will_continue_on) { nil }
let(:identifier) { nil }
let(:imported) { true }

it "validates successfully" do
subject.validate(record)
expect(record.errors[:licence_transaction_continuation_link]).to be_blank
end
end

context "when a link, will continue on and link doesn't exist" do
let(:link) { nil }
let(:will_continue_on) { nil }
Expand Down

0 comments on commit a6408cf

Please sign in to comment.