LOTS of changes to properly handle post/topic revisions

FIX: history revision can now properly be hidden
FIX: PostRevision serializer is now entirely dynamic to properly handle
hidden revisions
FIX: default history modal to "side by side" view on mobile
FIX: properly hiden which revision has been hidden
UX: inline category/user/wiki/post_type changes with the revision
details
FEATURE: new '/posts/:post_id/revisions/latest' endpoint to retrieve
latest revision
UX: do not show the hide/show revision button on mobile (no room for
them)
UX: remove CSS transitions on the buttons in the history modal
FIX: PostRevisor now handles all the changes that might create new
revisions
FIX: PostRevision.ensure_consistency! was wrong due to off by 1
mistake...
refactored topic's callbacks for better readability
extracted 'PostRevisionGuardian'
This commit is contained in:
Régis Hanol
2014-10-27 22:06:43 +01:00
parent caf31dde1e
commit e7f251c105
46 changed files with 878 additions and 949 deletions

View File

@ -16,7 +16,7 @@ describe PostRevisor do
describe 'with the same body' do
it "doesn't change version" do
lambda {
subject.revise!(post.user, post.raw).should == false
subject.revise!(post.user, { raw: post.raw }).should == false
post.reload
}.should_not change(post, :version)
end
@ -25,10 +25,11 @@ describe PostRevisor do
describe 'ninja editing' do
it 'correctly applies edits' do
SiteSetting.ninja_edit_window = 1.minute.to_i
subject.revise!(post.user, 'updated body', revised_at: post.updated_at + 10.seconds)
subject.revise!(post.user, { raw: 'updated body' }, revised_at: post.updated_at + 10.seconds)
post.reload
post.version.should == 1
post.public_version.should == 1
post.revisions.size.should == 0
post.last_version_at.should == first_version_at
subject.category_changed.should be_blank
@ -41,7 +42,7 @@ describe PostRevisor do
before do
SiteSetting.stubs(:ninja_edit_window).returns(1.minute.to_i)
subject.revise!(post.user, 'updated body', revised_at: revised_at)
subject.revise!(post.user, { raw: 'updated body' }, revised_at: revised_at)
post.reload
end
@ -49,11 +50,12 @@ describe PostRevisor do
subject.category_changed.should be_blank
end
it 'updates the version' do
it 'updates the versions' do
post.version.should == 2
post.public_version.should == 2
end
it 'creates a new version' do
it 'creates a new revision' do
post.revisions.size.should == 1
end
@ -64,12 +66,13 @@ describe PostRevisor do
describe "new edit window" do
before do
subject.revise!(post.user, 'yet another updated body', revised_at: revised_at)
subject.revise!(post.user, { raw: 'yet another updated body' }, revised_at: revised_at)
post.reload
end
it "doesn't create a new version if you do another" do
post.version.should == 2
post.public_version.should == 2
end
it "doesn't change last_version_at" do
@ -85,12 +88,13 @@ describe PostRevisor do
let!(:new_revised_at) {revised_at + 2.minutes}
before do
subject.revise!(post.user, 'yet another, another updated body', revised_at: new_revised_at)
subject.revise!(post.user, { raw: 'yet another, another updated body' }, revised_at: new_revised_at)
post.reload
end
it "does create a new version after the edit window" do
post.version.should == 3
post.public_version.should == 3
end
it "does create a new version after the edit window" do
@ -116,7 +120,7 @@ describe PostRevisor do
context "one paragraph description" do
before do
subject.revise!(post.user, new_description)
subject.revise!(post.user, { raw: new_description })
category.reload
end
@ -131,7 +135,7 @@ describe PostRevisor do
context "multiple paragraph description" do
before do
subject.revise!(post.user, "#{new_description}\n\nOther content goes here.")
subject.revise!(post.user, { raw: "#{new_description}\n\nOther content goes here." })
category.reload
end
@ -147,7 +151,7 @@ describe PostRevisor do
context 'when updating back to the original paragraph' do
before do
category.update_column(:description, 'this is my description')
subject.revise!(post.user, Category.post_template)
subject.revise!(post.user, { raw: Category.post_template })
category.reload
end
@ -167,7 +171,7 @@ describe PostRevisor do
it "triggers a rate limiter" do
EditRateLimiter.any_instance.expects(:performed!)
subject.revise!(changed_by, 'updated body')
subject.revise!(changed_by, { raw: 'updated body' })
end
end
@ -178,7 +182,7 @@ describe PostRevisor do
SiteSetting.stubs(:newuser_max_images).returns(0)
url = "http://i.imgur.com/wfn7rgU.jpg"
Oneboxer.stubs(:onebox).with(url, anything).returns("<img src='#{url}'>")
subject.revise!(changed_by, "So, post them here!\n#{url}")
subject.revise!(changed_by, { raw: "So, post them here!\n#{url}" })
end
it "allows an admin to insert images into a new user's post" do
@ -196,7 +200,7 @@ describe PostRevisor do
SiteSetting.stubs(:newuser_max_images).returns(0)
url = "http://i.imgur.com/FGg7Vzu.gif"
Oneboxer.stubs(:cached_onebox).with(url, anything).returns("<img src='#{url}'>")
subject.revise!(post.user, "So, post them here!\n#{url}")
subject.revise!(post.user, { raw: "So, post them here!\n#{url}" })
end
it "doesn't allow images to be inserted" do
@ -208,7 +212,7 @@ describe PostRevisor do
describe 'with a new body' do
let(:changed_by) { Fabricate(:coding_horror) }
let!(:result) { subject.revise!(changed_by, "lets update the body") }
let!(:result) { subject.revise!(changed_by, { raw: "lets update the body" }) }
it 'returns true' do
result.should == true
@ -222,8 +226,9 @@ describe PostRevisor do
post.invalidate_oneboxes.should == true
end
it 'increased the version' do
it 'increased the versions' do
post.version.should == 2
post.public_version.should == 2
end
it 'has the new revision' do
@ -242,16 +247,14 @@ describe PostRevisor do
context 'second poster posts again quickly' do
before do
SiteSetting.expects(:ninja_edit_window).returns(1.minute.to_i)
subject.revise!(changed_by, 'yet another updated body', revised_at: post.updated_at + 10.seconds)
SiteSetting.stubs(:ninja_edit_window).returns(1.minute.to_i)
subject.revise!(changed_by, { raw: 'yet another updated body' }, revised_at: post.updated_at + 10.seconds)
post.reload
end
it 'is a ninja edit, because the second poster posted again quickly' do
post.version.should == 2
end
it 'is a ninja edit, because the second poster posted again quickly' do
post.public_version.should == 2
post.revisions.size.should == 1
end
end
@ -262,19 +265,19 @@ describe PostRevisor do
revisor = described_class.new(post)
first_post = topic.posts.by_post_number.first
expect {
revisor.revise!(first_post.user, 'Edit the first post', revised_at: first_post.updated_at + 10.seconds)
revisor.revise!(first_post.user, { raw: 'Edit the first post' }, revised_at: first_post.updated_at + 10.seconds)
topic.reload
}.to change { topic.excerpt }
second_post = Fabricate(:post, post_args.merge(post_number: 2, topic_id: topic.id))
expect {
described_class.new(second_post).revise!(second_post.user, 'Edit the 2nd post')
described_class.new(second_post).revise!(second_post.user, { raw: 'Edit the 2nd post' })
topic.reload
}.to_not change { topic.excerpt }
end
end
it "doesn't strip starting whitespaces" do
subject.revise!(post.user, " <-- whitespaces --> ")
subject.revise!(post.user, { raw: " <-- whitespaces --> " })
post.reload
post.raw.should == " <-- whitespaces -->"
end