mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
FIX: Posts in the approval queue were sometimes dropping category
This commit is contained in:
parent
92cc57b5da
commit
0f01c9d25f
|
@ -70,6 +70,13 @@ class Reviewable < ActiveRecord::Base
|
||||||
%w[ReviewableFlaggedPost ReviewableQueuedPost ReviewableUser]
|
%w[ReviewableFlaggedPost ReviewableQueuedPost ReviewableUser]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def created_new!
|
||||||
|
self.created_new = true
|
||||||
|
self.topic = target.topic if topic.blank? && target.is_a?(Post)
|
||||||
|
self.target_created_by_id = target.is_a?(Post) ? target.user_id : nil
|
||||||
|
self.category_id = topic.category_id if category_id.blank? && topic.present?
|
||||||
|
end
|
||||||
|
|
||||||
# Create a new reviewable, or if the target has already been reviewed return it to the
|
# Create a new reviewable, or if the target has already been reviewed return it to the
|
||||||
# pending state and re-use it.
|
# pending state and re-use it.
|
||||||
#
|
#
|
||||||
|
@ -90,11 +97,7 @@ class Reviewable < ActiveRecord::Base
|
||||||
payload: payload,
|
payload: payload,
|
||||||
potential_spam: potential_spam
|
potential_spam: potential_spam
|
||||||
)
|
)
|
||||||
reviewable.created_new = true
|
reviewable.created_new!
|
||||||
reviewable.topic = target.topic if reviewable.topic.blank? && target.is_a?(Post)
|
|
||||||
reviewable.target_created_by_id = target.is_a?(Post) ? target.user_id : nil
|
|
||||||
reviewable.category_id = reviewable.topic.category_id if reviewable.topic.present?
|
|
||||||
|
|
||||||
reviewable.save!
|
reviewable.save!
|
||||||
reviewable
|
reviewable
|
||||||
|
|
||||||
|
|
|
@ -206,6 +206,7 @@ class NewPostManager
|
||||||
)
|
)
|
||||||
reviewable.payload['title'] = @args[:title] if @args[:title].present?
|
reviewable.payload['title'] = @args[:title] if @args[:title].present?
|
||||||
reviewable.category_id = args[:category] if args[:category].present?
|
reviewable.category_id = args[:category] if args[:category].present?
|
||||||
|
reviewable.created_new!
|
||||||
|
|
||||||
create_options = reviewable.create_options
|
create_options = reviewable.create_options
|
||||||
|
|
||||||
|
|
|
@ -276,7 +276,8 @@ describe NewPostManager do
|
||||||
topic.user,
|
topic.user,
|
||||||
raw: 'to the handler I say enqueue me!',
|
raw: 'to the handler I say enqueue me!',
|
||||||
title: 'this is the title of the queued post',
|
title: 'this is the title of the queued post',
|
||||||
tags: ['hello', 'world']
|
tags: ['hello', 'world'],
|
||||||
|
category: topic.category_id
|
||||||
)
|
)
|
||||||
|
|
||||||
result = manager.perform
|
result = manager.perform
|
||||||
|
@ -288,6 +289,7 @@ describe NewPostManager do
|
||||||
expect(reviewable.reviewable_scores).to be_present
|
expect(reviewable.reviewable_scores).to be_present
|
||||||
expect(reviewable.score).to eq(20.5)
|
expect(reviewable.score).to eq(20.5)
|
||||||
expect(reviewable.reviewable_by_moderator?).to eq(true)
|
expect(reviewable.reviewable_by_moderator?).to eq(true)
|
||||||
|
expect(reviewable.category).to be_present
|
||||||
expect(reviewable.payload['tags']).to eq(['hello', 'world'])
|
expect(reviewable.payload['tags']).to eq(['hello', 'world'])
|
||||||
expect(result.action).to eq(:enqueued)
|
expect(result.action).to eq(:enqueued)
|
||||||
expect(result).to be_success
|
expect(result).to be_success
|
||||||
|
@ -301,9 +303,13 @@ describe NewPostManager do
|
||||||
manager = NewPostManager.new(
|
manager = NewPostManager.new(
|
||||||
topic.user,
|
topic.user,
|
||||||
raw: 'another post by this user queue me',
|
raw: 'another post by this user queue me',
|
||||||
title: 'cool title in another topic'
|
topic_id: topic.id
|
||||||
)
|
)
|
||||||
result = manager.perform
|
result = manager.perform
|
||||||
|
reviewable = result.reviewable
|
||||||
|
|
||||||
|
expect(reviewable.topic).to be_present
|
||||||
|
expect(reviewable.category).to be_present
|
||||||
expect(result.pending_count).to eq(1)
|
expect(result.pending_count).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user