diff --git a/app/models/bulk_update_request.rb b/app/models/bulk_update_request.rb index a42a951f6..fea7992bf 100644 --- a/app/models/bulk_update_request.rb +++ b/app/models/bulk_update_request.rb @@ -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 diff --git a/test/unit/bulk_update_request_test.rb b/test/unit/bulk_update_request_test.rb index 9be6cd2da..ddde19c8a 100644 --- a/test/unit/bulk_update_request_test.rb +++ b/test/unit/bulk_update_request_test.rb @@ -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