diff --git a/db/fixtures/500_lounge_category.rb b/db/fixtures/500_lounge_category.rb index 5cc9cd36341..675dc9ccb29 100644 --- a/db/fixtures/500_lounge_category.rb +++ b/db/fixtures/500_lounge_category.rb @@ -11,27 +11,29 @@ unless Rails.env.test? raise "Failed to set permissions on trust level 3 lounge category!" end - creator = PostCreator.new(Discourse.system_user, - raw: I18n.t('vip_category_description'), - title: I18n.t('category.topic_prefix', category: lounge.name), - category: lounge.name, - archetype: Archetype.default - ) - post = creator.create + if lounge.topic_id.nil? + creator = PostCreator.new(Discourse.system_user, + raw: I18n.t('vip_category_description'), + title: I18n.t('category.topic_prefix', category: lounge.name), + category: lounge.name, + archetype: Archetype.default + ) + post = creator.create - unless post && post.id - puts post.errors.full_messages if post - puts creator.errors.inspect - raise "Failed to create description for trust level 3 lounge!" + unless post && post.id + puts post.errors.full_messages if post + puts creator.errors.inspect + raise "Failed to create description for trust level 3 lounge!" + end + + lounge.topic_id = post.topic.id + unless lounge.save + puts lounge.errors.full_messages + puts "Failed to set the lounge description topic!" + end + + # Reset topic count because we don't count the description topic + Category.exec_sql "UPDATE categories SET topic_count = 0 WHERE id = #{lounge.id}" end - - lounge.topic_id = post.topic.id - unless lounge.save - puts lounge.errors.full_messages - puts "Failed to set the lounge description topic!" - end - - # Reset topic count because we don't count the description topic - Category.exec_sql "UPDATE categories SET topic_count = 0 WHERE id = #{lounge.id}" end end diff --git a/db/fixtures/502_staff_category.rb b/db/fixtures/502_staff_category.rb index a977726f95b..96ce5650ace 100644 --- a/db/fixtures/502_staff_category.rb +++ b/db/fixtures/502_staff_category.rb @@ -10,27 +10,29 @@ unless Rails.env.test? raise "Failed to set permissions on the Staff category!" end - creator = PostCreator.new(Discourse.system_user, - raw: I18n.t('staff_category_description'), - title: I18n.t('category.topic_prefix', category: staff.name), - category: staff.name, - archetype: Archetype.default - ) - post = creator.create + if staff.topic_id.nil? + creator = PostCreator.new(Discourse.system_user, + raw: I18n.t('staff_category_description'), + title: I18n.t('category.topic_prefix', category: staff.name), + category: staff.name, + archetype: Archetype.default + ) + post = creator.create - unless post && post.id - puts post.errors.full_messages if post - puts creator.errors.inspect - raise "Failed to create description for Staff category!" + unless post && post.id + puts post.errors.full_messages if post + puts creator.errors.inspect + raise "Failed to create description for Staff category!" + end + + staff.topic_id = post.topic.id + unless staff.save + puts staff.errors.full_messages + puts "Failed to set the Staff category description topic!" + end + + # Reset topic count because we don't count the description topic + Category.exec_sql "UPDATE categories SET topic_count = 0 WHERE id = #{staff.id}" end - - staff.topic_id = post.topic.id - unless staff.save - puts staff.errors.full_messages - puts "Failed to set the Staff category description topic!" - end - - # Reset topic count because we don't count the description topic - Category.exec_sql "UPDATE categories SET topic_count = 0 WHERE id = #{staff.id}" end end