Fabricator specs (#23925)

This commit is contained in:
Matt Jankowski 2023-03-04 11:12:09 -05:00 committed by GitHub
parent c40d5e5a8f
commit cd99fa8ceb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 27 additions and 183 deletions

View file

@ -1,7 +0,0 @@
# frozen_string_literal: true
Fabricator(:account_alias) do
account
acct 'test@example.com'
uri 'https://example.com/users/test'
end

View file

@ -1,5 +0,0 @@
# frozen_string_literal: true
Fabricator(:account_deletion_request) do
account
end

View file

@ -5,4 +5,5 @@ Fabricator(:account_migration) do
target_account { |attrs| Fabricate(:account, also_known_as: [ActivityPub::TagManager.instance.uri_for(attrs[:account])]) }
acct { |attrs| attrs[:target_account].acct }
followers_count 1234
created_at { 60.days.ago }
end

View file

@ -2,5 +2,6 @@
Fabricator(:account_moderation_note) do
content 'MyText'
account nil
account
target_account { Fabricate(:account) }
end

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true
Fabricator(:account_pin) do
account nil
target_account nil
account
target_account(fabricator: :account)
before_create { |account_pin, _| account_pin.account.follow!(account_pin.target_account) }
end

View file

@ -1,8 +1,8 @@
# frozen_string_literal: true
Fabricator(:account_stat) do
account nil
statuses_count ''
following_count ''
followers_count ''
account
statuses_count '123'
following_count '456'
followers_count '789'
end

View file

@ -1,5 +0,0 @@
# frozen_string_literal: true
Fabricator(:account_tag_stat) do
accounts_count ''
end

View file

@ -1,5 +0,0 @@
# frozen_string_literal: true
Fabricator(:account_warning_preset) do
text 'MyText'
end

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true
Fabricator('Admin::ActionLog') do
account nil
account
action 'MyString'
target nil
end

View file

@ -1,6 +0,0 @@
# frozen_string_literal: true
Fabricator(:announcement_mute) do
account
announcement
end

View file

@ -1,7 +0,0 @@
# frozen_string_literal: true
Fabricator(:announcement_reaction) do
account
announcement
name '🌿'
end

View file

@ -1,8 +0,0 @@
# frozen_string_literal: true
Fabricator(:conversation_account) do
account nil
conversation nil
participant_account_ids ''
last_status nil
end

View file

@ -1,4 +0,0 @@
# frozen_string_literal: true
Fabricator(:conversation_mute) do
end

View file

@ -1,5 +0,0 @@
# frozen_string_literal: true
Fabricator(:custom_emoji_category) do
name 'MyString'
end

View file

@ -1,10 +0,0 @@
# frozen_string_literal: true
Fabricator(:encrypted_message) do
device
from_account
from_device_id { Faker::Number.number(digits: 5) }
type 0
body ''
message_franking ''
end

View file

@ -1,8 +0,0 @@
# frozen_string_literal: true
Fabricator(:featured_tag) do
account
tag
statuses_count 1_337
last_status_at Time.now.utc
end

View file

@ -1,5 +0,0 @@
# frozen_string_literal: true
Fabricator(:follow_recommendation_suppression) do
account
end

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true
Fabricator(:identity) do
user nil
user
provider 'MyString'
uid 'MyString'
end

View file

@ -1,4 +0,0 @@
# frozen_string_literal: true
Fabricator(:import) do
end

View file

@ -1,8 +0,0 @@
# frozen_string_literal: true
Fabricator(:ip_block) do
ip ''
severity ''
expires_at '2020-10-08 22:20:37'
comment 'MyText'
end

View file

@ -1,7 +0,0 @@
# frozen_string_literal: true
Fabricator(:list_account) do
list nil
account nil
follow nil
end

View file

@ -1,13 +0,0 @@
# frozen_string_literal: true
Fabricator(:one_time_key) do
device
key_id { Faker::Alphanumeric.alphanumeric(number: 10) }
key { Base64.strict_encode64(Ed25519::SigningKey.generate.verify_key.to_bytes) }
signature do |attrs|
signing_key = Ed25519::SigningKey.generate
attrs[:device].update(fingerprint_key: Base64.strict_encode64(signing_key.verify_key.to_bytes))
Base64.strict_encode64(signing_key.sign(attrs[:key]))
end
end

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
Fabricator(:setting) do
var 'var'
end

View file

@ -2,4 +2,5 @@
Fabricator(:site_upload) do
file { Rails.root.join('spec', 'fabricators', 'assets', 'utah_teapot.png').open }
var 'thumbnail'
end

View file

@ -1,9 +0,0 @@
# frozen_string_literal: true
Fabricator(:status_edit) do
status nil
account nil
text 'MyText'
spoiler_text 'MyText'
media_attachments_changed false
end

View file

@ -1,8 +0,0 @@
# frozen_string_literal: true
Fabricator(:status_stat) do
status_id nil
replies_count ''
reblogs_count ''
favourites_count ''
end

View file

@ -1,5 +1,5 @@
# frozen_string_literal: true
Fabricator(:unavailable_domain) do
domain { Faker::Internet.domain }
domain { Faker::Internet.domain_name }
end

View file

@ -1,6 +0,0 @@
# frozen_string_literal: true
Fabricator(:user_invite_request) do
user
text { Faker::Lorem.sentence }
end

View file

@ -1,4 +0,0 @@
# frozen_string_literal: true
Fabricator(:web_setting, from: Web::Setting) do
end

12
spec/fabricators_spec.rb Normal file
View file

@ -0,0 +1,12 @@
require 'rails_helper'
Fabrication.manager.load_definitions if Fabrication.manager.empty?
Fabrication.manager.schematics.map(&:first).each do |factory_name|
describe "The #{factory_name} factory" do
it 'is valid' do
factory = Fabricate(factory_name)
expect(factory).to be_valid
end
end
end

View file

@ -704,12 +704,6 @@ RSpec.describe Account, type: :model do
end
describe 'validations' do
it 'has a valid fabricator' do
account = Fabricate.build(:account)
account.valid?
expect(account).to be_valid
end
it 'is invalid without a username' do
account = Fabricate.build(:account, username: nil)
account.valid?

View file

@ -4,11 +4,6 @@ require 'rails_helper'
RSpec.describe Block, type: :model do
describe 'validations' do
it 'has a valid fabricator' do
block = Fabricate.build(:block)
expect(block).to be_valid
end
it 'is invalid without an account' do
block = Fabricate.build(:block, account: nil)
block.valid?

View file

@ -4,11 +4,6 @@ require 'rails_helper'
RSpec.describe DomainBlock, type: :model do
describe 'validations' do
it 'has a valid fabricator' do
domain_block = Fabricate.build(:domain_block)
expect(domain_block).to be_valid
end
it 'is invalid without a domain' do
domain_block = Fabricate.build(:domain_block, domain: nil)
domain_block.valid?

View file

@ -3,13 +3,6 @@
require 'rails_helper'
RSpec.describe EmailDomainBlock, type: :model do
describe 'validations' do
it 'has a valid fabricator' do
email_domain_block = Fabricate.build(:email_domain_block)
expect(email_domain_block).to be_valid
end
end
describe 'block?' do
let(:input) { nil }

View file

@ -9,11 +9,6 @@ RSpec.describe Follow, type: :model do
describe 'validations' do
subject { Follow.new(account: alice, target_account: bob, rate_limit: true) }
it 'has a valid fabricator' do
follow = Fabricate.build(:follow)
expect(follow).to be_valid
end
it 'is invalid without an account' do
follow = Fabricate.build(:follow, account: nil)
follow.valid?

View file

@ -4,11 +4,6 @@ require 'rails_helper'
RSpec.describe Mention, type: :model do
describe 'validations' do
it 'has a valid fabricator' do
mention = Fabricate.build(:mention)
expect(mention).to be_valid
end
it 'is invalid without an account' do
mention = Fabricate.build(:mention, account: nil)
mention.valid?

View file

@ -121,12 +121,6 @@ describe Report do
end
describe 'validations' do
it 'has a valid fabricator' do
report = Fabricate(:report)
report.valid?
expect(report).to be_valid
end
it 'is invalid if comment is longer than 1000 characters' do
report = Fabricate.build(:report, comment: Faker::Lorem.characters(number: 1001))
report.valid?