mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:28:37 +08:00
FEATURE: Allow watched words to be created as a group (#26632)
At the moment, there is no way to create a group of related watched words together. If a user needed a set of words to be created together, they'll have to create them individually one at a time. This change attempts to allow related watched words to be created as a group. The idea here is to have a list of words be tied together via a common `WatchedWordGroup` record. Given a list of words, a `WatchedWordGroup` record is created and assigned to each `WatchedWord` record. The existing WatchedWord creation behaviour remains largely unchanged. Co-authored-by: Selase Krakani <skrakani@gmail.com> Co-authored-by: Martin Brennan <martin@discourse.org>
This commit is contained in:
@ -86,6 +86,17 @@ RSpec.describe Admin::WatchedWordsController do
|
||||
expect(WatchedWord.find_by(id: watched_word.id)).to eq(nil)
|
||||
expect(UserHistory.where(action: UserHistory.actions[:watched_word_destroy]).count).to eq(1)
|
||||
end
|
||||
|
||||
it "should delete watched word group if it's the last word" do
|
||||
watched_word_group = Fabricate(:watched_word_group)
|
||||
watched_word.update!(watched_word_group: watched_word_group)
|
||||
|
||||
delete "/admin/customize/watched_words/#{watched_word.id}.json"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(WatchedWordGroup.exists?(id: watched_word_group.id)).to be_falsey
|
||||
expect(WatchedWord.exists?(id: watched_word.id)).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -104,17 +115,24 @@ RSpec.describe Admin::WatchedWordsController do
|
||||
before { sign_in(admin) }
|
||||
|
||||
it "creates a word with default case sensitivity" do
|
||||
post "/admin/customize/watched_words.json", params: { action_key: "flag", word: "Deals" }
|
||||
expect {
|
||||
post "/admin/customize/watched_words.json",
|
||||
params: {
|
||||
action_key: "flag",
|
||||
words: %w[Deals Offer],
|
||||
}
|
||||
}.to change { WatchedWord.count }.by(2)
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(WatchedWord.take.word).to eq("Deals")
|
||||
expect(WatchedWord.last.word).to eq("Offer")
|
||||
end
|
||||
|
||||
it "creates a word with the given case sensitivity" do
|
||||
post "/admin/customize/watched_words.json",
|
||||
params: {
|
||||
action_key: "flag",
|
||||
word: "PNG",
|
||||
words: ["PNG"],
|
||||
case_sensitive: true,
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user