From 55b691c980d3e37bc8025aec1165e3f55dd64a67 Mon Sep 17 00:00:00 2001 From: Molly Struve Date: Fri, 20 Dec 2019 12:21:16 -0600 Subject: [PATCH] Ensure model properties in factories are unique (#5190) --- spec/factories/articles.rb | 4 +++- spec/factories/badges.rb | 2 +- spec/factories/chat_channels.rb | 2 +- spec/factories/collections.rb | 2 +- spec/factories/github_repos.rb | 7 +++++-- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/spec/factories/articles.rb b/spec/factories/articles.rb index 186ba8eba..bc0696e08 100644 --- a/spec/factories/articles.rb +++ b/spec/factories/articles.rb @@ -1,7 +1,9 @@ FactoryBot.define do + sequence(:title) { |n| "#{Faker::Book.title}#{n}" } + factory :article do transient do - title { Faker::Book.title + " #{rand(1000)}" } + title { generate :title } published { true } date { "01/01/2015" } tags { Faker::Hipster.words(number: 4).join(", ") } diff --git a/spec/factories/badges.rb b/spec/factories/badges.rb index 78e17451f..b6580c827 100644 --- a/spec/factories/badges.rb +++ b/spec/factories/badges.rb @@ -2,7 +2,7 @@ FactoryBot.define do image_path = Rails.root.join("spec/support/fixtures/images/image1.jpeg") factory :badge do - title { Faker::Book.title + " #{rand(1000)}" } + sequence(:title) { |n| "#{Faker::Book.title}-#{n}" } description { Faker::Lorem.sentence } badge_image { Rack::Test::UploadedFile.new(image_path, "image/jpeg") } end diff --git a/spec/factories/chat_channels.rb b/spec/factories/chat_channels.rb index 2e6e118b2..fb2fbc194 100644 --- a/spec/factories/chat_channels.rb +++ b/spec/factories/chat_channels.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :chat_channel do channel_type { "open" } - slug { rand(10_000_000_000).to_s } + sequence(:slug) { |n| "slug-#{n}" } end trait :workshop do diff --git a/spec/factories/collections.rb b/spec/factories/collections.rb index 24ccda9ef..5a595f944 100644 --- a/spec/factories/collections.rb +++ b/spec/factories/collections.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :collection do user - slug { "word-#{rand(10_000)}" } + sequence(:slug) { |n| "slug-#{n}" } end trait :with_articles do diff --git a/spec/factories/github_repos.rb b/spec/factories/github_repos.rb index 70f684d3b..1a9c273fc 100644 --- a/spec/factories/github_repos.rb +++ b/spec/factories/github_repos.rb @@ -1,13 +1,16 @@ FactoryBot.define do + sequence(:github_id_code) { |n| n } + sequence(:url) { |n| "#{Faker::Internet.url}#{n}" } + factory :github_repo do user name { Faker::Book.title } - url { Faker::Internet.url } + url { generate :url } description { Faker::Book.title } language { Faker::Book.title } bytes_size { rand(100_000) } watchers_count { rand(100_000) } - github_id_code { rand(100_000) } + github_id_code { generate :github_id_code } stargazers_count { rand(100_000) } featured { true } fork { false }