diff --git a/db/fixtures/categories.rb b/db/fixtures/categories.rb new file mode 100644 index 00000000000..1c1558cdb56 --- /dev/null +++ b/db/fixtures/categories.rb @@ -0,0 +1,20 @@ +SiteSetting.refresh! +if SiteSetting.uncategorized_category_id == -1 + puts "Seeding uncategorized category!" + + result = Category.exec_sql "SELECT 1 FROM categories WHERE name = 'uncategorized'" + name = 'uncategorized' + if result.count > 0 + name << SecureRandom.hex + end + + result = Category.exec_sql "INSERT INTO categories + (name,color,slug,description,text_color, user_id, created_at, updated_at, position) + VALUES ('#{name}', 'AB9364', 'uncategorized', '', 'FFFFFF', -1, now(), now(), 1 ) + RETURNING id + " + category_id = result[0]["id"].to_i + + Category.exec_sql "INSERT INTO site_settings(name, data_type, value, created_at, updated_at) + VALUES ('uncategorized_category_id', 3, #{category_id}, now(), now())" +end diff --git a/db/migrate/20131022045114_add_uncategorized_category.rb b/db/migrate/20131022045114_add_uncategorized_category.rb index d8416d91677..f44e851efc4 100644 --- a/db/migrate/20131022045114_add_uncategorized_category.rb +++ b/db/migrate/20131022045114_add_uncategorized_category.rb @@ -2,14 +2,14 @@ class AddUncategorizedCategory < ActiveRecord::Migration def up result = execute "SELECT 1 FROM categories WHERE name = 'uncategorized'" + name = 'uncategorized' if result.count > 0 name << SecureRandom.hex end - result = execute "INSERT INTO categories (name,color,slug,description,text_color, user_id, created_at, updated_at, position) - VALUES ('uncategorized', 'AB9364', 'uncategorized', '', 'FFFFFF', -1, now(), now(), 1 ) + VALUES ('#{name}', 'AB9364', 'uncategorized', '', 'FFFFFF', -1, now(), now(), 1 ) RETURNING id " category_id = result[0]["id"].to_i diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index f0dcb29a53a..ce531412f8f 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -2,3 +2,7 @@ task 'db:migrate' => 'environment' do SeedFu.seed end + +task 'test:prepare' => 'environment' do + SeedFu.seed +end