mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 17:06:31 -06:00
FIX: Add topic_diff to PostRevisor (#12518)
The instance of the PostRevisor is passed to the post_edited event. It is useful to know what has happened to the topic in this event (we already pass a boolean for topic_changed? but that is not so helpful by itself).
This commit is contained in:
parent
9eb7c37098
commit
ea6f9af08b
@ -536,6 +536,10 @@ class PostRevisor
|
||||
@post.previous_changes.slice(*POST_TRACKED_FIELDS)
|
||||
end
|
||||
|
||||
def topic_diff
|
||||
@topic_changes.diff
|
||||
end
|
||||
|
||||
def perform_edit
|
||||
return if bypass_rate_limiter?
|
||||
EditRateLimiter.new(@editor).performed!
|
||||
|
@ -44,6 +44,22 @@ describe PostRevisor do
|
||||
end
|
||||
|
||||
context 'editing category' do
|
||||
it "triggers the :post_edited event with topic_changed?" do
|
||||
category = Fabricate(:category)
|
||||
category.set_permissions(everyone: :full)
|
||||
category.save!
|
||||
post = create_post
|
||||
events = DiscourseEvent.track_events do
|
||||
post.revise(post.user, category_id: category.id)
|
||||
end
|
||||
|
||||
event = events.find { |e| e[:event_name] == :post_edited }
|
||||
|
||||
expect(event[:params].first).to eq(post)
|
||||
expect(event[:params].second).to eq(true)
|
||||
expect(event[:params].third).to be_kind_of(PostRevisor)
|
||||
expect(event[:params].third.topic_diff).to eq({ "category_id" => [SiteSetting.uncategorized_category_id, category.id] })
|
||||
end
|
||||
|
||||
it 'does not revise category when no permission to create a topic in category' do
|
||||
category = Fabricate(:category)
|
||||
@ -855,6 +871,21 @@ describe PostRevisor do
|
||||
expect(post.topic.tags.map(&:name).sort).to eq(['important', 'stuff'])
|
||||
end
|
||||
|
||||
it "triggers the :post_edited event with topic_changed?" do
|
||||
topic.tags = [Fabricate(:tag, name: "super"), Fabricate(:tag, name: "stuff")]
|
||||
|
||||
events = DiscourseEvent.track_events do
|
||||
subject.revise!(user, raw: "lets totally update the body", tags: [])
|
||||
end
|
||||
|
||||
event = events.find { |e| e[:event_name] == :post_edited }
|
||||
|
||||
expect(event[:params].first).to eq(post)
|
||||
expect(event[:params].second).to eq(true)
|
||||
expect(event[:params].third).to be_kind_of(PostRevisor)
|
||||
expect(event[:params].third.topic_diff).to eq({ "tags" => [["super", "stuff"], []] })
|
||||
end
|
||||
|
||||
context "with staff-only tags" do
|
||||
before do
|
||||
create_staff_only_tags(['important'])
|
||||
|
Loading…
Reference in New Issue
Block a user