discourse_dev 0.0.1 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/config/routes.rb +5 -0
- data/discourse_dev.gemspec +3 -3
- data/lib/discourse_dev.rb +2 -1
- data/lib/discourse_dev/category.rb +39 -8
- data/lib/discourse_dev/config.rb +77 -0
- data/lib/discourse_dev/config.yml +4 -0
- data/lib/discourse_dev/engine.rb +5 -0
- data/lib/discourse_dev/group.rb +39 -0
- data/lib/discourse_dev/post.rb +88 -0
- data/lib/discourse_dev/record.rb +34 -6
- data/lib/discourse_dev/tag.rb +20 -0
- data/lib/discourse_dev/tasks/dev.rake +22 -1
- data/lib/discourse_dev/tasks/populate.rake +20 -0
- data/lib/discourse_dev/topic.rb +46 -8
- data/lib/discourse_dev/user.rb +19 -3
- data/lib/discourse_dev/version.rb +1 -1
- data/lib/faker/discourse.rb +14 -0
- data/lib/faker/locales/en.yml +114 -1
- metadata +15 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7cf21a4b27818d1c6c02ce68b6f3fec67fec0b5c7ce070203c4db6bec1e1e72
|
4
|
+
data.tar.gz: 7bcd79d041f43cf6ed4843c2a3fe9f20bba915682516586064a0356acb5246df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f964c9b509c0e219aff2161e49fc7d468861fefc85e6ce0a68250fbdfd2ca6d06d32ee7bf0b153ae99eb1dc9be0a1c4694752ec60ee7b0c71143d0283ebd5c15
|
7
|
+
data.tar.gz: 207d473198144df8997a72eb9ab6f9070b24b924c6600be546d6bef2aeb26076c633b781caba9fb69590a2c99807004b0c19a49026f588d2cc7ae0470fa391b5
|
data/README.md
CHANGED
@@ -1 +1,15 @@
|
|
1
1
|
# Discourse Dev
|
2
|
+
|
3
|
+

