Skip to content

A platform for community discussion. Free, open, simple.

FIX: don't downcase watched words on input since it can break the watched_words_regular_expressions setting

Neil Lalonde8f21c96ea5e8
diff --git a/app/models/watched_word.rb b/app/models/watched_word.rb
index d9af0071de1..0861fb3a22d 100644
--- a/app/models/watched_word.rb
+++ b/app/models/watched_word.rb
@@ -31,11 +31,12 @@ class WatchedWord < ActiveRecord::Base
scope :by_action, -> { order("action ASC, word ASC") }
def self.normalize_word(w)
- w.strip.downcase.squeeze('*')
+ w.strip.squeeze('*')
end
def self.create_or_update_word(params)
- w = find_or_initialize_by(word: normalize_word(params[:word]))
+ new_word = normalize_word(params[:word])
+ w = WatchedWord.where("word ILIKE ?", new_word).first || WatchedWord.new(word: new_word)
w.action_key = params[:action_key] if params[:action_key]
w.action = params[:action] if params[:action]
w.save
diff --git a/spec/models/watched_word_spec.rb b/spec/models/watched_word_spec.rb
index 7bc52d47e5e..f4cc34bc102 100644
--- a/spec/models/watched_word_spec.rb
+++ b/spec/models/watched_word_spec.rb
@@ -11,8 +11,8 @@ describe WatchedWord do
expect(described_class.count).to eq(1)
end
- it "downcases words" do
- expect(described_class.create(word: "ShooT").word).to eq('shoot')
+ it "doesn't downcase words" do
+ expect(described_class.create(word: "ShooT").word).to eq('ShooT')
end
it "strips leading and trailing spaces" do
diff --git a/spec/services/word_watcher_spec.rb b/spec/services/word_watcher_spec.rb
index 334446502c8..52264cf41af 100644
--- a/spec/services/word_watcher_spec.rb
+++ b/spec/services/word_watcher_spec.rb
@@ -76,6 +76,21 @@ describe WordWatcher do
m = WordWatcher.new("trooooooooot").word_matches_for_action?(:require_approval)
expect(m[1]).to eq("trooooooooot")
end
+
+ it "support uppercase" do
+ Fabricate(
+ :watched_word,
+ word: /a\S+ce/,
+ action: WatchedWord.actions[:require_approval]
+ )
+
+ m = WordWatcher.new('Amazing place').word_matches_for_action?(:require_approval)
+ expect(m).to be_nil
+ m = WordWatcher.new('Amazing applesauce').word_matches_for_action?(:require_approval)
+ expect(m[1]).to eq('applesauce')
+ m = WordWatcher.new('Amazing AppleSauce').word_matches_for_action?(:require_approval)
+ expect(m[1]).to eq('AppleSauce')
+ end
end
end