Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

FIX: Don't create a new version when a post is recovered. Also displa…

…y username instead of full name for consistency.
  • Loading branch information...
commit ea20993bedd09658cd5d1dad5be141fd273c83a3 1 parent 42c7a65
@eviltrout eviltrout authored
Showing with 32 additions and 3 deletions.
  1. +6 −3 app/models/post.rb
  2. +26 −0 spec/models/post_spec.rb
View
9 app/models/post.rb
@@ -14,7 +14,8 @@ module HiddenReason
FLAG_THRESHOLD_REACHED_AGAIN = 2
end
- versioned
+ versioned if: :raw_changed?
+
rate_limit
acts_as_paranoid
@@ -271,9 +272,11 @@ def cook(*args)
# 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
26 spec/models/post_spec.rb
@@ -41,6 +41,32 @@
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
Please sign in to comment.
Something went wrong with that request. Please try again.