Skip to content
Snippets Groups Projects
Commit 4e351678 authored by Rémy Coutable's avatar Rémy Coutable
Browse files

Don't use FFaker in factories, use sequences instead


FFaker can generate data that randomly break our test suite. This
simplifies our factories and use sequences which are more predictive.

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent ca6a7f1e
No related branches found
No related tags found
No related merge requests found
Showing
with 40 additions and 51 deletions
Loading
Loading
@@ -23,13 +23,13 @@ class Spinach::Features::ProjectHooks < Spinach::FeatureSteps
end
 
step 'I submit new hook' do
@url = FFaker::Internet.uri("http")
@url = 'http://example.org/1'
fill_in "hook_url", with: @url
expect { click_button "Add Webhook" }.to change(ProjectHook, :count).by(1)
end
 
step 'I submit new hook with SSL verification enabled' do
@url = FFaker::Internet.uri("http")
@url = 'http://example.org/2'
fill_in "hook_url", with: @url
check "hook_enable_ssl_verification"
expect { click_button "Add Webhook" }.to change(ProjectHook, :count).by(1)
Loading
Loading
Loading
Loading
@@ -12,7 +12,7 @@ describe Profiles::PersonalAccessTokensController do
end
 
it "allows creation of a token with scopes" do
name = FFaker::Product.brand
name = 'My PAT'
scopes = %w[api read_user]
 
post :create, personal_access_token: token_attributes.merge(scopes: scopes, name: name)
Loading
Loading
Loading
Loading
@@ -6,11 +6,7 @@ FactoryGirl.define do
team_id 'T0001'
team_domain 'Awesome Team'
 
sequence :chat_id do |n|
"U#{n}"
end
sequence :chat_name do |n|
"user#{n}"
end
sequence(:chat_id) { |n| "U#{n}" }
chat_name { generate(:username) }
end
end
FactoryGirl.define do
factory :chat_team, class: ChatTeam do
sequence :team_id do |n|
"abcdefghijklm#{n}"
end
sequence(:team_id) { |n| "abcdefghijklm#{n}" }
namespace factory: :group
end
end
FactoryGirl.define do
factory :ci_runner, class: Ci::Runner do
sequence :description do |n|
"My runner#{n}"
end
sequence(:description) { |n| "My runner#{n}" }
 
platform "darwin"
is_shared false
Loading
Loading
FactoryGirl.define do
factory :email do
user
email { FFaker::Internet.email('alias') }
email { generate(:email_alias) }
end
end
FactoryGirl.define do
sequence :issue_created_at do |n|
4.hours.ago + ( 2 * n ).seconds
end
factory :issue do
title
author
Loading
Loading
FactoryGirl.define do
factory :label, class: ProjectLabel do
sequence(:title) { |n| "label#{n}" }
title { generate(:label) }
color "#990000"
project factory: :empty_project
 
Loading
Loading
@@ -16,7 +16,7 @@ FactoryGirl.define do
end
 
factory :group_label, class: GroupLabel do
sequence(:title) { |n| "label#{n}" }
title { generate(:label) }
color "#990000"
group
end
Loading
Loading
FactoryGirl.define do
factory :oauth_application, class: 'Doorkeeper::Application', aliases: [:application] do
name { FFaker::Name.name }
sequence(:name) { |n| "OAuth App #{n}" }
uid { Doorkeeper::OAuth::Helpers::UniqueToken.generate }
redirect_uri { FFaker::Internet.uri('http') }
redirect_uri { generate(:url) }
owner
owner_type 'User'
end
Loading
Loading
Loading
Loading
@@ -2,7 +2,7 @@ FactoryGirl.define do
factory :personal_access_token do
user
token { SecureRandom.hex(50) }
name { FFaker::Product.brand }
sequence(:name) { |n| "PAT #{n}" }
revoked false
expires_at { 5.days.from_now }
scopes ['api']
Loading
Loading
FactoryGirl.define do
factory :project_hook do
url { FFaker::Internet.uri('http') }
url { generate(:url) }
 
