diff --git a/db/fixtures/500_lounge_category.rb b/db/fixtures/500_lounge_category.rb index a711f3a21b6..469a29a4a13 100644 --- a/db/fixtures/500_lounge_category.rb +++ b/db/fixtures/500_lounge_category.rb @@ -5,36 +5,38 @@ unless Rails.env.test? # The category for users with trust level 3 has been created. # Add permissions and a description to it. - lounge.group_names = ['trust_level_3'] - unless lounge.save - puts lounge.errors.full_messages - raise "Failed to set permissions on trust level 3 lounge category!" - end - - 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, - skip_validations: true - ) - 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!" - end - - lounge.topic_id = post.topic.id + Category.transaction do + lounge.group_names = ['trust_level_3'] unless lounge.save puts lounge.errors.full_messages - puts "Failed to set the lounge description topic!" + raise "Failed to set permissions on trust level 3 lounge category!" 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}" + 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, + skip_validations: true + ) + 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!" + 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 end end diff --git a/db/fixtures/501_meta_category.rb b/db/fixtures/501_meta_category.rb index d8b0b9724e5..a0827c60239 100644 --- a/db/fixtures/501_meta_category.rb +++ b/db/fixtures/501_meta_category.rb @@ -2,28 +2,30 @@ unless Rails.env.test? meta = Category.where(id: SiteSetting.meta_category_id).first if meta && !meta.topic_id - creator = PostCreator.new(Discourse.system_user, - raw: I18n.t('meta_category_description'), - title: I18n.t('category.topic_prefix', category: meta.name), - category: meta.name, - archetype: Archetype.default - ) - post = creator.create + Category.transaction do + creator = PostCreator.new(Discourse.system_user, + raw: I18n.t('meta_category_description'), + title: I18n.t('category.topic_prefix', category: meta.name), + category: meta.name, + archetype: Archetype.default + ) + post = creator.create - unless post && post.id - puts post.errors.full_messages if post - puts creator.errors.inspect - raise "Failed meta topic" + unless post && post.id + puts post.errors.full_messages if post + puts creator.errors.inspect + raise "Failed meta topic" + end + + meta.set_permissions(:everyone => :full) + meta.topic_id = post.topic.id + unless meta.save + puts meta.errors.full_messages + puts "Failed to set the meta description and permission!" + end + + # Reset topic count because we don't count the description topic + Category.exec_sql "UPDATE categories SET topic_count = 0 WHERE id = #{meta.id}" end - - meta.set_permissions(:everyone => :full) - meta.topic_id = post.topic.id - unless meta.save - puts meta.errors.full_messages - puts "Failed to set the meta description and permission!" - end - - # Reset topic count because we don't count the description topic - Category.exec_sql "UPDATE categories SET topic_count = 0 WHERE id = #{meta.id}" end end diff --git a/db/fixtures/502_staff_category.rb b/db/fixtures/502_staff_category.rb index 96ce5650ace..116a13dfba3 100644 --- a/db/fixtures/502_staff_category.rb +++ b/db/fixtures/502_staff_category.rb @@ -4,35 +4,37 @@ unless Rails.env.test? # Add permissions and a description to the Staff category. - staff.group_names = ['staff'] - unless staff.save - puts staff.errors.full_messages - raise "Failed to set permissions on the Staff category!" - end - - 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!" - end - - staff.topic_id = post.topic.id + Category.transaction do + staff.group_names = ['staff'] unless staff.save puts staff.errors.full_messages - puts "Failed to set the Staff category description topic!" + raise "Failed to set permissions on the Staff category!" 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}" + 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!" + 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 end end