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:
@@ -15,7 +15,7 @@ class BulkUpdateRequest < ApplicationRecord
|
|||||||
validate :validate_script, :on => :create
|
validate :validate_script, :on => :create
|
||||||
before_validation :initialize_attributes, :on => :create
|
before_validation :initialize_attributes, :on => :create
|
||||||
before_validation :normalize_text
|
before_validation :normalize_text
|
||||||
before_create :create_forum_topic
|
after_create :create_forum_topic
|
||||||
after_save :update_notice
|
after_save :update_notice
|
||||||
|
|
||||||
scope :pending_first, -> { order(Arel.sql("(case status when 'pending' then 0 when 'approved' then 1 else 2 end)")) }
|
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
|
CurrentUser.as(user) do
|
||||||
self.forum_topic = ForumTopic.create(title: title, category_id: 1, creator: user) unless forum_topic.present?
|
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?
|
self.forum_post = forum_topic.posts.create(body: reason_with_link, creator: user) unless forum_post.present?
|
||||||
|
save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -104,9 +104,11 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "create a forum topic" do
|
should "create a forum topic" do
|
||||||
assert_difference("ForumTopic.count", 1) do
|
bur = create(:bulk_update_request, reason: "zzz", script: "create alias aaa -> bbb")
|
||||||
BulkUpdateRequest.create(:title => "abc", :reason => "zzz", :script => "create alias aaa -> bbb", :skip_secondary_validations => true)
|
|
||||||
end
|
assert_equal(true, bur.forum_post.present?)
|
||||||
|
assert_match(/\[bur:#{bur.id}\]/, bur.forum_post.body)
|
||||||
|
assert_match(/zzz/, bur.forum_post.body)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "that has an invalid alias" do
|
context "that has an invalid alias" do
|
||||||
|
|||||||
Reference in New Issue
Block a user