trait :token do
token { SecureRandom.hex(10) }
Loading
Loading
FactoryGirl.define do
sequence(:username) { |n| "user#{n}" }
sequence(:name) { |n| "John Doe#{n}" }
sequence(:email) { |n| "user#{n}@example.org" }
sequence(:email_alias) { |n| "user.alias#{n}@example.org" }
sequence(:url) { |n| "http://example#{n}.org" }
sequence(:label) { |n| "label#{n}" }
sequence(:branch) { |n| "my-branch-#{n}" }
sequence(:issue_created_at) { |n| 4.hours.ago + (2 * n).seconds }
end
FactoryGirl.define do
factory :service_hook do
url { FFaker::Internet.uri('http') }
url { generate(:url) }
service
end
end
FactoryGirl.define do
sequence :title, aliases: [:content] do
FFaker::Lorem.sentence
end
sequence :file_name do
FFaker::Internet.user_name
end
sequence(:title, aliases: [:content]) { |n| "My snippet #{n}" }
sequence(:file_name) { |n| "snippet-#{n}.rb" }
 
factory :snippet do
author
Loading
Loading
FactoryGirl.define do
factory :spam_log do
user
source_ip { FFaker::Internet.ip_v4_address }
sequence(:source_ip) { |n| "42.42.42.#{n % 255}" }
noteable_type 'Issue'
title { FFaker::Lorem.sentence }
description { FFaker::Lorem.paragraph(5) }
sequence(:title) { |n| "Spam title #{n}" }
description { "Spam description\nwith\nmultiple\nlines" }
end
end
FactoryGirl.define do
factory :system_hook do
url { FFaker::Internet.uri('http') }
url { generate(:url) }
end
end
FactoryGirl.define do
sequence(:name) { FFaker::Name.name }
factory :user, aliases: [:author, :assignee, :recipient, :owner, :creator, :resource_owner] do
email { FFaker::Internet.email }
name
sequence(:username) { |n| "#{FFaker::Internet.user_name}#{n}" }
email { generate(:email) }
name { generate(:name) }
username { generate(:username) }
password "12345678"
confirmed_at { Time.now }
confirmation_token { nil }
Loading
Loading
Loading
Loading
@@ -26,7 +26,7 @@ describe "Admin::Hooks", feature: true do
end
 
describe "New Hook" do
let(:url) { FFaker::Internet.uri('http') }
let(:url) { generate(:url) }
 
it 'adds new hook' do
visit admin_hooks_path
Loading
Loading
Loading
Loading
@@ -16,7 +16,7 @@ describe 'Admin > Users > Impersonation Tokens', feature: true, js: true do
 
describe "token creation" do
it "allows creation of a token" do
name = FFaker::Product.brand
name = 'Hello World'
 
visit admin_user_impersonation_tokens_path(user_id: user.username)
fill_in "Name", with: name
Loading
Loading
Loading
Loading
@@ -46,16 +46,16 @@ describe 'issuable list', feature: true do
end
 
def create_issuables(issuable_type)
3.times do
3.times do |n|
issuable =
if issuable_type == :issue
create(:issue, project: project, author: user)
else
create(:merge_request, title: FFaker::Lorem.sentence, source_project: project, source_branch: FFaker::Name.name)
create(:merge_request, source_project: project, source_branch: "#{n}-feature")
end
 
2.times do
create(:note_on_issue, noteable: issuable, project: project, note: 'Test note')
create(:note_on_issue, noteable: issuable, project: project)
end
 
create(:award_emoji, :downvote, awardable: issuable)
Loading
Loading
@@ -65,9 +65,8 @@ describe 'issuable list', feature: true do
if issuable_type == :issue
issue = Issue.reorder(:iid).first
merge_request = create(:merge_request,
title: FFaker::Lorem.sentence,
source_project: project,
source_branch: FFaker::Name.name)
source_branch: 'my-bug-fix')
 
MergeRequestsClosingIssues.create!(issue: issue, merge_request: merge_request)
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment