mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 12:13:58 -06:00
FIX: Username update should ignore revisions without raw
This commit is contained in:
parent
ba0cec2091
commit
c67c2dc638
@ -31,11 +31,13 @@ module Jobs
|
||||
|
||||
def update_revisions
|
||||
PostRevision.where(post_conditions("post_revisions.post_id"), post_condition_args).find_each do |revision|
|
||||
revision.modifications["raw"].map! { |raw| update_raw(raw) }
|
||||
revision.modifications["cooked"].map! { |cooked| update_cooked(cooked) }
|
||||
if revision.modifications.key?("raw") || revision.modifications.key?("cooked")
|
||||
revision.modifications["raw"]&.map! { |raw| update_raw(raw) }
|
||||
revision.modifications["cooked"]&.map! { |cooked| update_cooked(cooked) }
|
||||
revision.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_notifications
|
||||
params = {
|
||||
|
@ -218,28 +218,30 @@ describe UsernameChanger do
|
||||
end
|
||||
|
||||
it 'replaces mentions within revisions' do
|
||||
revisions = [{ raw: "Hello Foo" }, { raw: "Hello @foo!" }, { raw: "Hello @foo!!" }]
|
||||
revisions = [{ raw: "Hello Foo" }, { title: "new topic title" }, { raw: "Hello @foo!" }, { raw: "Hello @foo!!" }]
|
||||
post = create_post_and_change_username(raw: "Hello @foo", revisions: revisions)
|
||||
|
||||
expect(post.raw).to eq("Hello @bar!!")
|
||||
expect(post.cooked).to eq(%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a>!!</p>))
|
||||
|
||||
expect(post.revisions.count).to eq(3)
|
||||
expect(post.revisions.count).to eq(4)
|
||||
|
||||
expect(post.revisions[0].modifications["raw"][0]).to eq("Hello @bar")
|
||||
expect(post.revisions[0].modifications["raw"][1]).to eq("Hello Foo")
|
||||
expect(post.revisions[0].modifications["cooked"][0]).to eq(%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a></p>))
|
||||
expect(post.revisions[0].modifications["cooked"][1]).to eq(%Q(<p>Hello Foo</p>))
|
||||
|
||||
expect(post.revisions[1].modifications["raw"][0]).to eq("Hello Foo")
|
||||
expect(post.revisions[1].modifications["raw"][1]).to eq("Hello @bar!")
|
||||
expect(post.revisions[1].modifications["cooked"][0]).to eq(%Q(<p>Hello Foo</p>))
|
||||
expect(post.revisions[1].modifications["cooked"][1]).to eq(%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a>!</p>))
|
||||
expect(post.revisions[1].modifications).to include("title")
|
||||
|
||||
expect(post.revisions[2].modifications["raw"][0]).to eq("Hello @bar!")
|
||||
expect(post.revisions[2].modifications["raw"][1]).to eq("Hello @bar!!")
|
||||
expect(post.revisions[2].modifications["cooked"][0]).to eq(%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a>!</p>))
|
||||
expect(post.revisions[2].modifications["cooked"][1]).to eq(%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a>!!</p>))
|
||||
expect(post.revisions[2].modifications["raw"][0]).to eq("Hello Foo")
|
||||
expect(post.revisions[2].modifications["raw"][1]).to eq("Hello @bar!")
|
||||
expect(post.revisions[2].modifications["cooked"][0]).to eq(%Q(<p>Hello Foo</p>))
|
||||
expect(post.revisions[2].modifications["cooked"][1]).to eq(%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a>!</p>))
|
||||
|
||||
expect(post.revisions[3].modifications["raw"][0]).to eq("Hello @bar!")
|
||||
expect(post.revisions[3].modifications["raw"][1]).to eq("Hello @bar!!")
|
||||
expect(post.revisions[3].modifications["cooked"][0]).to eq(%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a>!</p>))
|
||||
expect(post.revisions[3].modifications["cooked"][1]).to eq(%Q(<p>Hello <a class="mention" href="/u/bar">@bar</a>!!</p>))
|
||||
end
|
||||
|
||||
it 'replaces mentions in posts marked for deletion' do
|
||||
|
Loading…
Reference in New Issue
Block a user