|
4
|
+
|
5
|
+
Rake helper tasks for Discourse developers.
|
6
|
+
|
7
|
+
## Available Rake Tasks
|
8
|
+
|
9
|
+
* `dev:reset`
|
10
|
+
* `dev:config`
|
11
|
+
* `dev:populate`
|
12
|
+
* `groups:populate`
|
13
|
+
* `users:populate`
|
14
|
+
* `categories:populate`
|
15
|
+
* `topics:populate`
|
data/config/routes.rb
ADDED
data/discourse_dev.gemspec
CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ["Vinoth Kannan"]
|
11
11
|
spec.email = ["svkn.87@gmail.com"]
|
12
12
|
|
13
|
-
spec.summary = %q{Rake helper for Discourse developers}
|
14
|
-
spec.description = %q{Rake helper for Discourse developers}
|
13
|
+
spec.summary = %q{Rake helper tasks for Discourse developers}
|
14
|
+
spec.description = %q{Rake helper tasks for Discourse developers}
|
15
15
|
spec.homepage = "https://github.com/discourse/discourse_dev"
|
16
16
|
spec.license = "MIT"
|
17
17
|
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_runtime_dependency "faker", "~> 2.16"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 2.0"
|
24
|
-
spec.add_development_dependency "rake", "
|
24
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
25
25
|
|
26
26
|
spec.required_ruby_version = '>= 2.6.0'
|
27
27
|
end
|
data/lib/discourse_dev.rb
CHANGED
@@ -8,5 +8,6 @@ I18n.load_path += Dir[File.join(__dir__, 'faker', 'locales', '**/*.yml')]
|
|
8
8
|
I18n.reload! if I18n.backend.initialized?
|
9
9
|
|
10
10
|
module DiscourseDev
|
11
|
-
require 'discourse_dev/railtie'
|
11
|
+
require 'discourse_dev/railtie'
|
12
|
+
require 'discourse_dev/engine'
|
12
13
|
end
|
@@ -9,21 +9,52 @@ module DiscourseDev
|
|
9
9
|
|
10
10
|
def initialize(count = DEFAULT_COUNT)
|
11
11
|
super(::Category, count)
|
12
|
+
@parent_category_ids = ::Category.where(parent_category_id: nil).pluck(:id)
|
12
13
|
end
|
13
14
|
|
14
15
|
def data
|
15
|
-
name = Faker::
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
name = Faker::Discourse.unique.category
|
17
|
+
parent_category_id = nil
|
18
|
+
|
19
|
+
if Faker::Boolean.boolean(true_ratio: 0.6)
|
20
|
+
offset = Faker::Number.between(from: 0, to: @parent_category_ids.count - 1)
|
21
|
+
parent_category_id = @parent_category_ids[offset]
|
22
|
+
@permissions = ::Category.find(parent_category_id).permissions_params.presence
|
23
|
+
else
|
24
|
+
@permissions = nil
|
25
|
+
end
|
19
26
|
|
20
27
|
{
|
21
28
|
name: name,
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
29
|
+
description: Faker::Lorem.paragraph,
|
30
|
+
user_id: ::Discourse::SYSTEM_USER_ID,
|
31
|
+
color: Faker::Color.hex_color.last(6),
|
32
|
+
parent_category_id: parent_category_id
|
26
33
|
}
|
27
34
|
end
|
35
|
+
|
36
|
+
def permissions
|
37
|
+
return @permissions if @permissions.present?
|
38
|
+
return { everyone: :full } if Faker::Boolean.boolean(true_ratio: 0.75)
|
39
|
+
|
40
|
+
permission = {}
|
41
|
+
group = Group.random
|
42
|
+
permission[group.id] = Faker::Number.between(from: 1, to: 3)
|
43
|
+
|
44
|
+
permission
|
45
|
+
end
|
46
|
+
|
47
|
+
def create!
|
48
|
+
super do |category|
|
49
|
+
category.set_permissions(permissions)
|
50
|
+
category.save!
|
51
|
+
|
52
|
+
@parent_category_ids << category.id if category.parent_category_id.blank?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.random
|
57
|
+
super(::Category)
|
58
|
+
end
|
28
59
|
end
|
29
60
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
module DiscourseDev
|
6
|
+
class Config
|
7
|
+
attr_reader :config, :default_config
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@default_config = YAML.load_file(File.join(File.expand_path(__dir__), "config.yml"))
|
11
|
+
file_path = File.join(Rails.root, "config", "dev.yml")
|
12
|
+
|
13
|
+
if File.exists?(file_path)
|
14
|
+
@config = YAML.load_file(file_path)
|
15
|
+
else
|
16
|
+
@config = {}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def update!
|
21
|
+
update_site_settings
|
22
|
+
create_admin_user
|
23
|
+
set_seed
|
24
|
+
end
|
25
|
+
|
26
|
+
def update_site_settings
|
27
|
+
puts "Updating site settings..."
|
28
|
+
|
29
|
+
site_settings = config["site_settings"] || {}
|
30
|
+
|
31
|
+
site_settings.each do |key, value|
|
32
|
+
puts "#{key} = #{value}"
|
33
|
+
SiteSetting.set(key, value)
|
34
|
+
end
|
35
|
+
|
36
|
+
keys = site_settings.keys
|
37
|
+
|
38
|
+
default_config["site_settings"].each do |key, value|
|
39
|
+
next if keys.include?(key)
|
40
|
+
|
41
|
+
puts "#{key} = #{value}"
|
42
|
+
SiteSetting.set(key, value)
|
43
|
+
end
|
44
|
+
|
45
|
+
SiteSetting.refresh!
|
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
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'discourse_dev/record'
|
4
|
+
require 'rails'
|
5
|
+
require 'faker'
|
6
|
+
|
7
|
+
module DiscourseDev
|
8
|
+
class Group < Record
|
9
|
+
|
10
|
+
DEFAULT_COUNT = 15.freeze
|
11
|
+
|
12
|
+
def initialize(count = DEFAULT_COUNT)
|
13
|
+
super(::Group, count)
|
14
|
+
end
|
15
|
+
|
16
|
+
def data
|
17
|
+
{
|
18
|
+
name: Faker::Discourse.unique.group,
|
19
|
+
public_exit: Faker::Boolean.boolean,
|
20
|
+
public_admission: Faker::Boolean.boolean,
|
21
|
+
primary_group: Faker::Boolean.boolean
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def create!
|
26
|
+
super do |group|
|
27
|
+
if Faker::Boolean.boolean
|
28
|
+
group.add_owner(::Discourse.system_user)
|
29
|
+
group.allow_membership_requests = true
|
30
|
+
group.save!
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.random
|
36
|
+
super(::Group)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'discourse_dev/record'
|
4
|
+
require 'faker'
|
5
|
+
|
6
|
+
module DiscourseDev
|
7
|
+
class Post < Record
|
8
|
+
|
9
|
+
attr_reader :topic
|
10
|
+
|
11
|
+
def initialize(topic, count = DEFAULT_COUNT)
|
12
|
+
super(::Post, count)
|
13
|
+
@topic = topic
|
14
|
+
|
15
|
+
category = topic.category
|
16
|
+
unless category.groups.blank?
|
17
|
+
group_ids = category.groups.pluck(:id)
|
18
|
+
@user_ids = ::GroupUser.where(group_id: group_ids).pluck(:user_id)
|
19
|
+
@user_count = @user_ids.count
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def data
|
24
|
+
{
|
25
|
+
topic_id: topic.id,
|
26
|
+
raw: Faker::Markdown.sandwich(sentences: 5),
|
27
|
+
skip_validations: true
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def create!
|
32
|
+
begin
|
33
|
+
PostCreator.new(user, data).create!
|
34
|
+
rescue ActiveRecord::RecordNotSaved => e
|
35
|
+
puts e
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def user
|
40
|
+
return User.random if topic.category.groups.blank?
|
41
|
+
return Discourse.system_user if @user_ids.blank?
|
42
|
+
|
43
|
+
position = Faker::Number.between(from: 0, to: @user_count - 1)
|
44
|
+
::User.find(@user_ids[position])
|
45
|
+
end
|
46
|
+
|
47
|
+
def populate!
|
48
|
+
@count.times do |i|
|
49
|
+
@index = i
|
50
|
+
create!
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.add_replies!(args)
|
55
|
+
if !args[:topic_id]
|
56
|
+
puts "Topic ID is required. Aborting."
|
57
|
+
return
|
58
|
+
end
|
59
|
+
|
60
|
+
if !::Topic.find_by_id(args[:topic_id])
|
61
|
+
puts "Topic ID does not match topic in DB, aborting."
|
62
|
+
return
|
63
|
+
end
|
64
|
+
|
65
|
+
topic = ::Topic.find_by_id(args[:topic_id])
|
66
|
+
count = args[:count] ? args[:count].to_i : 50
|
67
|
+
|
68
|
+
puts "Creating #{count} replies in '#{topic.title}'"
|
69
|
+
|
70
|
+
count.times do |i|
|
71
|
+
@index = i
|
72
|
+
begin
|
73
|
+
reply = {
|
74
|
+
topic_id: topic.id,
|
75
|
+
raw: Faker::Markdown.sandwich(sentences: 5),
|
76
|
+
skip_validations: true
|
77
|
+
}
|
78
|
+
PostCreator.new(User.random, reply).create!
|
79
|
+
rescue ActiveRecord::RecordNotSaved => e
|
80
|
+
puts e
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
puts "Done!"
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
data/lib/discourse_dev/record.rb
CHANGED
@@ -11,28 +11,56 @@ module DiscourseDev
|
|
11
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
|
-
model.create!(data)
|
21
|
-
|
22
|
+
record = model.create!(data)
|
23
|
+
yield(record) if block_given?
|
22
24
|
end
|
23
25
|
|
24
26
|
def populate!
|
25
|
-
|
26
|
-
|
27
|
+
if current_count >= @count
|
28
|
+
puts "Already have #{@count}+ #{type.downcase} records."
|
29
|
+
|
30
|
+
Rake.application.top_level_tasks.each do |task_name|
|
31
|
+
Rake::Task[task_name].reenable
|
32
|
+
end
|
33
|
+
|
34
|
+
Rake::Task['dev:repopulate'].invoke
|
35
|
+
return
|
36
|
+
end
|
37
|
+
|
38
|
+
puts "Creating #{@count} sample #{type.downcase} records"
|
39
|
+
|
40
|
+
@count.times do |i|
|
41
|
+
@index = i
|
42
|
+
create!
|
43
|
+
putc "."
|
44
|
+
end
|
45
|
+
|
27
46
|
puts
|
28
47
|
end
|
29
48
|
|
30
|
-
def
|
31
|
-
@
|
49
|
+
def index
|
50
|
+
@index
|
51
|
+
end
|
52
|
+
|
53
|
+
def current_count
|
54
|
+
model.count
|
32
55
|
end
|
33
56
|
|
34
57
|
def self.populate!
|
35
58
|
self.new.populate!
|
36
59
|
end
|
60
|
+
|
61
|
+
def self.random(model)
|
62
|
+
offset = Faker::Number.between(from: 0, to: model.count - 1)
|
63
|
+
model.offset(offset).first
|
64
|
+
end
|
37
65
|
end
|
38
66
|
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
|
@@ -11,12 +11,33 @@ task 'dev:reset' => ['db:load_config'] do |_, args|
|
|
11
11
|
check_environment!
|
12
12
|
|
13
13
|
Rake::Task['db:migrate:reset'].invoke
|
14
|
-
Rake::Task['
|
14
|
+
Rake::Task['dev:config'].invoke
|
15
15
|
Rake::Task['dev:populate'].invoke
|
16
16
|
end
|
17
17
|
|
18
|
+
desc 'Initialize development environment'
|
19
|
+
task 'dev:config' => ['db:load_config'] do |_, args|
|
20
|
+
DiscourseDev::Config.new.update!
|
21
|
+
end
|
22
|
+
|
18
23
|
desc 'Populate sample content for development environment'
|
19
24
|
task 'dev:populate' => ['db:load_config'] do |_, args|
|
25
|
+
Rake::Task['groups:populate'].invoke
|
20
26
|
Rake::Task['users:populate'].invoke
|
27
|
+
Rake::Task['categories:populate'].invoke
|
28
|
+
Rake::Task['tags:populate'].invoke
|
21
29
|
Rake::Task['topics:populate'].invoke
|
22
30
|
end
|
31
|
+
|
32
|
+
desc 'Repopulate sample datas in development environment'
|
33
|
+
task 'dev:repopulate' => ['db:load_config'] do |_, args|
|
34
|
+
require 'highline/import'
|
35
|
+
|
36
|
+
answer = ask("Do you want to repopulate the database with fresh data? It will recreate DBs and run migration from scratch before generating all the samples. (Y/n) ")
|
37
|
+
|
38
|
+
if (answer == "" || answer.downcase == 'y')
|
39
|
+
Rake::Task['dev:reset'].invoke
|
40
|
+
else
|
41
|
+
puts "You can run `dev:reset` rake task to do this repopulate action anytime."
|
42
|
+
end
|
43
|
+
end
|
@@ -1,11 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
desc 'Creates sample categories'
|
4
|
+
task 'groups:populate' => ['db:load_config'] do |_, args|
|
5
|
+
DiscourseDev::Group.populate!
|
6
|
+
end
|
7
|
+
|
3
8
|
desc 'Creates sample user accounts'
|
4
9
|
task 'users:populate' => ['db:load_config'] do |_, args|
|
5
10
|
DiscourseDev::User.populate!
|
6
11
|
end
|
7
12
|
|
13
|
+
desc 'Creates sample categories'
|
14
|
+
task 'categories:populate' => ['db:load_config'] do |_, args|
|
15
|
+
DiscourseDev::Category.populate!
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Creates sample tags'
|
19
|
+
task 'tags:populate' => ['db:load_config'] do |_, args|
|
20
|
+
DiscourseDev::Tag.populate!
|
21
|
+
end
|
22
|
+
|
8
23
|
desc 'Creates sample topics'
|
9
24
|
task 'topics:populate' => ['db:load_config'] do |_, args|
|
10
25
|
DiscourseDev::Topic.populate!
|
11
26
|
end
|
27
|
+
|
28
|
+
desc 'Add replies to a topic'
|
29
|
+
task 'replies:populate', [:topic_id, :count] => ['db:load_config'] do |_, args|
|
30
|
+
DiscourseDev::Post.add_replies!(args)
|
31
|
+
end
|
data/lib/discourse_dev/topic.rb
CHANGED
@@ -8,26 +8,64 @@ 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
|
-
|
17
|
+
category: @category.id,
|
18
|
+
tags: tags,
|
20
19
|
topic_opts: { custom_fields: { dev_sample: true } },
|
21
20
|
skip_validations: true
|
22
21
|
}
|
23
22
|
end
|
24
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
|
+
|
32
|
+
def tags
|
33
|
+
@tags = []
|
34
|
+
|
35
|
+
Faker::Number.between(from: 0, to: 3).times do
|
36
|
+
@tags << Faker::Discourse.tag
|
37
|
+
end
|
38
|
+
|
39
|
+
@tags.uniq
|
40
|
+
end
|
41
|
+
|
25
42
|
def create!
|
26
|
-
|
27
|
-
|
43
|
+
@category = Category.random
|
44
|
+
topic = data
|
45
|
+
post = PostCreator.new(user, topic).create!
|
46
|
+
|
47
|
+
if topic[:title] == "Coolest thing you have seen today"
|
48
|
+
reply_count = 99
|
49
|
+
else
|
50
|
+
reply_count = Faker::Number.between(from: 0, to: 12)
|
51
|
+
end
|
52
|
+
|
53
|
+
Post.new(post.topic, reply_count).populate!
|
54
|
+
end
|
55
|
+
|
56
|
+
def user
|
57
|
+
return User.random if @category.groups.blank?
|
58
|
+
|
59
|
+
group_ids = @category.groups.pluck(:id)
|
60
|
+
user_ids = ::GroupUser.where(group_id: group_ids).pluck(:user_id)
|
61
|
+
user_count = user_ids.count
|
62
|
+
position = Faker::Number.between(from: 0, to: user_count - 1)
|
63
|
+
::User.find(user_ids[position] || Discourse::SYSTEM_USER_ID)
|
64
|
+
end
|
28
65
|
|
29
|
-
|
30
|
-
|
66
|
+
def current_count
|
67
|
+
category_definition_topic_ids = ::Category.pluck(:topic_id)
|
68
|
+
::Topic.where(archetype: :regular).where.not(id: category_definition_topic_ids).count
|
31
69
|
end
|
32
70
|
end
|
33
71
|
end
|
data/lib/discourse_dev/user.rb
CHANGED
@@ -12,9 +12,9 @@ module DiscourseDev
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def data
|
15
|
-
name = Faker::Name.name
|
16
|
-
email = Faker::Internet.email(name: name)
|
17
|
-
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]
|
18
18
|
username_lower = username.downcase
|
19
19
|
|
20
20
|
{
|
@@ -22,8 +22,24 @@ module DiscourseDev
|
|
22
22
|
email: email,
|
23
23
|
username: username,
|
24
24
|
username_lower: username_lower,
|
25
|
+
moderator: Faker::Boolean.boolean(true_ratio: 0.1),
|
25
26
|
trust_level: Faker::Number.between(from: 1, to: 4)
|
26
27
|
}
|
27
28
|
end
|
29
|
+
|
30
|
+
def create!
|
31
|
+
super do |user|
|
32
|
+
user.activate
|
33
|
+
Faker::Number.between(from: 0, to: 2).times do
|
34
|
+
group = Group.random
|
35
|
+
|
36
|
+
group.add(user)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.random
|
42
|
+
super(::User)
|
43
|
+
end
|
28
44
|
end
|
29
45
|
end
|
data/lib/faker/discourse.rb
CHANGED
@@ -1,12 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'faker'
|
4
|
+
|
3
5
|
module Faker
|
4
6
|
class Discourse < Base
|
5
7
|
class << self
|
6
8
|
|
9
|
+
def tag
|
10
|
+
fetch('discourse.tags')
|
11
|
+
end
|
12
|
+
|
7
13
|
def category
|
8
14
|
fetch('discourse.categories')
|
9
15
|
end
|
16
|
+
|
17
|
+
def group
|
18
|
+
fetch('discourse.groups')
|
19
|
+
end
|
20
|
+
|
21
|
+
def topic
|
22
|
+
fetch('discourse.topics')
|
23
|
+
end
|
10
24
|
end
|
11
25
|
end
|
12
26
|
end
|
data/lib/faker/locales/en.yml
CHANGED
@@ -4,7 +4,6 @@ en:
|
|
4
4
|
categories:
|
5
5
|
- movies
|
6
6
|
- tech
|
7
|
-
- general
|
8
7
|
- videos
|
9
8
|
- gaming
|
10
9
|
- sports
|
@@ -19,3 +18,117 @@ en:
|
|
19
18
|
- announcements
|
20
19
|
- bug
|
21
20
|
- community
|
21
|
+
- Events
|
22
|
+
- Education
|
23
|
+
- General Discussion
|
24
|
+
- News
|
25
|
+
- Suggestions
|
26
|
+
- Introduce Yourself
|
27
|
+
- Frequently Asked Questions
|
28
|
+
- Off-Topic
|
29
|
+
- Expert Advice
|
30
|
+
- Home and Living
|
31
|
+
- Babies and Kids
|
32
|
+
- International
|
33
|
+
- Partners
|
34
|
+
- Getting Started
|
35
|
+
- Creator's Corner
|
36
|
+
- Feature Requests
|
37
|
+
- Other Languages
|
38
|
+
- Travelling
|
39
|
+
- Recipes
|
40
|
+
- Newbies
|
41
|
+
- Covid-19
|
42
|
+
- Resources
|
43
|
+
- Docs
|
44
|
+
- Publishing
|
45
|
+
- Marketplace
|
46
|
+
- Community Guidelines
|
47
|
+
- Archived
|
48
|
+
- Meta
|
49
|
+
- Software and Operating Systems
|
50
|
+
- Arts & Media
|
51
|
+
- Science and Engineering
|
52
|
+
- Quizzes and Challenges
|
53
|
+
- Politics
|
54
|
+
- Roadmap
|
55
|
+
- Share Tips and Tricks
|
56
|
+
groups:
|
57
|
+
- team
|
58
|
+
- designers
|
59
|
+
- authors
|
60
|
+
- contributors
|
61
|
+
- customers
|
62
|
+
- subscribers
|
63
|
+
- creators
|
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.7
|
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-
|
11
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|
@@ -42,17 +42,17 @@ dependencies:
|
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 12.3.3
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
description: Rake helper for Discourse developers
|
54
|
+
version: 12.3.3
|
55
|
+
description: Rake helper tasks for Discourse developers
|
56
56
|
email:
|
57
57
|
- svkn.87@gmail.com
|
58
58
|
executables: []
|
@@ -65,11 +65,18 @@ files:
|
|
65
65
|
- LICENSE.txt
|
66
66
|
- README.md
|
67
67
|
- Rakefile
|
68
|
+
- config/routes.rb
|
68
69
|
- discourse_dev.gemspec
|
69
70
|
- lib/discourse_dev.rb
|
70
71
|
- lib/discourse_dev/category.rb
|
72
|
+
- lib/discourse_dev/config.rb
|
73
|
+
- lib/discourse_dev/config.yml
|
74
|
+
- lib/discourse_dev/engine.rb
|
75
|
+
- lib/discourse_dev/group.rb
|
76
|
+
- lib/discourse_dev/post.rb
|
71
77
|
- lib/discourse_dev/railtie.rb
|
72
78
|
- lib/discourse_dev/record.rb
|
79
|
+
- lib/discourse_dev/tag.rb
|
73
80
|
- lib/discourse_dev/tasks/dev.rake
|
74
81
|
- lib/discourse_dev/tasks/populate.rake
|
75
82
|
- lib/discourse_dev/topic.rb
|
@@ -99,5 +106,5 @@ requirements: []
|
|
99
106
|
rubygems_version: 3.0.3
|
100
107
|
signing_key:
|
101
108
|
specification_version: 4
|
102
|
-
summary: Rake helper for Discourse developers
|
109
|
+
summary: Rake helper tasks for Discourse developers
|
103
110
|
test_files: []
|