From 3fcf9cedd88c19fd6fd5585714b111429676dabc Mon Sep 17 00:00:00 2001 From: James Smith Date: Wed, 24 Jun 2026 12:31:01 +0100 Subject: [PATCH] Use Faker::UniquenessGenerator to stop name clashes in tests --- spec/factories/collection.rb | 2 +- spec/factories/doorkeeper/application.rb | 2 +- spec/factories/federails/actor.rb | 2 +- spec/factories/group.rb | 2 +- spec/factories/link.rb | 2 +- spec/factories/list.rb | 2 +- spec/factories/model_file.rb | 2 +- spec/factories/user.rb | 4 ++-- spec/support/faker.rb | 5 +++++ 9 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 spec/support/faker.rb diff --git a/spec/factories/collection.rb b/spec/factories/collection.rb index 46786f415..fbaa45228 100644 --- a/spec/factories/collection.rb +++ b/spec/factories/collection.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :collection do - name { Faker::Name.name } + name { Faker::Name.unique.name } caption { Faker::Lorem.sentence } notes { Faker::Lorem.paragraph } links_attributes { [{url: "http://example.com", text: "anchor text"}] } diff --git a/spec/factories/doorkeeper/application.rb b/spec/factories/doorkeeper/application.rb index 3eb2858a1..28976b835 100644 --- a/spec/factories/doorkeeper/application.rb +++ b/spec/factories/doorkeeper/application.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :oauth_application, class: "Doorkeeper::Application" do - name { Faker::Appliance.equipment } + name { Faker::Appliance.unique.equipment } redirect_uri { "urn:ietf:wg:oauth:2.0:oob" } scopes { ["read", "write", "delete"] } confidential { true } diff --git a/spec/factories/federails/actor.rb b/spec/factories/federails/actor.rb index eb42bced4..975c3f21a 100644 --- a/spec/factories/federails/actor.rb +++ b/spec/factories/federails/actor.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :actor, class: "Federails::Actor" do - name { Faker::Name.name } + name { Faker::Name.unique.name } actor_type { "Person" } entity { nil } extensions { diff --git a/spec/factories/group.rb b/spec/factories/group.rb index 4171c5ab4..bd8621786 100644 --- a/spec/factories/group.rb +++ b/spec/factories/group.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :group do - name { Faker::Commerce.product_name } + name { Faker::Commerce.unique.product_name } creator end end diff --git a/spec/factories/link.rb b/spec/factories/link.rb index edb8401b5..69462955b 100644 --- a/spec/factories/link.rb +++ b/spec/factories/link.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :link do - url { Faker::Internet.url } + url { Faker::Internet.unique.url } text { Faker::Internet.username } end end diff --git a/spec/factories/list.rb b/spec/factories/list.rb index 1bc8f8832..4895be2be 100644 --- a/spec/factories/list.rb +++ b/spec/factories/list.rb @@ -1,5 +1,5 @@ FactoryBot.define do factory :list do - name { Faker::Name.name } + name { Faker::Name.unique.name } end end diff --git a/spec/factories/model_file.rb b/spec/factories/model_file.rb index 95dbfb370..e9c7a74d7 100644 --- a/spec/factories/model_file.rb +++ b/spec/factories/model_file.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :model_file do model - filename { Faker::File.file_name(ext: "stl") } + filename { Faker::File.unique.file_name(ext: "stl") } attachment { filename ? Rack::Test::UploadedFile.new(StringIO.new, original_filename: filename) : nil } after :create do |file, context| diff --git a/spec/factories/user.rb b/spec/factories/user.rb index 1615ae831..f14d298e4 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :user do - email { Faker::Internet.email } - username { Faker::Internet.username specifier: 8, separators: [] } + email { Faker::Internet.unique.email } + username { Faker::Internet.unique.username specifier: 8, separators: [] } password { Faker::Internet.password max_length: 32, min_length: 32, mix_case: true, special_characters: true } factory :admin do diff --git a/spec/support/faker.rb b/spec/support/faker.rb new file mode 100644 index 000000000..a2b20e7eb --- /dev/null +++ b/spec/support/faker.rb @@ -0,0 +1,5 @@ +RSpec.configure do |config| + config.after do + Faker::UniqueGenerator.clear + end +end