* FEATURE: Adds site setting to let quotes on direct replies.

* DEV: Added test.
* FIX: Do not bump topic when removing full quotes.
This commit is contained in:
Bianca Nenciu
2018-12-12 16:42:53 +02:00
committed by Régis Hanol
parent dbbadb5c35
commit 7cac04e1a8
4 changed files with 38 additions and 18 deletions

View File

@@ -1146,28 +1146,44 @@ describe CookedPostProcessor do
context "remove direct reply full quote" do
let(:topic) { Fabricate(:topic) }
let!(:post) { Fabricate(:post, topic: topic, raw: "this is the first post") }
let(:raw) do
<<~RAW
[quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]
this is the first post
[/quote]
and this is the third reply
RAW
end
it 'works' do
post = Fabricate(:post, topic: topic, raw: "this is the first post")
hidden = Fabricate(:post, topic: topic, hidden: true, raw: "this is the second post")
small_action = Fabricate(:post, topic: topic, post_type: Post.types[:small_action])
raw = <<~RAW
[quote="#{post.user.username}, post:#{post.post_number}, topic:#{topic.id}"]
this is the first post
[/quote]
SiteSetting.remove_full_quote = true
and this is the third reply
RAW
hidden = Fabricate(:post, topic: topic, hidden: true, raw: "this is the second post after")
small_action = Fabricate(:post, topic: topic, post_type: Post.types[:small_action])
reply = Fabricate(:post, topic: topic, raw: raw)
cpp = CookedPostProcessor.new(reply)
cpp.removed_direct_reply_full_quotes
freeze_time Time.zone.now do
topic.bumped_at = 1.day.ago
CookedPostProcessor.new(reply).removed_direct_reply_full_quotes
expect(topic.posts).to eq([post, hidden, small_action, reply])
expect(reply.raw).to eq("and this is the third reply")
expect(reply.revisions.count).to eq(1)
expect(reply.revisions.first.modifications["raw"]).to eq([raw, reply.raw])
expect(reply.revisions.first.modifications["edit_reason"][1]).to eq(I18n.t(:removed_direct_reply_full_quotes))
expect(topic.posts).to eq([post, hidden, small_action, reply])
expect(topic.bumped_at).to eq(1.day.ago)
expect(reply.raw).to eq("and this is the third reply")
expect(reply.revisions.count).to eq(1)
expect(reply.revisions.first.modifications["raw"]).to eq([raw, reply.raw])
expect(reply.revisions.first.modifications["edit_reason"][1]).to eq(I18n.t(:removed_direct_reply_full_quotes))
end
end
it "does nothing when 'remove_full_quote' is disabled" do
SiteSetting.remove_full_quote = false
reply = Fabricate(:post, topic: topic, raw: raw)
CookedPostProcessor.new(reply).removed_direct_reply_full_quotes
expect(reply.raw).to eq(raw)
end
end