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

AP-4575 [EXT]: Allow whitespace and case-insensitive searching #6030

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions app/forms/base_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def attr_accessor(*symbols)
def locally_assigned
@locally_assigned ||= []
end

def normalizes(name, with:)
send(:before_validation, proc {
send("#{name}=", with.call(send(name)))
})
end
end

def initialize(*args)
Expand Down
2 changes: 2 additions & 0 deletions app/forms/copy_case/search_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class SearchForm < BaseForm

attr_accessor :search_ref, :copiable_case

normalizes :search_ref, with: ->(search_ref) { search_ref.strip.upcase }

validates :search_ref,
presence: true,
format: { with: APPLICATION_REF_REGEXP },
Expand Down
2 changes: 2 additions & 0 deletions app/forms/link_case/search_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class SearchForm < BaseForm

APPLICATION_REF_REGEXP = /\AL-[0-9ABCDEFHIJKLMNPRTUVWXY]{3}-[0-9ABCDEFHIJKLMNPRTUVWXY]{3}\z/

normalizes :search_ref, with: ->(search_ref) { search_ref.strip.upcase }

validates :search_ref,
presence: true,
format: { with: APPLICATION_REF_REGEXP },
Expand Down
16 changes: 16 additions & 0 deletions spec/forms/copy_case/search_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@
end
end

context "with a mixed case and whitespace including but otherwise valid application reference" do
let(:search_ref) { " \t l-TVH-u0t \t" }

let(:source_application) do
create(:legal_aid_application,
application_ref: "L-TVH-U0T",
provider: legal_aid_application.provider)
end

before { source_application }

it "finds the application id" do
expect { call_save }.to change(instance, :copiable_case).from(nil).to(source_application)
end
end

context "with a valid format but non-existant application reference" do
let(:search_ref) { "L-FFF-FFF" }

Expand Down
14 changes: 14 additions & 0 deletions spec/forms/link_case/search_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@
end
end

context "with a mixed case and whitespace including but otherwise valid application reference" do
let(:search_ref) { " \t l-TVH-u0t \t" }

let(:source_application) do
create(:legal_aid_application, application_ref: "L-TVH-U0T")
end

before { source_application }

it "finds the application id" do
expect { call_save }.to change(instance, :linkable_case).from(nil).to(source_application)
end
end

context "with a valid format but non-existant application reference" do
let(:search_ref) { "L-FFF-FFF" }

Expand Down