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.rbindex d9af0071de1..0861fb3a22d 100644--- a/app/models/watched_word.rb+++ b/app/models/watched_word.rb@@ -31,11 +31,12 @@ class WatchedWord < ActiveRecord::Basescope :by_action, -> { order("action ASC, word ASC") }def self.normalize_word(w)- w.strip.downcase.squeeze('*')+ w.strip.squeeze('*')enddef 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.savediff --git a/spec/models/watched_word_spec.rb b/spec/models/watched_word_spec.rbindex 7bc52d47e5e..f4cc34bc102 100644--- a/spec/models/watched_word_spec.rb+++ b/spec/models/watched_word_spec.rb@@ -11,8 +11,8 @@ describe WatchedWord doexpect(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')endit "strips leading and trailing spaces" dodiff --git a/spec/services/word_watcher_spec.rb b/spec/services/word_watcher_spec.rbindex 334446502c8..52264cf41af 100644--- a/spec/services/word_watcher_spec.rb+++ b/spec/services/word_watcher_spec.rb@@ -76,6 +76,21 @@ describe WordWatcher dom = 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')+ endendend