discourse_dev 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/discourse_dev/category.rb +8 -12
- data/lib/discourse_dev/config.rb +31 -0
- data/lib/discourse_dev/config.yml +2 -1
- data/lib/discourse_dev/group.rb +5 -10
- data/lib/discourse_dev/record.rb +21 -5
- data/lib/discourse_dev/tag.rb +20 -0
- data/lib/discourse_dev/tasks/dev.rake +1 -1
- data/lib/discourse_dev/tasks/populate.rake +5 -0
- data/lib/discourse_dev/topic.rb +24 -12
- data/lib/discourse_dev/user.rb +9 -7
- data/lib/discourse_dev/version.rb +1 -1
- data/lib/faker/discourse.rb +8 -0
- data/lib/faker/locales/en.yml +70 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b40ff76d084fee2f0eeef50807149a399e6c4bbdf256259dd23a6925d6bdeb7
|
4
|
+
data.tar.gz: 748af95af548a6d79ee21d96dd68688d5c554cb78391a416b63980805d4b25a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0914512344fa239f36c6ae42c4890ef4cad9fd991a234c5f8b301751a84a89633d20f035e64e526935031767842b27e6a36758e8ea982a3672e83e22c2826b4b'
|
7
|
+
data.tar.gz: d9cfa147a8616124232baef18d01203cd09b6c88a5d5c4c7b9a7527e4ef56d4f79c07c0d2ea13809907ba81b3cc38c4b669307d2a6ebef57b4d21364b96ba1b4
|
@@ -9,23 +9,16 @@ module DiscourseDev
|
|
9
9
|
|
10
10
|
def initialize(count = DEFAULT_COUNT)
|
11
11
|
super(::Category, count)
|
12
|
-
@existing_names = ::Category.pluck(:name)
|
13
12
|
@parent_category_ids = ::Category.where(parent_category_id: nil).pluck(:id)
|
14
|
-
@group_count = ::Group.count
|
15
13
|
end
|
16
14
|
|
17
15
|
def data
|
18
|
-
name = Faker::Discourse.category
|
16
|
+
name = Faker::Discourse.unique.category
|
19
17
|
parent_category_id = nil
|
20
18
|
|
21
|
-
while @existing_names.include? name
|
22
|
-
name = Faker::Discourse.category
|
23
|
-
end
|
24
|
-
|
25
|
-
@existing_names << name
|
26
|
-
|
27
19
|
if Faker::Boolean.boolean(true_ratio: 0.6)
|
28
|
-
|
20
|
+
offset = Faker::Number.between(from: 0, to: @parent_category_ids.count - 1)
|
21
|
+
parent_category_id = @parent_category_ids[offset]
|
29
22
|
@permissions = ::Category.find(parent_category_id).permissions_params.presence
|
30
23
|
else
|
31
24
|
@permissions = nil
|
@@ -45,8 +38,7 @@ module DiscourseDev
|
|
45
38
|
return { everyone: :full } if Faker::Boolean.boolean(true_ratio: 0.75)
|
46
39
|
|
47
40
|
permission = {}
|
48
|
-
|
49
|
-
group = ::Group.offset(offset).first
|
41
|
+
group = Group.random
|
50
42
|
permission[group.id] = Faker::Number.between(from: 1, to: 3)
|
51
43
|
|
52
44
|
permission
|
@@ -60,5 +52,9 @@ module DiscourseDev
|
|
60
52
|
@parent_category_ids << category.id if category.parent_category_id.blank?
|
61
53
|
end
|
62
54
|
end
|
55
|
+
|
56
|
+
def self.random
|
57
|
+
super(::Category)
|
58
|
+
end
|
63
59
|
end
|
64
60
|
end
|
data/lib/discourse_dev/config.rb
CHANGED
@@ -19,6 +19,8 @@ module DiscourseDev
|
|
19
19
|
|
20
20
|
def update!
|
21
21
|
update_site_settings
|
22
|
+
create_admin_user
|
23
|
+
set_seed
|
22
24
|
end
|
23
25
|
|
24
26
|
def update_site_settings
|
@@ -42,5 +44,34 @@ module DiscourseDev
|
|
42
44
|
|
43
45
|
SiteSetting.refresh!
|
44
46
|
end
|
47
|
+
|
48
|
+
def create_admin_user
|
49
|
+
puts "Creating default admin user account..."
|
50
|
+
|
51
|
+
settings = config["admin"]
|
52
|
+
|
53
|
+
if settings.present?
|
54
|
+
email = settings["email"]
|
55
|
+
|
56
|
+
admin = ::User.create!(
|
57
|
+
email: email,
|
58
|
+
username: settings["username"] || UserNameSuggester.suggest(email),
|
59
|
+
password: settings["password"]
|
60
|
+
)
|
61
|
+
admin.grant_admin!
|
62
|
+
if admin.trust_level < 1
|
63
|
+
admin.change_trust_level!(1)
|
64
|
+
end
|
65
|
+
admin.email_tokens.update_all confirmed: true
|
66
|
+
admin.activate
|
67
|
+
else
|
68
|
+
Rake::Task['admin:create'].invoke
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def set_seed
|
73
|
+
seed = config["seed"] || default_config["seed"] || 1
|
74
|
+
Faker::Config.random = Random.new(seed)
|
75
|
+
end
|
45
76
|
end
|
46
77
|
end
|
data/lib/discourse_dev/group.rb
CHANGED
@@ -11,20 +11,11 @@ module DiscourseDev
|
|
11
11
|
|
12
12
|
def initialize(count = DEFAULT_COUNT)
|
13
13
|
super(::Group, count)
|
14
|
-
@existing_names = ::Group.where(automatic: false).pluck(:name)
|
15
14
|
end
|
16
15
|
|
17
16
|
def data
|
18
|
-
name = Faker::Discourse.group
|
19
|
-
|
20
|
-
while @existing_names.include? name
|
21
|
-
name = Faker::Company.profession.gsub(" ", "-")
|
22
|
-
end
|
23
|
-
|
24
|
-
@existing_names << name
|
25
|
-
|
26
17
|
{
|
27
|
-
name:
|
18
|
+
name: Faker::Discourse.unique.group,
|
28
19
|
public_exit: Faker::Boolean.boolean,
|
29
20
|
public_admission: Faker::Boolean.boolean,
|
30
21
|
primary_group: Faker::Boolean.boolean
|
@@ -40,5 +31,9 @@ module DiscourseDev
|
|
40
31
|
end
|
41
32
|
end
|
42
33
|
end
|
34
|
+
|
35
|
+
def self.random
|
36
|
+
super(::Group)
|
37
|
+
end
|
43
38
|
end
|
44
39
|
end
|
data/lib/discourse_dev/record.rb
CHANGED
@@ -8,28 +8,44 @@ module DiscourseDev
|
|
8
8
|
class Record
|
9
9
|
DEFAULT_COUNT = 30.freeze
|
10
10
|
|
11
|
-
attr_reader :model, :type
|
11
|
+
attr_reader :model, :type
|
12
12
|
|
13
13
|
def initialize(model, count = DEFAULT_COUNT)
|
14
|
+
Faker::Discourse.unique.clear
|
14
15
|
@model = model
|
15
16
|
@type = model.to_s
|
16
17
|
@count = count
|
18
|
+
@index = nil
|
17
19
|
end
|
18
20
|
|
19
21
|
def create!
|
20
22
|
record = model.create!(data)
|
21
|
-
yield(record)
|
22
|
-
putc "."
|
23
|
+
yield(record) if block_given?
|
23
24
|
end
|
24
25
|
|
25
26
|
def populate!
|
26
|
-
puts "Creating #{count} sample #{type.downcase} records"
|
27
|
-
|
27
|
+
puts "Creating #{@count} sample #{type.downcase} records"
|
28
|
+
|
29
|
+
@count.times do |i|
|
30
|
+
@index = i
|
31
|
+
create!
|
32
|
+
putc "."
|
33
|
+
end
|
34
|
+
|
28
35
|
puts
|
29
36
|
end
|
30
37
|
|
38
|
+
def index
|
39
|
+
@index
|
40
|
+
end
|
41
|
+
|
31
42
|
def self.populate!
|
32
43
|
self.new.populate!
|
33
44
|
end
|
45
|
+
|
46
|
+
def self.random(model)
|
47
|
+
offset = Faker::Number.between(from: 0, to: model.count - 1)
|
48
|
+
model.offset(offset).first
|
49
|
+
end
|
34
50
|
end
|
35
51
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'discourse_dev/record'
|
4
|
+
require 'rails'
|
5
|
+
require 'faker'
|
6
|
+
|
7
|
+
module DiscourseDev
|
8
|
+
class Tag < Record
|
9
|
+
|
10
|
+
def initialize(count = DEFAULT_COUNT)
|
11
|
+
super(::Tag, count)
|
12
|
+
end
|
13
|
+
|
14
|
+
def data
|
15
|
+
{
|
16
|
+
name: Faker::Discourse.unique.tag,
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -12,7 +12,6 @@ task 'dev:reset' => ['db:load_config'] do |_, args|
|
|
12
12
|
|
13
13
|
Rake::Task['db:migrate:reset'].invoke
|
14
14
|
Rake::Task['dev:config'].invoke
|
15
|
-
Rake::Task['admin:create'].invoke
|
16
15
|
Rake::Task['dev:populate'].invoke
|
17
16
|
end
|
18
17
|
|
@@ -26,5 +25,6 @@ task 'dev:populate' => ['db:load_config'] do |_, args|
|
|
26
25
|
Rake::Task['groups:populate'].invoke
|
27
26
|
Rake::Task['users:populate'].invoke
|
28
27
|
Rake::Task['categories:populate'].invoke
|
28
|
+
Rake::Task['tags:populate'].invoke
|
29
29
|
Rake::Task['topics:populate'].invoke
|
30
30
|
end
|
@@ -15,6 +15,11 @@ task 'categories:populate' => ['db:load_config'] do |_, args|
|
|
15
15
|
DiscourseDev::Category.populate!
|
16
16
|
end
|
17
17
|
|
18
|
+
desc 'Creates sample tags'
|
19
|
+
task 'tags:populate' => ['db:load_config'] do |_, args|
|
20
|
+
DiscourseDev::Tag.populate!
|
21
|
+
end
|
22
|
+
|
18
23
|
desc 'Creates sample topics'
|
19
24
|
task 'topics:populate' => ['db:load_config'] do |_, args|
|
20
25
|
DiscourseDev::Topic.populate!
|
data/lib/discourse_dev/topic.rb
CHANGED
@@ -8,38 +8,50 @@ module DiscourseDev
|
|
8
8
|
|
9
9
|
def initialize(count = DEFAULT_COUNT)
|
10
10
|
super(::Topic, count)
|
11
|
-
@category_ids = ::Category.pluck(:id)
|
12
|
-
@user_count = ::User.count
|
13
11
|
end
|
14
12
|
|
15
13
|
def data
|
16
14
|
{
|
17
|
-
title:
|
15
|
+
title: title[0, SiteSetting.max_topic_title_length],
|
18
16
|
raw: Faker::Markdown.sandwich(sentences: 5),
|
19
|
-
category: @
|
17
|
+
category: @category.id,
|
20
18
|
tags: tags,
|
21
19
|
topic_opts: { custom_fields: { dev_sample: true } },
|
22
20
|
skip_validations: true
|
23
21
|
}
|
24
22
|
end
|
25
23
|
|
24
|
+
def title
|
25
|
+
if index <= I18n.t("faker.discourse.topics").count
|
26
|
+
Faker::Discourse.unique.topic
|
27
|
+
else
|
28
|
+
Faker::Lorem.unique.sentence(word_count: 3, supplemental: true, random_words_to_add: 4).chomp(".")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
26
32
|
def tags
|
27
33
|
@tags = []
|
28
|
-
keys = ["model", "make", "manufacture"]
|
29
34
|
|
30
|
-
Faker::Number.between(from: 0, to: 3).times do
|
31
|
-
@tags << Faker::
|
35
|
+
Faker::Number.between(from: 0, to: 3).times do
|
36
|
+
@tags << Faker::Discourse.tag
|
32
37
|
end
|
33
38
|
|
34
|
-
@tags
|
39
|
+
@tags.uniq
|
35
40
|
end
|
36
41
|
|
37
42
|
def create!
|
38
|
-
|
39
|
-
user = ::User.offset(offset).first
|
40
|
-
|
43
|
+
@category = Category.random
|
41
44
|
PostCreator.new(user, data).create!
|
42
|
-
|
45
|
+
end
|
46
|
+
|
47
|
+
def user
|
48
|
+
return User.random if @category.groups.blank?
|
49
|
+
|
50
|
+
group_ids = @category.groups.pluck(:id)
|
51
|
+
user_ids = ::GroupUser.where(group_id: group_ids).pluck(:user_id)
|
52
|
+
user_count = user_ids.count
|
53
|
+
position = Faker::Number.between(from: 0, to: user_count - 1)
|
54
|
+
::User.find(user_ids[position] || Discourse::SYSTEM_USER_ID)
|
43
55
|
end
|
44
56
|
end
|
45
57
|
end
|
data/lib/discourse_dev/user.rb
CHANGED
@@ -9,14 +9,12 @@ module DiscourseDev
|
|
9
9
|
|
10
10
|
def initialize(count = DEFAULT_COUNT)
|
11
11
|
super(::User, count)
|
12
|
-
@groups = ::Group.where(automatic: false)
|
13
|
-
@group_count = @groups.count
|
14
12
|
end
|
15
13
|
|
16
14
|
def data
|
17
|
-
name = Faker::Name.name
|
18
|
-
email = Faker::Internet.email(name: name)
|
19
|
-
username = Faker::Internet.username(specifier: name)[0, SiteSetting.max_username_length]
|
15
|
+
name = Faker::Name.unique.name
|
16
|
+
email = Faker::Internet.unique.email(name: name)
|
17
|
+
username = Faker::Internet.unique.username(specifier: name)[0, SiteSetting.max_username_length]
|
20
18
|
username_lower = username.downcase
|
21
19
|
|
22
20
|
{
|
@@ -31,13 +29,17 @@ module DiscourseDev
|
|
31
29
|
|
32
30
|
def create!
|
33
31
|
super do |user|
|
32
|
+
user.activate
|
34
33
|
Faker::Number.between(from: 0, to: 2).times do
|
35
|
-
|
36
|
-
group = @groups.offset(offset).first
|
34
|
+
group = Group.random
|
37
35
|
|
38
36
|
group.add(user)
|
39
37
|
end
|
40
38
|
end
|
41
39
|
end
|
40
|
+
|
41
|
+
def self.random
|
42
|
+
super(::User)
|
43
|
+
end
|
42
44
|
end
|
43
45
|
end
|
data/lib/faker/discourse.rb
CHANGED
@@ -6,6 +6,10 @@ module Faker
|
|
6
6
|
class Discourse < Base
|
7
7
|
class << self
|
8
8
|
|
9
|
+
def tag
|
10
|
+
fetch('discourse.tags')
|
11
|
+
end
|
12
|
+
|
9
13
|
def category
|
10
14
|
fetch('discourse.categories')
|
11
15
|
end
|
@@ -13,6 +17,10 @@ module Faker
|
|
13
17
|
def group
|
14
18
|
fetch('discourse.groups')
|
15
19
|
end
|
20
|
+
|
21
|
+
def topic
|
22
|
+
fetch('discourse.topics')
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
18
26
|
end
|
data/lib/faker/locales/en.yml
CHANGED
@@ -62,3 +62,73 @@ en:
|
|
62
62
|
- subscribers
|
63
63
|
- creators
|
64
64
|
- translators
|
65
|
+
- editors
|
66
|
+
- developers
|
67
|
+
- publishers
|
68
|
+
- leaders
|
69
|
+
- advertisers
|
70
|
+
- early-birds
|
71
|
+
- partners
|
72
|
+
topics:
|
73
|
+
- Whoa. Check out this crazy paper artwork
|
74
|
+
- What’s the coolest thing you have worked on?
|
75
|
+
- A bear, however hard he tries, grows tubby without exercise
|
76
|
+
- Impressions Games City Builders
|
77
|
+
- Recommended reading for Community and FOSS enthusiasts
|
78
|
+
- Robots are taking our jobs!
|
79
|
+
- Modernizing the antiquated boxing scoring system
|
80
|
+
- Death by poisonous and electric watermelon
|
81
|
+
- D&D Gallery - Prey for Smiley Bob play session [with terrain]
|
82
|
+
- Why is uninhabited land in the US so closed off?
|
83
|
+
- The Room Appreciation Topic
|
84
|
+
- Recommend a great YouTube video
|
85
|
+
- Favorite TV show scene?
|
86
|
+
- Is the Second Amendment still relevant today?
|
87
|
+
- What methods/books did you use to learn Ruby?
|
88
|
+
- What is your favorite TED Video
|
89
|
+
- MLP:FIM Season 3 (spoilers ahoy!)
|
90
|
+
- Do you use a mobile device for ALL your work? Tell me how!
|
91
|
+
- What’s your all-time favorite movie scene?
|
92
|
+
- Enjoyable children’s shows for adults
|
93
|
+
- Totally amped about the 80s
|
94
|
+
- Do microwave ovens kill bacteria?
|
95
|
+
- Most inspirational movie you have ever seen?
|
96
|
+
- Catching all 151 in 2 hours
|
97
|
+
- Charlie The Unicorn 4
|
98
|
+
- Video Games for Pre-Teens?
|
99
|
+
- Online learning
|
100
|
+
- Mark of the Ninja
|
101
|
+
- Funniest thing you’ve seen today?
|
102
|
+
- Coolest thing you have seen today
|
103
|
+
- Share your Hallowe’en pictures
|
104
|
+
tags:
|
105
|
+
- art
|
106
|
+
- code
|
107
|
+
- official
|
108
|
+
- feedback
|
109
|
+
- fun
|
110
|
+
- dev
|
111
|
+
- design
|
112
|
+
- test
|
113
|
+
- blog
|
114
|
+
- cloud
|
115
|
+
- tv
|
116
|
+
- movies
|
117
|
+
- review
|
118
|
+
- news
|
119
|
+
- link
|
120
|
+
- video
|
121
|
+
- photos
|
122
|
+
- lead
|
123
|
+
- mobile
|
124
|
+
- music
|
125
|
+
- release
|
126
|
+
- notes
|
127
|
+
- todo
|
128
|
+
- duplicate
|
129
|
+
- praise
|
130
|
+
- faq
|
131
|
+
- job-application
|
132
|
+
- rfc
|
133
|
+
- email
|
134
|
+
- wiki
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discourse_dev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinoth Kannan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/discourse_dev/group.rb
|
74
74
|
- lib/discourse_dev/railtie.rb
|
75
75
|
- lib/discourse_dev/record.rb
|
76
|
+
- lib/discourse_dev/tag.rb
|
76
77
|
- lib/discourse_dev/tasks/dev.rake
|
77
78
|
- lib/discourse_dev/tasks/populate.rake
|
78
79
|
- lib/discourse_dev/topic.rb
|