Fix fake_data task; add CI test for it (#1087)
The test is overdue for how brittle fake_data.rb is, but as that's a slow process that's not critical functionality, I only want it running on CI.
This commit is contained in:
parent
36cee94b69
commit
344e947374
|
@ -26,7 +26,9 @@ jobs:
|
|||
- name: Prepare database
|
||||
run: ./bin/rails db:schema:load
|
||||
- name: Run tests
|
||||
run: bundle exec rspec
|
||||
run: |
|
||||
bundle exec rspec
|
||||
bundle exec rspec spec/slow/*_spec.rb
|
||||
- name: Run linters
|
||||
run: |
|
||||
bundle exec rubocop
|
||||
|
|
|
@ -116,6 +116,9 @@ running tests:
|
|||
|
||||
* See `config/initializers/production.rb.sample` for GitHub/Twitter integration help.
|
||||
|
||||
* You probably want to use [git-imerge](https://lobste.rs/s/dbm2d4) to pull in
|
||||
changes from Lobsters to your site.
|
||||
|
||||
#### Administration
|
||||
|
||||
Basic moderation happens on-site, but most other administrative tasks require use of the rails console in production.
|
||||
|
|
|
@ -31,4 +31,4 @@ puts " * inactive-user for disowned comments by deleted users"
|
|||
puts " * a test tag"
|
||||
puts
|
||||
puts "If this is a dev environment, you probably want to run `rails fake_data`"
|
||||
puts "If this is production, you want to run `rails console` to rename your admin, category, and tag"
|
||||
puts "If this is production, you want to run `rails console` to rename your admin. Edit your category, and tag on-site."
|
||||
|
|
|
@ -19,7 +19,7 @@ class FakeDataGenerator
|
|||
email: Faker::Internet.email(name: name),
|
||||
password: password,
|
||||
password_confirmation: password,
|
||||
username: Faker::Internet.user_name(specifier: 5..40, separators: %w(_)),
|
||||
username: Faker::Internet.user_name(specifier: name, separators: %w(_))[..23],
|
||||
created_at: (User::NEW_USER_DAYS + 1).days.ago,
|
||||
karma: Random.rand(User::MIN_KARMA_TO_FLAG * 2),
|
||||
about: Faker::Lorem.sentence(word_count: 7),
|
||||
|
@ -27,14 +27,20 @@ class FakeDataGenerator
|
|||
invited_by_user: User.select(&:can_invite?).sample,
|
||||
}
|
||||
create_args.merge!(is_admin: true) if i % 8 == 0
|
||||
users << User.create!(create_args)
|
||||
if i % 7 == 0
|
||||
users[i].grant_moderatorship_by_user!(mod)
|
||||
end
|
||||
if i % 6 == 0
|
||||
users[i].disable_invite_by_user_for_reason!(mod, Faker::Lorem.sentence(word_count: 5))
|
||||
begin
|
||||
users << User.create!(create_args)
|
||||
if i % 7 == 0
|
||||
users.last.grant_moderatorship_by_user!(mod)
|
||||
end
|
||||
if i % 6 == 0
|
||||
users.last.disable_invite_by_user_for_reason!(mod, Faker::Lorem.sentence(word_count: 5))
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
puts "caught #{e}"
|
||||
next if e.message == 'Validation failed: Username has already been taken'
|
||||
end
|
||||
end
|
||||
users.compact!
|
||||
puts
|
||||
|
||||
print 'Categories '
|
||||
|
@ -225,7 +231,7 @@ class FakeDataGenerator
|
|||
user.ban_by_user_for_reason!(User.moderators.sample,
|
||||
Faker::Lorem.sentence(word_count: 5))
|
||||
if i.even?
|
||||
user.unban_by_user!(User.moderators.sample)
|
||||
user.unban_by_user!(User.moderators.sample, "reformed")
|
||||
end
|
||||
end
|
||||
puts
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Tests in this directory do not run as part of the regular test suite with
|
||||
`bundle exec rspec`. They are excluded by config.exclude
|
|
@ -0,0 +1,12 @@
|
|||
require 'rails_helper'
|
||||
|
||||
Rails.application.load_tasks
|
||||
|
||||
describe "fake_data" do
|
||||
before { Rails.application.load_seed }
|
||||
|
||||
# basic smoke test, task shouldn't throw exceptions
|
||||
it 'runs' do
|
||||
FakeDataGenerator.new.generate
|
||||
end
|
||||
end
|
|
@ -37,6 +37,9 @@ RSpec.configure do |config|
|
|||
mocks.verify_partial_doubles = true
|
||||
end
|
||||
|
||||
# Some tests are slow, rarely catch a bug, and are not critical functionality.
|
||||
config.exclude_pattern = 'spec/slow/*_spec.rb'
|
||||
|
||||
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
||||
# have no way to turn it off -- the option exists only for backwards
|
||||
# compatibility in RSpec 3). It causes shared context metadata to be
|
||||
|
|
Loading…
Reference in New Issue