Improve developer seeds
Return execution of observers in seeds. Mute email sending to letter opening in you browser. Added `rake dev` task to reset db and add seeds. Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
6e73b208a9
commit
39f80884db
11 changed files with 88 additions and 78 deletions
|
@ -8,8 +8,7 @@ User.seed(:id, [
|
|||
password_confirmation: "5iveL!fe",
|
||||
admin: true,
|
||||
projects_limit: 100,
|
||||
theme_id: Gitlab::Theme::MARS
|
||||
theme_id: Gitlab::Theme::MARS,
|
||||
confirmed_at: DateTime.now
|
||||
}
|
||||
])
|
||||
|
||||
User.find(1).confirm!
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
Gitlab::Seeder.quiet do
|
||||
project_urls = [
|
||||
'https://github.com/documentcloud/underscore.git',
|
||||
'https://github.com/diaspora/diaspora.git',
|
||||
|
@ -51,3 +52,4 @@ project_urls.each_with_index do |url, i|
|
|||
print 'F'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,6 +6,7 @@ Gitlab::Seeder.quiet do
|
|||
username: Faker::Internet.user_name,
|
||||
name: Faker::Name.name,
|
||||
email: Faker::Internet.email,
|
||||
confirmed_at: DateTime.now
|
||||
}])
|
||||
print '.'
|
||||
rescue ActiveRecord::RecordNotSaved
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
ActiveRecord::Base.observers.disable :all
|
||||
|
||||
Gitlab::Seeder.quiet do
|
||||
Group.all.each do |group|
|
||||
User.all.sample(4).each do |user|
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
ActiveRecord::Base.observers.disable :all
|
||||
|
||||
Gitlab::Seeder.quiet do
|
||||
(1..300).each do |i|
|
||||
# Random Project
|
||||
|
@ -12,9 +10,7 @@ Gitlab::Seeder.quiet do
|
|||
|
||||
user_id = user.id
|
||||
|
||||
begin
|
||||
Thread.current[:current_user] = user
|
||||
|
||||
Gitlab::Seeder.by_user(user) do
|
||||
Issue.seed(:id, [{
|
||||
id: i,
|
||||
project_id: project.id,
|
||||
|
@ -25,8 +21,6 @@ Gitlab::Seeder.quiet do
|
|||
title: Faker::Lorem.sentence(6),
|
||||
description: Faker::Lorem.sentence
|
||||
}])
|
||||
ensure
|
||||
Thread.current[:current_user] = nil
|
||||
end
|
||||
print('.')
|
||||
end
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
ActiveRecord::Base.observers.disable :all
|
||||
|
||||
Gitlab::Seeder.quiet do
|
||||
(1..100).each do |i|
|
||||
# Random Project
|
||||
|
@ -17,9 +15,8 @@ Gitlab::Seeder.quiet do
|
|||
next if branches.uniq.size < 2
|
||||
|
||||
user_id = user.id
|
||||
begin
|
||||
Thread.current[:current_user] = user
|
||||
|
||||
Gitlab::Seeder.by_user(user) do
|
||||
MergeRequest.seed(:id, [{
|
||||
id: i,
|
||||
source_branch: branches.first,
|
||||
|
@ -31,8 +28,6 @@ Gitlab::Seeder.quiet do
|
|||
milestone: project.milestones.sample,
|
||||
title: Faker::Lorem.sentence(6)
|
||||
}])
|
||||
ensure
|
||||
Thread.current[:current_user] = nil
|
||||
end
|
||||
print('.')
|
||||
end
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
ActiveRecord::Base.observers.enable :all
|
||||
|
||||
Gitlab::Seeder.quiet do
|
||||
User.first(30).each_with_index do |user, i|
|
||||
Key.seed(:id, [
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
ActiveRecord::Base.observers.disable :all
|
||||
|
||||
Gitlab::Seeder.quiet do
|
||||
contents = [
|
||||
`curl https://gist.github.com/randx/4275756/raw/da2f262920c96d1a970d48bf2e99147954b1f4bd/glus1204.sh`,
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
ActiveRecord::Base.observers.disable :all
|
||||
|
||||
Gitlab::Seeder.quiet do
|
||||
Issue.all.limit(10).each_with_index do |issue, i|
|
||||
5.times do
|
||||
user = issue.project.team.users.sample
|
||||
|
||||
Gitlab::Seeder.by_user(user) do
|
||||
Note.seed(:id, [{
|
||||
project_id: issue.project.id,
|
||||
author_id: issue.project.team.users.sample.id,
|
||||
author_id: user.id,
|
||||
note: Faker::Lorem.sentence,
|
||||
noteable_id: issue.id,
|
||||
noteable_type: 'Issue'
|
||||
}])
|
||||
|
||||
print '.'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,29 @@
|
|||
module Gitlab
|
||||
class Seeder
|
||||
def self.quiet
|
||||
mute_mailer
|
||||
SeedFu.quiet = true
|
||||
yield
|
||||
SeedFu.quiet = false
|
||||
puts "\nOK".green
|
||||
end
|
||||
|
||||
def self.by_user(user)
|
||||
begin
|
||||
Thread.current[:current_user] = user
|
||||
yield
|
||||
ensure
|
||||
Thread.current[:current_user] = nil
|
||||
end
|
||||
end
|
||||
|
||||
def self.mute_mailer
|
||||
code = <<-eos
|
||||
def Notify.delay
|
||||
self
|
||||
end
|
||||
eos
|
||||
eval(code)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
task dev: ["dev:setup"]
|
||||
|
||||
namespace :dev do
|
||||
desc "GITLAB | Setup developer environment (db, fixtures)"
|
||||
task :setup => :environment do
|
||||
ENV['force'] = 'yes'
|
||||
Rake::Task["db:setup"].invoke
|
||||
Rake::Task["db:seed_fu"].invoke
|
||||
Rake::Task["gitlab:setup"].invoke
|
||||
Rake::Task["gitlab:shell:setup"].invoke
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue