Skip to content

Commit e742988

Browse files
Add whitespace normalisation when creating pending changes
1 parent 5a589e9 commit e742988

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

app/models/concerns/pending_changes_concern.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def apply_pending_changes_to_new_record!
5656

5757
def normalised(value)
5858
if value.is_a?(String)
59-
value.downcase.presence
59+
value.downcase.normalise_whitespace&.presence
6060
elsif value.is_a?(Time)
6161
value.round
6262
else

spec/models/concerns/pending_changes_concern_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,17 @@
6262
end
6363

6464
describe "#normalised" do
65-
it "downcases strings and returns presence" do
65+
it "downcases strings" do
6666
expect(model.send(:normalised, "HELLO WORLD")).to eq("hello world")
6767
expect(model.send(:normalised, "Mixed Case")).to eq("mixed case")
6868
expect(model.send(:normalised, "lowercase")).to eq("lowercase")
6969
end
7070

71+
it "normalises whitespace in strings" do
72+
expect(model.send(:normalised, " Hello World ")).to eq("hello world")
73+
expect(model.send(:normalised, "Hello\tWorld")).to eq("hello world")
74+
end
75+
7176
it "returns nil for empty strings" do
7277
expect(model.send(:normalised, "")).to be_nil
7378
expect(model.send(:normalised, " ")).to be_nil

0 commit comments

Comments
 (0)