BigW Consortium Gitlab

12_snippets.rb 1.14 KB
Newer Older
1 2
require './spec/support/sidekiq'

3
Gitlab::Seeder.quiet do
Dmitriy Zaporozhets committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
  content =<<eos
class Member < ActiveRecord::Base
  include Notifiable
  include Gitlab::Access

  belongs_to :user
  belongs_to :source, polymorphic: true

  validates :user, presence: true
  validates :source, presence: true
  validates :user_id, uniqueness: { scope: [:source_type, :source_id], message: "already exists in source" }
  validates :access_level, inclusion: { in: Gitlab::Access.all_values }, presence: true

  scope :guests, -> { where(access_level: GUEST) }
  scope :reporters, -> { where(access_level: REPORTER) }
  scope :developers, -> { where(access_level: DEVELOPER) }
  scope :masters,  -> { where(access_level: MASTER) }
  scope :owners,  -> { where(access_level: OWNER) }

  delegate :name, :username, :email, to: :user, prefix: true
end
eos
26

27
  50.times do |i|
28 29 30 31 32
    user = User.all.sample

    PersonalSnippet.seed(:id, [{
      id: i,
      author_id: user.id,
Robert Speicher committed
33 34
      title: FFaker::Lorem.sentence(3),
      file_name:  FFaker::Internet.domain_word + '.rb',
Dmitriy Zaporozhets committed
35 36
      visibility_level: Gitlab::VisibilityLevel.values.sample,
      content: content,
37
    }])
Dmitriy Zaporozhets committed
38

39 40 41 42
    print('.')
  end
end