BURs: fix broken [bur:<id>] links in forum posts.

Fix bulk update requests generating invalid [bur:<id>] links in forum
posts. The id was missing because the BUR created the forum topic in a
before_create hook, which created the post before the BUR was saved so
the BUR didn't have an id yet. Fix regression caused by b4ce2d83.
This commit is contained in:
evazion
2020-01-21 19:42:57 -06:00
parent 0a3d038df9
commit 1aadd19663
2 changed files with 7 additions and 4 deletions

View File

@@ -15,7 +15,7 @@ class BulkUpdateRequest < ApplicationRecord
validate :validate_script, :on => :create
before_validation :initialize_attributes, :on => :create
before_validation :normalize_text
before_create :create_forum_topic
after_create :create_forum_topic
after_save :update_notice
scope :pending_first, -> { order(Arel.sql("(case status when 'pending' then 0 when 'approved' then 1 else 2 end)")) }
@@ -97,6 +97,7 @@ class BulkUpdateRequest < ApplicationRecord
CurrentUser.as(user) do
self.forum_topic = ForumTopic.create(title: title, category_id: 1, creator: user) unless forum_topic.present?
self.forum_post = forum_topic.posts.create(body: reason_with_link, creator: user) unless forum_post.present?
save
end
end

View File

@@ -104,9 +104,11 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
end
should "create a forum topic" do
assert_difference("ForumTopic.count", 1) do
BulkUpdateRequest.create(:title => "abc", :reason => "zzz", :script => "create alias aaa -> bbb", :skip_secondary_validations => true)
end
bur = create(:bulk_update_request, reason: "zzz", script: "create alias aaa -> bbb")
assert_equal(true, bur.forum_post.present?)
assert_match(/\[bur:#{bur.id}\]/, bur.forum_post.body)
assert_match(/zzz/, bur.forum_post.body)
end
context "that has an invalid alias" do