Seed categories in transactions

This commit is contained in:
Neil Lalonde
2014-03-19 11:59:53 -04:00
parent 51e3d72461
commit 7780013c3a
3 changed files with 78 additions and 72 deletions

View File

@ -5,6 +5,7 @@ unless Rails.env.test?
# The category for users with trust level 3 has been created.
# Add permissions and a description to it.
Category.transaction do
lounge.group_names = ['trust_level_3']
unless lounge.save
puts lounge.errors.full_messages
@ -37,4 +38,5 @@ unless Rails.env.test?
Category.exec_sql "UPDATE categories SET topic_count = 0 WHERE id = #{lounge.id}"
end
end
end
end

View File

@ -2,6 +2,7 @@ unless Rails.env.test?
meta = Category.where(id: SiteSetting.meta_category_id).first
if meta && !meta.topic_id
Category.transaction do
creator = PostCreator.new(Discourse.system_user,
raw: I18n.t('meta_category_description'),
title: I18n.t('category.topic_prefix', category: meta.name),
@ -26,4 +27,5 @@ unless Rails.env.test?
# 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
end

View File

@ -4,6 +4,7 @@ unless Rails.env.test?
# Add permissions and a description to the Staff category.
Category.transaction do
staff.group_names = ['staff']
unless staff.save
puts staff.errors.full_messages
@ -35,4 +36,5 @@ unless Rails.env.test?
Category.exec_sql "UPDATE categories SET topic_count = 0 WHERE id = #{staff.id}"
end
end
end
end