2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-05 08:59:27 +08:00

Extensibility for tracking changes to a topic

This commit is contained in:
Robin Ward 2015-01-27 12:13:45 -05:00
parent 420abdff69
commit d43944b3ed
7 changed files with 133 additions and 39 deletions

View file

@ -7,6 +7,38 @@ describe PostRevisor do
let(:newuser) { Fabricate(:newuser) }
let(:post_args) { {user: newuser, topic: topic} }
context 'TopicChanges' do
let(:topic) { Fabricate(:topic) }
let(:tc) {
topic.reload
PostRevisor::TopicChanges.new(topic, topic.user)
}
it 'provides a guardian' do
tc.guardian.should be_an_instance_of Guardian
end
it 'tracks changes properly' do
tc.diff.should == {}
# it remembers changes we tell it to
tc.record_change('height', '180cm', '170cm')
tc.diff['height'].should == ['180cm', '170cm']
# it works with arrays of values
tc.record_change('colors', nil, ['red', 'blue'])
tc.diff['colors'].should == [nil, ['red', 'blue']]
# it does not record changes to the same val
tc.record_change('wat', 'js', 'js')
tc.diff['wat'].should be_nil
tc.record_change('tags', ['a', 'b'], ['a', 'b'])
tc.diff['tags'].should be_nil
end
end
context 'revise' do
let(:post) { Fabricate(:post, post_args) }
let(:first_version_at) { post.last_version_at }