discourse_dev 0.0.2 → 0.0.8
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 +10 -0
- data/config/routes.rb +5 -0
- data/lib/discourse_dev.rb +20 -1
- data/lib/discourse_dev/category.rb +8 -12
- data/lib/discourse_dev/config.rb +40 -0
- data/lib/discourse_dev/config.yml +4 -1
- data/lib/discourse_dev/engine.rb +5 -0
- data/lib/discourse_dev/group.rb +7 -11
- data/lib/discourse_dev/post.rb +104 -0
- data/lib/discourse_dev/record.rb +38 -5
- data/lib/discourse_dev/tag.rb +20 -0
- data/lib/discourse_dev/tasks/dev.rake +19 -2
- data/lib/discourse_dev/tasks/populate.rake +10 -0
- data/lib/discourse_dev/topic.rb +69 -9
- data/lib/discourse_dev/user.rb +11 -8
- data/lib/discourse_dev/version.rb +1 -1
- data/lib/faker/discourse.rb +10 -0
- data/lib/faker/locales/en.yml +70 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78ead97c8c37d30f88d98a6e95a720647d73e564aa39872599488e3bcfc6fb0d
|
4
|
+
data.tar.gz: eb83d5121929c789d926d69fc54c9d79f25d32f1f1177b524212699e5a0e901d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcd86419248de6cfe03d3e09e9d3eb7f7c0e67ba460cd7a23dd49eeb605b8ad66db5055b1dbb6333588aac6a4ee00c08b9cd8d7113571bc904d888238bac8fe5
|
7
|
+
data.tar.gz: 1e965d65532c23d0c8f5c0afd0e2d56f73b5d954219611416fb34bad0c8425f191caf47085122d7cb13234bdefed7da33ec7bcb6a000580d50ef44eb36353f09
|
data/README.md
CHANGED
@@ -3,3 +3,13 @@
|
|
3
3
|

