Skip to content

Commit

Permalink
Remove leading and trailing whitespace from filters
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpattinson committed Sep 8, 2023
1 parent 681ca9f commit 7df5a33
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/lib/filters/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Base

def initialize(scope:, params:)
@scope = scope
@params = params
@params = params.transform_values(&:strip)
end

def apply
Expand Down
32 changes: 32 additions & 0 deletions spec/lib/filters/country_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,36 @@
expect(subject).to eq(scope)
end
end

context "with trailing whitespace" do
let(:params) { { location: "country:US " } }
let(:scope) { ApplicationForm.all }

let!(:included) do
create(
:application_form,
region: create(:region, country: create(:country, code: "US")),
)
end

it "returns a filtered scope" do
expect(subject).to contain_exactly(included)
end
end

context "with leading whitespace" do
let(:params) { { location: " country:US" } }
let(:scope) { ApplicationForm.all }

let!(:included) do
create(
:application_form,
region: create(:region, country: create(:country, code: "US")),
)
end

it "returns a filtered scope" do
expect(subject).to contain_exactly(included)
end
end
end
34 changes: 34 additions & 0 deletions spec/lib/filters/email_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,40 @@

it { is_expected.to contain_exactly(included) }
end

context "with trailing whitespace" do
let(:params) { { email: "[email protected] " } }
let(:scope) { ApplicationForm.all }
let!(:included) { create(:application_form, teacher:) }

before do
create(
:application_form,
teacher: create(:teacher, email: "[email protected]"),
)
end

it "returns a filtered scope" do
expect(subject).to contain_exactly(included)
end
end

context "with leading whitespace" do
let(:params) { { email: " [email protected]" } }
let(:scope) { ApplicationForm.all }
let!(:included) { create(:application_form, teacher:) }

before do
create(
:application_form,
teacher: create(:teacher, email: "[email protected]"),
)
end

it "returns a filtered scope" do
expect(subject).to contain_exactly(included)
end
end
end

context "the params don't include email" do
Expand Down

0 comments on commit 7df5a33

Please sign in to comment.