Commit fa65b65b authored by Robert Speicher's avatar Robert Speicher

Merge branch '29643-stop-using-ffaker-in-factories' into 'master'

Don't use FFaker in factories, use sequences instead

Closes #29643

See merge request !10184
parents 2fd089a2 bf69e629
require 'factory_girl_rails'
module Db
module Fixtures
module Development
class AbuseReport
def self.seed
Gitlab::Seeder.quiet do
(::AbuseReport.default_per_page + 3).times do
reported_user =
::User.create!(
username: "#{FFaker::Internet.user_name}-reported",
name: FFaker::Name.name,
email: FFaker::Internet.email,
confirmed_at: DateTime.now,
password: '12345678'
)
(AbuseReport.default_per_page + 3).times do
FactoryGirl.create(:abuse_report)
::AbuseReport.create(reporter: ::User.take, user: reported_user, message: 'User sends spam')
print '.'
end
end
end
end
end
end
end
Db::Fixtures::Development::AbuseReport.seed
......@@ -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)
......
......@@ -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)
......
......@@ -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
......
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
title { generate(:title) }
author
project factory: :empty_project
......
FactoryGirl.define do
factory :label, class: ProjectLabel do
sequence(:title) { |n| "label#{n}" }
trait :base_label do
title { generate(:label_title) }
color "#990000"
end
factory :label, traits: [:base_label], class: ProjectLabel do
project factory: :empty_project
transient do
......@@ -15,9 +18,7 @@ FactoryGirl.define do
end
end
factory :group_label, class: GroupLabel do
sequence(:title) { |n| "label#{n}" }
color "#990000"
factory :group_label, traits: [:base_label] do
group
end
end
FactoryGirl.define do
factory :merge_request do
title
title { generate(:title) }
author
association :source_project, :repository, factory: :project
target_project { source_project }
......
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
......
......@@ -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']
......
FactoryGirl.define do
factory :project_hook do
url { FFaker::Internet.uri('http') }
url { generate(:url) }
trait :token do
token { SecureRandom.hex(10) }
......
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(:title) { |n| "My title #{n}" }
sequence(:filename) { |n| "filename-#{n}.rb" }
sequence(:url) { |n| "http://example#{n}.org" }
sequence(:label_title) { |n| "label#{n}" }
sequence(:branch) { |n| "my-branch-#{n}" }
sequence(:past_time) { |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
factory :snippet do
author
title
content
file_name
title { generate(:title) }
content { generate(:title) }
file_name { generate(:filename) }
trait :public do
visibility_level Snippet::PUBLIC
......
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 }
......
require 'spec_helper'
describe 'Admin browse spam logs' do
let!(:spam_log) { create(:spam_log) }
let!(:spam_log) { create(:spam_log, description: 'abcde ' * 20) }
before do
login_as :admin
......
......@@ -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
......
......@@ -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
......
......@@ -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: generate(:branch))
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)
......@@ -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: generate(:branch))
MergeRequestsClosingIssues.create!(issue: issue, merge_request: merge_request)
end
......
......@@ -27,7 +27,7 @@ describe 'Profile > Personal Access Tokens', feature: true, js: true do
describe "token creation" do
it "allows creation of a personal access token" do
name = FFaker::Product.brand
name = 'My PAT'
visit profile_personal_access_tokens_path
fill_in "Name", with: name
......@@ -52,7 +52,7 @@ describe 'Profile > Personal Access Tokens', feature: true, js: true do
it "displays an error message" do
disallow_personal_access_token_saves!
visit profile_personal_access_tokens_path
fill_in "Name", with: FFaker::Product.brand
fill_in "Name", with: 'My PAT'
expect { click_on "Create Personal Access Token" }.not_to change { PersonalAccessToken.count }
expect(page).to have_content("Name cannot be nil")
......
require 'spec_helper'
feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature: true, js: true do
feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', :js do
include WaitForAjax
before { allow_any_instance_of(U2fHelper).to receive(:inject_u2f_api?).and_return(true) }
......@@ -11,8 +11,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
wait_for_ajax
end
def register_u2f_device(u2f_device = nil)
name = FFaker::Name.first_name
def register_u2f_device(u2f_device = nil, name: 'My device')
u2f_device ||= FakeU2fDevice.new(page, name)
u2f_device.respond_to_u2f_registration
click_on 'Setup New U2F Device'
......@@ -62,7 +61,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
expect(page).to have_content('Your U2F device was registered')
# Second device
second_device = register_u2f_device
second_device = register_u2f_device(name: 'My other device')
expect(page).to have_content('Your U2F device was registered')
expect(page).to have_content(first_device.name)
......@@ -76,7 +75,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
expect(page).to have_content("You've already enabled two-factor authentication using mobile")
first_u2f_device = register_u2f_device
second_u2f_device = register_u2f_device
second_u2f_device = register_u2f_device(name: 'My other device')
click_on "Delete", match: :first
......@@ -99,7 +98,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
user.update_attribute(:otp_required_for_login, true)
visit profile_account_path
manage_two_factor_authentication
register_u2f_device(u2f_device)
register_u2f_device(u2f_device, name: 'My other device')
expect(page).to have_content('Your U2F device was registered')
expect(U2fRegistration.count).to eq(2)
......@@ -198,7 +197,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
current_user.update_attribute(:otp_required_for_login, true)
visit profile_account_path
manage_two_factor_authentication
register_u2f_device
register_u2f_device(name: 'My other device')
logout
# Try authenticating user with the old U2F device
......@@ -231,7 +230,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
describe "when a given U2F device has not been registered" do
it "does not allow logging in with that particular device" do
unregistered_device = FakeU2fDevice.new(page, FFaker::Name.first_name)
unregistered_device = FakeU2fDevice.new(page, 'My device')
login_as(user)
unregistered_device.respond_to_u2f_authentication
expect(page).to have_content('We heard back from your U2F device')
......@@ -252,7 +251,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
# Register second device
visit profile_two_factor_auth_path
expect(page).to have_content("Your U2F device needs to be set up.")
second_device = register_u2f_device
second_device = register_u2f_device(name: 'My other device')
logout
# Authenticate as both devices
......
......@@ -183,7 +183,7 @@ describe Gitlab::GitAccess, lib: true do
describe '#check_push_access!' do
before { merge_into_protected_branch }
let(:unprotected_branch) { FFaker::Internet.user_name }
let(:unprotected_branch) { 'unprotected_branch' }
let(:changes) do
{ push_new_branch: "#{Gitlab::Git::BLANK_SHA} 570e7b2ab refs/heads/wow",
......@@ -211,9 +211,9 @@ describe Gitlab::GitAccess, lib: true do
target_branch = project.repository.lookup('feature')
source_branch = project.repository.create_file(
user,
FFaker::InternetSE.login_user_name,
FFaker::HipsterIpsum.paragraph,
message: FFaker::HipsterIpsum.sentence,
'John Doe',
'This is the file content',
message: 'This is a good commit message',
branch_name: unprotected_branch)
rugged = project.repository.rugged
author = { email: "email@example.com", time: Time.now, name: "Example Git User" }
......
require 'spec_helper'
describe Gitlab::Git, lib: true do
let(:committer_email) { FFaker::Internet.email }
# I have to remove periods from the end of the name
# This happened when the user's name had a suffix (i.e. "Sr.")
# This seems to be what git does under the hood. For example, this commit:
#
# $ git commit --author='Foo Sr. <foo@example.com>' -m 'Where's my trailing period?'
#
# results in this:
#
# $ git show --pretty
# ...
# Author: Foo Sr <foo@example.com>
# ...
let(:committer_name) { FFaker::Name.name.chomp("\.") }
let(:committer_email) { 'user@example.org' }
let(:committer_name) { 'John Doe' }
describe 'committer_hash' do
it "returns a hash containing the given email and name" do
......
......@@ -37,7 +37,7 @@ describe Notify do
context 'for issues' do
let(:issue) { create(:issue, author: current_user, assignee: assignee, project: project) }
let(:issue_with_description) { create(:issue, author: current_user, assignee: assignee, project: project, description: FFaker::Lorem.sentence) }
let(:issue_with_description) { create(:issue, author: current_user, assignee: assignee, project: project, description: 'My awesome description') }
describe 'that are new' do
subject { Notify.new_issue_email(issue.assignee_id, issue.id) }
......@@ -187,7 +187,7 @@ describe Notify do
let(:project) { create(:project, :repository) }
let(:merge_author) { create(:user) }
let(:merge_request) { create(:merge_request, author: current_user, assignee: assignee, source_project: project, target_project: project) }
let(:merge_request_with_description) { create(:merge_request, author: current_user, assignee: assignee, source_project: project, target_project: project, description: FFaker::Lorem.sentence) }
let(:merge_request_with_description) { create(:merge_request, author: current_user, assignee: assignee, source_project: project, target_project: project, description: 'My awesome description') }
describe 'that are new' do
subject { Notify.new_merge_request_email(merge_request.assignee_id, merge_request.id) }
......
......@@ -13,7 +13,7 @@ describe 'CycleAnalytics#plan', feature: true do
data_fn: -> (context) do
{
issue: context.create(:issue, project: context.project),
branch_name: context.random_git_name
branch_name: context.generate(:branch)
}
end,
start_time_conditions: [["issue associated with a milestone",
......@@ -35,7 +35,7 @@ describe 'CycleAnalytics#plan', feature: true do
context "when a regular label (instead of a list label) is added to the issue" do
it "returns nil" do
branch_name = random_git_name
branch_name = generate(:branch)
label = create(:label)
issue = create(:issue, project: project)
issue.update(label_ids: [label.id])
......
......@@ -23,7 +23,7 @@ describe 'CycleAnalytics#production', feature: true do
# Make other changes on master
sha = context.project.repository.create_file(
context.user,
context.random_git_name,
context.generate(:branch),
'content',
message: 'commit message',
branch_name: 'master')
......
......@@ -28,7 +28,7 @@ describe 'CycleAnalytics#staging', feature: true do
# Make other changes on master
sha = context.project.repository.create_file(
context.user,
context.random_git_name,
context.generate(:branch),
'content',
message: 'commit message',
branch_name: 'master')
......
......@@ -24,21 +24,8 @@ describe Repository, models: true do
repository.commit(merge_commit_id)
end
let(:author_email) { FFaker::Internet.email }
# I have to remove periods from the end of the name
# This happened when the user's name had a suffix (i.e. "Sr.")
# This seems to be what git does under the hood. For example, this commit:
#
# $ git commit --author='Foo Sr. <foo@example.com>' -m 'Where's my trailing period?'
#
# results in this:
#
# $ git show --pretty
# ...
# Author: Foo Sr <foo@example.com>
# ...
let(:author_name) { FFaker::Name.name.chomp("\.") }
let(:author_email) { 'user@example.org' }
let(:author_name) { 'John Doe' }
describe '#branch_names_contains' do
subject { repository.branch_names_contains(sample_commit.id) }
......
......@@ -11,21 +11,8 @@ describe API::Files, api: true do
ref: 'master'
}
end
let(:author_email) { FFaker::Internet.email }
# I have to remove periods from the end of the name
# This happened when the user's name had a suffix (i.e. "Sr.")
# This seems to be what git does under the hood. For example, this commit:
#
# $ git commit --author='Foo Sr. <foo@example.com>' -m 'Where's my trailing period?'
#
# results in this:
#
# $ git show --pretty
# ...
# Author: Foo Sr <foo@example.com>
# ...
let(:author_name) { FFaker::Name.name.chomp("\.") }
let(:author_email) { 'user@example.org' }
let(:author_name) { 'John Doe' }
before { project.team << [user, :developer] }
......
......@@ -19,7 +19,7 @@ describe API::Issues, api: true do
project: project,
state: :closed,
milestone: milestone,
created_at: generate(:issue_created_at),
created_at: generate(:past_time),
updated_at: 3.hours.ago
end
let!(:confidential_issue) do
......@@ -28,7 +28,7 @@ describe API::Issues, api: true do
project: project,
author: author,
assignee: assignee,
created_at: generate(:issue_created_at),
created_at: generate(:past_time),
updated_at: 2.hours.ago
end
let!(:issue) do
......@@ -37,7 +37,7 @@ describe API::Issues, api: true do
assignee: user,
project: project,
milestone: milestone,
created_at: generate(:issue_created_at),
created_at: generate(:past_time),
updated_at: 1.hour.ago
end
let!(:label) do
......
......@@ -3,7 +3,7 @@ require 'spec_helper'
describe API::Members, api: true do
include ApiHelpers
let(:master) { create(:user) }
let(:master) { create(:user, username: 'master_user') }
let(:developer) { create(:user) }
let(:access_requester) { create(:user) }
let(:stranger) { create(:user) }
......
......@@ -341,7 +341,6 @@ describe API::Projects, :api do
it "assigns attributes to project" do
project = attributes_for(:project, {
path: 'camelCasePath',
description: FFaker::Lorem.sentence,
issues_enabled: false,
merge_requests_enabled: false,
wiki_enabled: false,
......@@ -475,7 +474,6 @@ describe API::Projects, :api do
it 'assigns attributes to project' do
project = attributes_for(:project, {
description: FFaker::Lorem.sentence,
issues_enabled: false,
merge_requests_enabled: false,
wiki_enabled: false,
......
......@@ -26,8 +26,8 @@ describe API::V3::Files, api: true do
ref: 'master'
}
end
let(:author_email) { FFaker::Internet.email }
let(:author_name) { FFaker::Name.name.chomp("\.") }
let(:author_email) { 'user@example.org' }
let(:author_name) { 'John Doe' }
before { project.team << [user, :developer] }
......
......@@ -19,7 +19,7 @@ describe API::V3::Issues, api: true do
project: project,
state: :closed,
milestone: milestone,
created_at: generate(:issue_created_at),
created_at: generate(:past_time),
updated_at: 3.hours.ago
end
let!(:confidential_issue) do
......@@ -28,7 +28,7 @@ describe API::V3::Issues, api: true do
project: project,
author: author,
assignee: assignee,
created_at: generate(:issue_created_at),
created_at: generate(:past_time),
updated_at: 2.hours.ago
end
let!(:issue) do
......@@ -37,7 +37,7 @@ describe API::V3::Issues, api: true do
assignee: user,
project: project,
milestone: milestone,
created_at: generate(:issue_created_at),
created_at: generate(:past_time),
updated_at: 1.hour.ago
end
let!(:label) do
......
......@@ -356,7 +356,6 @@ describe API::V3::Projects, api: true do
it "assigns attributes to project" do
project = attributes_for(:project, {
path: 'camelCasePath',
description: FFaker::Lorem.sentence,
issues_enabled: false,
merge_requests_enabled: false,
wiki_enabled: false,
......@@ -501,7 +500,6 @@ describe API::V3::Projects, api: true do
it 'assigns attributes to project' do
project = attributes_for(:project, {
description: FFaker::Lorem.sentence,
issues_enabled: false,
merge_requests_enabled: false,
wiki_enabled: false,
......
module CycleAnalyticsHelpers
def create_commit_referencing_issue(issue, branch_name: random_git_name)
def create_commit_referencing_issue(issue, branch_name: generate(:branch))
project.repository.add_branch(user, branch_name, 'master')
create_commit("Commit for ##{issue.iid}", issue.project, user, branch_name)
end
......@@ -7,9 +7,7 @@ module CycleAnalyticsHelpers
def create_commit(message, project, user, branch_name, count: 1)
oldrev = project.repository.commit(branch_name).sha
commit_shas = Array.new(count) do |index|
filename = random_git_name
commit_sha = project.repository.create_file(user, filename, "content", message: message, branch_name: branch_name)
commit_sha = project.repository.create_file(user, generate(:branch), "content", message: message, branch_name: branch_name)
project.repository.commit(commit_sha)
commit_sha
......@@ -24,13 +22,13 @@ module CycleAnalyticsHelpers
def create_merge_request_closing_issue(issue, message: nil, source_branch: nil)
if !source_branch || project.repository.commit(source_branch).blank?
source_branch = random_git_name
source_branch = generate(:branch)
project.repository.add_branch(user, source_branch, 'master')
end
sha = project.repository.create_file(
user,
random_git_name,
generate(:branch),
'content',
message: 'commit message',
branch_name: source_branch)
......
......@@ -63,9 +63,9 @@ module FilterSpecHelper
#
# Returns a String
def invalidate_reference(reference)
if reference =~ /\A(.+)?.\d+\z/
if reference =~ /\A(.+)?[^\d]\d+\z/
# Integer-based reference with optional project prefix
reference.gsub(/\d+\z/) { |i| i.to_i + 1 }
reference.gsub(/\d+\z/) { |i| i.to_i + 10_000 }
elsif reference =~ /\A(.+@)?(\h{7,40}\z)/
# SHA-based reference with optional prefix
reference.gsub(/\h{7,40}\z/) { |v| v.reverse }
......
module GitHelpers
def random_git_name
"#{FFaker::Product.brand}-#{FFaker::Product.brand}-#{rand(1000)}"
end
end
RSpec.configure do |config|
config.include GitHelpers
end
......@@ -2,12 +2,12 @@ shared_examples 'issuables list meta-data' do |issuable_type, action = nil|
before do
@issuable_ids = []
2.times do
2.times do |n|
issuable =
if issuable_type == :issue
create(issuable_type, project: project)
else
create(issuable_type, title: FFaker::Lorem.sentence, source_project: project, source_branch: FFaker::Name.name)
create(issuable_type, source_project: project, source_branch: "#{n}-feature")
end
@issuable_ids << issuable.id
......
......@@ -7,7 +7,7 @@ shared_examples 'new issuable record that supports slash commands' do
let(:assignee) { create(:user) }
let!(:milestone) { create(:milestone, project: project) }
let!(:labels) { create_list(:label, 3, project: project) }
let(:base_params) { { title: FFaker::Lorem.sentence(3) } }
let(:base_params) { { title: 'My issuable title' } }
let(:params) { base_params.merge(defined?(default_params) ? default_params : {}).merge(example_params) }
let(:issuable) { described_class.new(project, user, params).execute }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment