FIX: Don't create a new version when a post is recovered. Also display username instead of full name for consistency.

This commit is contained in:
Robin Ward 2013-03-13 12:35:55 -04:00
parent 42c7a65a05
commit ea20993bed
2 changed files with 32 additions and 3 deletions

View File

@ -14,7 +14,8 @@ class Post < ActiveRecord::Base
FLAG_THRESHOLD_REACHED_AGAIN = 2
end
versioned
versioned if: :raw_changed?
rate_limit
acts_as_paranoid
@ -271,9 +272,11 @@ class Post < ActiveRecord::Base
# A list of versions including the initial version
def all_versions
result = []
result << { number: 1, display_username: user.name, created_at: created_at }
result << { number: 1, display_username: user.username, created_at: created_at }
versions.order(:number).includes(:user).each do |v|
result << { number: v.number, display_username: v.user.name, created_at: v.created_at }
if v.user.present?
result << { number: v.number, display_username: v.user.username, created_at: v.created_at }
end
end
result
end

View File

@ -41,6 +41,32 @@ describe Post do
end
describe "versions and deleting/recovery" do
let(:post) { Fabricate(:post, post_args) }
before do
post.destroy
post.reload
end
it "doesn't create a new version when deleted" do
post.versions.count.should == 0
end
describe "recovery" do
before do
post.recover
post.reload
end
it "doesn't create a new version when recovered" do
post.versions.count.should == 0
end
end
end
describe 'post uniqueness' do
context "disabled" do