Class: DiscourseDev::Group

Inherits:
Record
  • Object
show all
Defined in:
lib/discourse_dev/group.rb

Constant Summary collapse

DEFAULT_COUNT =
15.freeze

Instance Attribute Summary

Attributes inherited from Record

#count, #model, #type

Instance Method Summary collapse

Methods inherited from Record

#populate!, populate!

Constructor Details

#initialize(count = DEFAULT_COUNT) ⇒ Group



12
13
14
15
# File 'lib/discourse_dev/group.rb', line 12

def initialize(count = DEFAULT_COUNT)
  super(::Group, count)
  @existing_names = ::Group.where(automatic: false).pluck(:name)
end

Instance Method Details

#create!Object



34
35
36
37
38
39
40
41
42
# File 'lib/discourse_dev/group.rb', line 34

def create!
  super do |group|
    if Faker::Boolean.boolean
      group.add_owner(::Discourse.system_user)
      group.allow_membership_requests = true
      group.save!
    end
  end
end

#dataObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/discourse_dev/group.rb', line 17

def data
  name = Faker::Discourse.group

  while @existing_names.include? name
    name = Faker::Company.profession.gsub(" ", "-")
  end

  @existing_names << name

  {
    name: name,
    public_exit: Faker::Boolean.boolean,
    public_admission: Faker::Boolean.boolean,
    primary_group: Faker::Boolean.boolean
  }
end