|
4
4
|
|
5
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/lib/discourse_dev.rb
CHANGED
@@ -8,5 +8,24 @@ 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'
|
13
|
+
|
14
|
+
def self.config
|
15
|
+
@config ||= Config.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require "active_record/database_configurations"
|
20
|
+
|
21
|
+
ActiveRecord::Tasks::DatabaseTasks.module_eval do
|
22
|
+
alias_method :rails_each_current_configuration, :each_current_configuration
|
23
|
+
|
24
|
+
private
|
25
|
+
def each_current_configuration(environment, name = nil)
|
26
|
+
rails_each_current_configuration(environment, name) { |db_config|
|
27
|
+
next if environment == "development" && ENV["SKIP_TEST_DATABASE"] == "1" && db_config["database"] != "discourse_development"
|
28
|
+
yield db_config
|
29
|
+
}
|
30
|
+
end
|
12
31
|
end
|
@@ -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,43 @@ 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 = self.seed || 1
|
74
|
+
Faker::Config.random = Random.new(seed)
|
75
|
+
end
|
76
|
+
|
77
|
+
def start_date
|
78
|
+
DateTime.parse(config["start_date"] || default_config["start_date"])
|
79
|
+
end
|
80
|
+
|
81
|
+
def method_missing(name)
|
82
|
+
name = name.to_s
|
83
|
+
config[name] || default_config[name]
|
84
|
+
end
|
45
85
|
end
|
46
86
|
end
|
data/lib/discourse_dev/group.rb
CHANGED
@@ -11,23 +11,15 @@ 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
|
-
primary_group: Faker::Boolean.boolean
|
21
|
+
primary_group: Faker::Boolean.boolean,
|
22
|
+
created_at: Faker::Time.between(from: DiscourseDev.config.start_date, to: DateTime.now),
|
31
23
|
}
|
32
24
|
end
|
33
25
|
|
@@ -40,5 +32,9 @@ module DiscourseDev
|
|
40
32
|
end
|
41
33
|
end
|
42
34
|
end
|
35
|
+
|
36
|
+
def self.random
|
37
|
+
super(::Group)
|
38
|
+
end
|
43
39
|
end
|
44
40
|
end
|
@@ -0,0 +1,104 @@
|
|
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
|
+
@max_likes_count = DiscourseDev.config.max_likes_count
|
17
|
+
unless category.groups.blank?
|
18
|
+
group_ids = category.groups.pluck(:id)
|
19
|
+
@user_ids = ::GroupUser.where(group_id: group_ids).pluck(:user_id)
|
20
|
+
@user_count = @user_ids.count
|
21
|
+
@max_likes_count = @user_count - 1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def data
|
26
|
+
{
|
27
|
+
topic_id: topic.id,
|
28
|
+
raw: Faker::Markdown.sandwich(sentences: 5),
|
29
|
+
created_at: Faker::Time.between(from: topic.last_posted_at, to: DateTime.now),
|
30
|
+
skip_validations: true,
|
31
|
+
skip_guardian: true
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def create!
|
36
|
+
post = PostCreator.new(user, data).create!
|
37
|
+
topic.reload
|
38
|
+
generate_likes(post)
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate_likes(post)
|
42
|
+
user_ids = [post.user_id]
|
43
|
+
|
44
|
+
Faker::Number.between(from: 0, to: @max_likes_count).times do
|
45
|
+
user = self.user
|
46
|
+
next if user_ids.include?(user.id)
|
47
|
+
|
48
|
+
PostActionCreator.new(user, post, PostActionType.types[:like], created_at: Faker::Time.between(from: post.created_at, to: DateTime.now)).perform
|
49
|
+
user_ids << user.id
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def user
|
54
|
+
return User.random if topic.category.groups.blank?
|
55
|
+
return Discourse.system_user if @user_ids.blank?
|
56
|
+
|
57
|
+
position = Faker::Number.between(from: 0, to: @user_count - 1)
|
58
|
+
::User.find(@user_ids[position])
|
59
|
+
end
|
60
|
+
|
61
|
+
def populate!
|
62
|
+
generate_likes(topic.first_post)
|
63
|
+
|
64
|
+
@count.times do |i|
|
65
|
+
@index = i
|
66
|
+
create!
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.add_replies!(args)
|
71
|
+
if !args[:topic_id]
|
72
|
+
puts "Topic ID is required. Aborting."
|
73
|
+
return
|
74
|
+
end
|
75
|
+
|
76
|
+
if !::Topic.find_by_id(args[:topic_id])
|
77
|
+
puts "Topic ID does not match topic in DB, aborting."
|
78
|
+
return
|
79
|
+
end
|
80
|
+
|
81
|
+
topic = ::Topic.find_by_id(args[:topic_id])
|
82
|
+
count = args[:count] ? args[:count].to_i : 50
|
83
|
+
|
84
|
+
puts "Creating #{count} replies in '#{topic.title}'"
|
85
|
+
|
86
|
+
count.times do |i|
|
87
|
+
@index = i
|
88
|
+
begin
|
89
|
+
reply = {
|
90
|
+
topic_id: topic.id,
|
91
|
+
raw: Faker::Markdown.sandwich(sentences: 5),
|
92
|
+
skip_validations: true
|
93
|
+
}
|
94
|
+
PostCreator.new(User.random, reply).create!
|
95
|
+
rescue ActiveRecord::RecordNotSaved => e
|
96
|
+
puts e
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
puts "Done!"
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
data/lib/discourse_dev/record.rb
CHANGED
@@ -8,28 +8,61 @@ 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
|
15
|
+
RateLimiter.disable
|
16
|
+
|
14
17
|
@model = model
|
15
18
|
@type = model.to_s
|
16
19
|
@count = count
|
20
|
+
@index = nil
|
17
21
|
end
|
18
22
|
|
19
23
|
def create!
|
20
24
|
record = model.create!(data)
|
21
|
-
yield(record)
|
22
|
-
putc "."
|
25
|
+
yield(record) if block_given?
|
23
26
|
end
|
24
27
|
|
25
28
|
def populate!
|
26
|
-
|
27
|
-
|
29
|
+
if current_count >= @count
|
30
|
+
puts "Already have #{@count}+ #{type.downcase} records."
|
31
|
+
|
32
|
+
Rake.application.top_level_tasks.each do |task_name|
|
33
|
+
Rake::Task[task_name].reenable
|
34
|
+
end
|
35
|
+
|
36
|
+
Rake::Task['dev:repopulate'].invoke
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
puts "Creating #{@count} sample #{type.downcase} records"
|
41
|
+
|
42
|
+
@count.times do |i|
|
43
|
+
@index = i
|
44
|
+
create!
|
45
|
+
putc "."
|
46
|
+
end
|
47
|
+
|
28
48
|
puts
|
29
49
|
end
|
30
50
|
|
51
|
+
def index
|
52
|
+
@index
|
53
|
+
end
|
54
|
+
|
55
|
+
def current_count
|
56
|
+
model.count
|
57
|
+
end
|
58
|
+
|
31
59
|
def self.populate!
|
32
60
|
self.new.populate!
|
33
61
|
end
|
62
|
+
|
63
|
+
def self.random(model)
|
64
|
+
offset = Faker::Number.between(from: 0, to: model.count - 1)
|
65
|
+
model.offset(offset).first
|
66
|
+
end
|
34
67
|
end
|
35
68
|
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
|
@@ -4,6 +4,9 @@ def check_environment!
|
|
4
4
|
if !Rails.env.development?
|
5
5
|
raise "Database commands are only supported in development environment"
|
6
6
|
end
|
7
|
+
|
8
|
+
ENV['SKIP_TEST_DATABASE'] = "1"
|
9
|
+
ENV['SKIP_MULTISITE'] = "1"
|
7
10
|
end
|
8
11
|
|
9
12
|
desc 'Run db:migrate:reset task and populate sample content for development environment'
|
@@ -12,13 +15,12 @@ task 'dev:reset' => ['db:load_config'] do |_, args|
|
|
12
15
|
|
13
16
|
Rake::Task['db:migrate:reset'].invoke
|
14
17
|
Rake::Task['dev:config'].invoke
|
15
|
-
Rake::Task['admin:create'].invoke
|
16
18
|
Rake::Task['dev:populate'].invoke
|
17
19
|
end
|
18
20
|
|
19
21
|
desc 'Initialize development environment'
|
20
22
|
task 'dev:config' => ['db:load_config'] do |_, args|
|
21
|
-
DiscourseDev
|
23
|
+
DiscourseDev.config.update!
|
22
24
|
end
|
23
25
|
|
24
26
|
desc 'Populate sample content for development environment'
|
@@ -26,5 +28,20 @@ task 'dev:populate' => ['db:load_config'] do |_, args|
|
|
26
28
|
Rake::Task['groups:populate'].invoke
|
27
29
|
Rake::Task['users:populate'].invoke
|
28
30
|
Rake::Task['categories:populate'].invoke
|
31
|
+
Rake::Task['tags:populate'].invoke
|
29
32
|
Rake::Task['topics:populate'].invoke
|
33
|
+
system("redis-cli flushall")
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Repopulate sample datas in development environment'
|
37
|
+
task 'dev:repopulate' => ['db:load_config'] do |_, args|
|
38
|
+
require 'highline/import'
|
39
|
+
|
40
|
+
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) ")
|
41
|
+
|
42
|
+
if (answer == "" || answer.downcase == 'y')
|
43
|
+
Rake::Task['dev:reset'].invoke
|
44
|
+
else
|
45
|
+
puts "You can run `dev:reset` rake task to do this repopulate action anytime."
|
46
|
+
end
|
30
47
|
end
|
@@ -15,7 +15,17 @@ 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!
|
21
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,86 @@ 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
|
14
|
+
max_views = 0
|
15
|
+
|
16
|
+
case Faker::Number.between(from: 0, to: 5)
|
17
|
+
when 0
|
18
|
+
max_views = 10
|
19
|
+
when 1
|
20
|
+
max_views = 100
|
21
|
+
when 2
|
22
|
+
max_views = SiteSetting.topic_views_heat_low
|
23
|
+
when 3
|
24
|
+
max_views = SiteSetting.topic_views_heat_medium
|
25
|
+
when 4
|
26
|
+
max_views = SiteSetting.topic_views_heat_high
|
27
|
+
when 5
|
28
|
+
max_views = SiteSetting.topic_views_heat_high + SiteSetting.topic_views_heat_medium
|
29
|
+
end
|
30
|
+
|
16
31
|
{
|
17
|
-
title:
|
32
|
+
title: title[0, SiteSetting.max_topic_title_length],
|
18
33
|
raw: Faker::Markdown.sandwich(sentences: 5),
|
19
|
-
category: @
|
20
|
-
|
34
|
+
category: @category.id,
|
35
|
+
created_at: Faker::Time.between(from: DiscourseDev.config.start_date, to: DateTime.now),
|
36
|
+
tags: tags,
|
37
|
+
topic_opts: {
|
38
|
+
import_mode: true,
|
39
|
+
views: Faker::Number.between(from: 1, to: max_views),
|
40
|
+
custom_fields: { dev_sample: true }
|
41
|
+
},
|
21
42
|
skip_validations: true
|
22
43
|
}
|
23
44
|
end
|
24
45
|
|
46
|
+
def title
|
47
|
+
if index <= I18n.t("faker.discourse.topics").count
|
48
|
+
Faker::Discourse.unique.topic
|
49
|
+
else
|
50
|
+
Faker::Lorem.unique.sentence(word_count: 3, supplemental: true, random_words_to_add: 4).chomp(".")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def tags
|
55
|
+
@tags = []
|
56
|
+
|
57
|
+
Faker::Number.between(from: 0, to: 3).times do
|
58
|
+
@tags << Faker::Discourse.tag
|
59
|
+
end
|
60
|
+
|
61
|
+
@tags.uniq
|
62
|
+
end
|
63
|
+
|
25
64
|
def create!
|
26
|
-
|
27
|
-
|
65
|
+
@category = Category.random
|
66
|
+
topic = data
|
67
|
+
post = PostCreator.new(user, topic).create!
|
68
|
+
|
69
|
+
if topic[:title] == "Coolest thing you have seen today"
|
70
|
+
reply_count = 99
|
71
|
+
else
|
72
|
+
reply_count = Faker::Number.between(from: 0, to: 12)
|
73
|
+
end
|
74
|
+
|
75
|
+
Post.new(post.topic, reply_count).populate!
|
76
|
+
end
|
77
|
+
|
78
|
+
def user
|
79
|
+
return User.random if @category.groups.blank?
|
80
|
+
|
81
|
+
group_ids = @category.groups.pluck(:id)
|
82
|
+
user_ids = ::GroupUser.where(group_id: group_ids).pluck(:user_id)
|
83
|
+
user_count = user_ids.count
|
84
|
+
position = Faker::Number.between(from: 0, to: user_count - 1)
|
85
|
+
::User.find(user_ids[position] || Discourse::SYSTEM_USER_ID)
|
86
|
+
end
|
28
87
|
|
29
|
-
|
30
|
-
|
88
|
+
def current_count
|
89
|
+
category_definition_topic_ids = ::Category.pluck(:topic_id)
|
90
|
+
::Topic.where(archetype: :regular).where.not(id: category_definition_topic_ids).count
|
31
91
|
end
|
32
92
|
end
|
33
93
|
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
|
{
|
@@ -25,19 +23,24 @@ module DiscourseDev
|
|
25
23
|
username: username,
|
26
24
|
username_lower: username_lower,
|
27
25
|
moderator: Faker::Boolean.boolean(true_ratio: 0.1),
|
28
|
-
trust_level: Faker::Number.between(from: 1, to: 4)
|
26
|
+
trust_level: Faker::Number.between(from: 1, to: 4),
|
27
|
+
created_at: Faker::Time.between(from: DiscourseDev.config.start_date, to: DateTime.now),
|
29
28
|
}
|
30
29
|
end
|
31
30
|
|
32
31
|
def create!
|
33
32
|
super do |user|
|
33
|
+
user.activate
|
34
34
|
Faker::Number.between(from: 0, to: 2).times do
|
35
|
-
|
36
|
-
group = @groups.offset(offset).first
|
35
|
+
group = Group.random
|
37
36
|
|
38
37
|
group.add(user)
|
39
38
|
end
|
40
39
|
end
|
41
40
|
end
|
41
|
+
|
42
|
+
def self.random
|
43
|
+
super(::User)
|
44
|
+
end
|
42
45
|
end
|
43
46
|
end
|
data/lib/faker/discourse.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
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
|
@@ -11,6 +17,10 @@ module Faker
|
|
11
17
|
def group
|
12
18
|
fetch('discourse.groups')
|
13
19
|
end
|
20
|
+
|
21
|
+
def topic
|
22
|
+
fetch('discourse.topics')
|
23
|
+
end
|
14
24
|
end
|
15
25
|
end
|
16
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.8
|
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
|
@@ -65,14 +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
|
71
72
|
- lib/discourse_dev/config.rb
|
72
73
|
- lib/discourse_dev/config.yml
|
74
|
+
- lib/discourse_dev/engine.rb
|
73
75
|
- lib/discourse_dev/group.rb
|
76
|
+
- lib/discourse_dev/post.rb
|
74
77
|
- lib/discourse_dev/railtie.rb
|
75
78
|
- lib/discourse_dev/record.rb
|
79
|
+
- lib/discourse_dev/tag.rb
|
76
80
|
- lib/discourse_dev/tasks/dev.rake
|
77
81
|
- lib/discourse_dev/tasks/populate.rake
|
78
82
|
- lib/discourse_dev/topic.rb
|