Skip to content

Commit

Permalink
Skip validation for licence with link but no text
Browse files Browse the repository at this point in the history
Currently ~40 licences in Publisher don't have will continue on text but
do have a link as this validation doesn't exist in Publisher. Now we've
implemented it here, we need to skip that certain validation for the
import to successfully import all licences. Next time these licences are
edited, they will need the link text to save and publish so the
situation will resolve in time.

Trello:
https://trello.com/c/FUHCUnxO/2096-skip-validation-for-will-continue-on-text-when-importing
  • Loading branch information
1pretz1 committed Jul 10, 2023
1 parent 8f45a81 commit 9b61574
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 9b61574

Please sign in to comment.