mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 13:55:08 +08:00
BUGFIX/FEATURE: store topic changes in post revisions
History + edit notifications for title and category changes
This commit is contained in:
@ -3,7 +3,63 @@ require_dependency 'post_revision'
|
||||
|
||||
describe PostRevision do
|
||||
|
||||
it { should belong_to :user }
|
||||
it { should belong_to :post }
|
||||
before do
|
||||
@number = 1
|
||||
end
|
||||
|
||||
def create_rev(modifications, post_id=1)
|
||||
@number += 1
|
||||
PostRevision.create!(post_id: post_id, user_id: 1, number: @number, modifications: modifications)
|
||||
end
|
||||
|
||||
it "can grab history from current object" do
|
||||
p = PostRevision.new(modifications: {"foo" => ["bar", "bar1"]})
|
||||
p.previous("foo").should == "bar"
|
||||
p.current("foo").should == "bar1"
|
||||
end
|
||||
|
||||
it "can fallback to previous revisions if needed" do
|
||||
create_rev("foo" => ["A", "B"])
|
||||
r2 = create_rev("bar" => ["C", "D"])
|
||||
|
||||
r2.current("foo").should == "B"
|
||||
r2.previous("foo").should == "B"
|
||||
end
|
||||
|
||||
it "can fallback to post if needed" do
|
||||
post = Fabricate(:post)
|
||||
r = create_rev({"foo" => ["A", "B"]}, post.id)
|
||||
|
||||
r.current("raw").should == post.raw
|
||||
r.previous("raw").should == post.raw
|
||||
r.current("cooked").should == post.cooked
|
||||
r.previous("cooked").should == post.cooked
|
||||
end
|
||||
|
||||
it "can fallback to topic if needed" do
|
||||
post = Fabricate(:post)
|
||||
r = create_rev({"foo" => ["A", "B"]}, post.id)
|
||||
|
||||
r.current("title").should == post.topic.title
|
||||
r.previous("title").should == post.topic.title
|
||||
end
|
||||
|
||||
it "can find title changes" do
|
||||
r = create_rev({"title" => ["hello", "frog"]})
|
||||
r.title_changes[:inline].should =~ /frog.*hello/
|
||||
r.title_changes[:side_by_side].should =~ /hello.*frog/
|
||||
end
|
||||
|
||||
it "can find category changes" do
|
||||
cat1 = Fabricate(:category, name: "cat1")
|
||||
cat2 = Fabricate(:category, name: "cat2")
|
||||
|
||||
r = create_rev({"category_id" => [cat1.id, cat2.id]})
|
||||
|
||||
changes = r.category_changes
|
||||
changes[:previous_category_id].should == cat1.id
|
||||
changes[:current_category_id].should == cat2.id
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,9 +0,0 @@
|
||||
require 'spec_helper'
|
||||
require_dependency 'topic_revision'
|
||||
|
||||
describe TopicRevision do
|
||||
|
||||
it { should belong_to :user }
|
||||
it { should belong_to :topic }
|
||||
|
||||
end
|
@ -7,23 +7,6 @@ describe Topic do
|
||||
|
||||
it { should validate_presence_of :title }
|
||||
|
||||
it { should belong_to :category }
|
||||
it { should belong_to :user }
|
||||
it { should belong_to :last_poster }
|
||||
it { should belong_to :featured_user1 }
|
||||
it { should belong_to :featured_user2 }
|
||||
it { should belong_to :featured_user3 }
|
||||
it { should belong_to :featured_user4 }
|
||||
|
||||
it { should have_many :posts }
|
||||
it { should have_many :topic_users }
|
||||
it { should have_many :topic_links }
|
||||
it { should have_many :topic_allowed_users }
|
||||
it { should have_many :allowed_users }
|
||||
it { should have_many :invites }
|
||||
it { should have_many :topic_revisions }
|
||||
it { should have_many :revisions }
|
||||
|
||||
it { should rate_limit }
|
||||
|
||||
context 'slug' do
|
||||
@ -735,10 +718,11 @@ describe Topic do
|
||||
end
|
||||
|
||||
describe 'revisions' do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:topic) { post.topic }
|
||||
|
||||
it "has no revisions by default" do
|
||||
topic.revisions.size.should == 1
|
||||
post.revisions.size.should == 0
|
||||
end
|
||||
|
||||
context 'changing title' do
|
||||
@ -749,7 +733,7 @@ describe Topic do
|
||||
end
|
||||
|
||||
it "creates a new revision" do
|
||||
topic.revisions.size.should == 2
|
||||
post.revisions.size.should == 1
|
||||
end
|
||||
|
||||
end
|
||||
@ -762,7 +746,7 @@ describe Topic do
|
||||
end
|
||||
|
||||
it "creates a new revision" do
|
||||
topic.revisions.size.should == 2
|
||||
post.revisions.size.should == 1
|
||||
end
|
||||
|
||||
context "removing a category" do
|
||||
@ -771,7 +755,12 @@ describe Topic do
|
||||
end
|
||||
|
||||
it "creates a new revision" do
|
||||
topic.revisions.size.should == 3
|
||||
post.revisions.size.should == 2
|
||||
last_rev = post.revisions.order(:number).last
|
||||
last_rev.previous("category_id").should == category.id
|
||||
last_rev.current("category_id").should == SiteSetting.uncategorized_category_id
|
||||
post.reload
|
||||
post.version.should == 3
|
||||
end
|
||||
end
|
||||
|
||||
@ -784,7 +773,7 @@ describe Topic do
|
||||
end
|
||||
|
||||
it "doesn't create a new version" do
|
||||
topic.revisions.size.should == 1
|
||||
post.revisions.size.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
@ -1210,7 +1199,7 @@ describe Topic do
|
||||
describe 'secured' do
|
||||
it 'can remove secure groups' do
|
||||
category = Fabricate(:category, read_restricted: true)
|
||||
topic = Fabricate(:topic, category: category)
|
||||
Fabricate(:topic, category: category)
|
||||
|
||||
Topic.secured(Guardian.new(nil)).count.should == 0
|
||||
Topic.secured(Guardian.new(Fabricate(:admin))).count.should == 2
|
||||
|
Reference in New Issue
Block a user