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 ::AbuseReport.create(reporter: ::User.take, user: reported_user, message: 'User sends spam')
FactoryGirl.create(:abuse_report) print '.'
end
end
end
end
end
end
end end
Db::Fixtures::Development::AbuseReport.seed
...@@ -23,13 +23,13 @@ class Spinach::Features::ProjectHooks < Spinach::FeatureSteps ...@@ -23,13 +23,13 @@ class Spinach::Features::ProjectHooks < Spinach::FeatureSteps
end end
step 'I submit new hook' do step 'I submit new hook' do
@url = FFaker::Internet.uri("http") @url = 'http://example.org/1'
fill_in "hook_url", with: @url fill_in "hook_url", with: @url
expect { click_button "Add Webhook" }.to change(ProjectHook, :count).by(1) expect { click_button "Add Webhook" }.to change(ProjectHook, :count).by(1)
end end
step 'I submit new hook with SSL verification enabled' do 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 fill_in "hook_url", with: @url
check "hook_enable_ssl_verification" check "hook_enable_ssl_verification"
expect { click_button "Add Webhook" }.to change(ProjectHook, :count).by(1) expect { click_button "Add Webhook" }.to change(ProjectHook, :count).by(1)
......
...@@ -12,7 +12,7 @@ describe Profiles::PersonalAccessTokensController do ...@@ -12,7 +12,7 @@ describe Profiles::PersonalAccessTokensController do
end end
it "allows creation of a token with scopes" do it "allows creation of a token with scopes" do
name = FFaker::Product.brand name = 'My PAT'
scopes = %w[api read_user] scopes = %w[api read_user]
post :create, personal_access_token: token_attributes.merge(scopes: scopes, name: name) post :create, personal_access_token: token_attributes.merge(scopes: scopes, name: name)
......
...@@ -6,11 +6,7 @@ FactoryGirl.define do ...@@ -6,11 +6,7 @@ FactoryGirl.define do
team_id 'T0001' team_id 'T0001'
team_domain 'Awesome Team' team_domain 'Awesome Team'
sequence :chat_id do |n| sequence(:chat_id) { |n| "U#{n}" }
"U#{n}" chat_name { generate(:username) }
end
sequence :chat_name do |n|
"user#{n}"
end
end end
end end
FactoryGirl.define do FactoryGirl.define do
factory :chat_team, class: ChatTeam do factory :chat_team, class: ChatTeam do
sequence :team_id do |n| sequence(:team_id) { |n| "abcdefghijklm#{n}" }
"abcdefghijklm#{n}"
end
namespace factory: :group namespace factory: :group
end end
end end
FactoryGirl.define do FactoryGirl.define do
factory :ci_runner, class: Ci::Runner do factory :ci_runner, class: Ci::Runner do
sequence :description do |n| sequence(:description) { |n| "My runner#{n}" }
"My runner#{n}"
end
platform "darwin" platform "darwin"
is_shared false is_shared false
......
FactoryGirl.define do FactoryGirl.define do
factory :email do factory :email do
user user
email { FFaker::Internet.email('alias') } email { generate(:email_alias) }
end end
end end
FactoryGirl.define do FactoryGirl.define do
sequence :issue_created_at do |n|
4.hours.ago + ( 2 * n ).seconds
end
factory :issue do factory :issue do
title title { generate(:title) }
author author
project factory: :empty_project project factory: :empty_project
......
FactoryGirl.define do FactoryGirl.define do
factory :label, class: ProjectLabel do trait :base_label do
sequence(:title) { |n| "label#{n}" } title { generate(:label_title) }
color "#990000" color "#990000"
end
factory :label, traits: [:base_label], class: ProjectLabel do
project factory: :empty_project project factory: :empty_project
transient do transient do
...@@ -15,9 +18,7 @@ FactoryGirl.define do ...@@ -15,9 +18,7 @@ FactoryGirl.define do
end end
end end
factory :group_label, class: GroupLabel do factory :group_label, traits: [:base_label] do
sequence(:title) { |n| "label#{n}" }
color "#990000"
group group
end end
end end
FactoryGirl.define do FactoryGirl.define do
factory :merge_request do factory :merge_request do
title title { generate(:title) }
author author
association :source_project, :repository, factory: :project association :source_project, :repository, factory: :project
target_project { source_project } target_project { source_project }
......
FactoryGirl.define do FactoryGirl.define do
factory :oauth_application, class: 'Doorkeeper::Application', aliases: [:application] 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 } uid { Doorkeeper::OAuth::Helpers::UniqueToken.generate }
redirect_uri { FFaker::Internet.uri('http') } redirect_uri { generate(:url) }
owner owner
owner_type 'User' owner_type 'User'
end end
......
...@@ -2,7 +2,7 @@ FactoryGirl.define do ...@@ -2,7 +2,7 @@ FactoryGirl.define do
factory :personal_access_token do factory :personal_access_token do
user user
token { SecureRandom.hex(50) } token { SecureRandom.hex(50) }
name { FFaker::Product.brand } sequence(:name) { |n| "PAT #{n}" }
revoked false revoked false
expires_at { 5.days.from_now } expires_at { 5.days.from_now }
scopes ['api'] scopes ['api']
......
FactoryGirl.define do FactoryGirl.define do
factory :project_hook do factory :project_hook do
url { FFaker::Internet.uri('http') } url { generate(:url) }
trait :token do trait :token do
token { SecureRandom.hex(10) } 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 FactoryGirl.define do
factory :service_hook do factory :service_hook do
url { FFaker::Internet.uri('http') } url { generate(:url) }
service service
end end
end end
FactoryGirl.define do FactoryGirl.define do
sequence :title, aliases: [:content] do
FFaker::Lorem.sentence
end
sequence :file_name do
FFaker::Internet.user_name
end
factory :snippet do factory :snippet do
author author
title title { generate(:title) }
content content { generate(:title) }
file_name file_name { generate(:filename) }
trait :public do trait :public do
visibility_level Snippet::PUBLIC visibility_level Snippet::PUBLIC
......
FactoryGirl.define do FactoryGirl.define do
factory :spam_log do factory :spam_log do
user user
source_ip { FFaker::Internet.ip_v4_address } sequence(:source_ip) { |n| "42.42.42.#{n % 255}" }
noteable_type 'Issue' noteable_type 'Issue'
title { FFaker::Lorem.sentence } sequence(:title) { |n| "Spam title #{n}" }
description { FFaker::Lorem.paragraph(5) } description { "Spam description\nwith\nmultiple\nlines" }
end end
end end
FactoryGirl.define do FactoryGirl.define do
factory :system_hook do factory :system_hook do
url { FFaker::Internet.uri('http') } url { generate(:url) }
end end
end end
FactoryGirl.define do FactoryGirl.define do
sequence(:name) { FFaker::Name.name }
factory :user, aliases: [:author, :assignee, :recipient, :owner, :creator, :resource_owner] do factory :user, aliases: [:author, :assignee, :recipient, :owner, :creator, :resource_owner] do
email { FFaker::Internet.email } email { generate(:email) }
name name { generate(:name) }
sequence(:username) { |n| "#{FFaker::Internet.user_name}#{n}" } username { generate(:username) }
password "12345678" password "12345678"
confirmed_at { Time.now } confirmed_at { Time.now }
confirmation_token { nil } confirmation_token { nil }
......
require 'spec_helper' require 'spec_helper'
describe 'Admin browse spam logs' do describe 'Admin browse spam logs' do
let!(:spam_log) { create(:spam_log) } let!(:spam_log) { create(:spam_log, description: 'abcde ' * 20) }
before do before do
login_as :admin login_as :admin
......
...@@ -26,7 +26,7 @@ describe "Admin::Hooks", feature: true do ...@@ -26,7 +26,7 @@ describe "Admin::Hooks", feature: true do
end end
describe "New Hook" do describe "New Hook" do
let(:url) { FFaker::Internet.uri('http') } let(:url) { generate(:url) }
it 'adds new hook' do it 'adds new hook' do
visit admin_hooks_path visit admin_hooks_path
......
...@@ -16,7 +16,7 @@ describe 'Admin > Users > Impersonation Tokens', feature: true, js: true do ...@@ -16,7 +16,7 @@ describe 'Admin > Users > Impersonation Tokens', feature: true, js: true do
describe "token creation" do describe "token creation" do
it "allows creation of a token" 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) visit admin_user_impersonation_tokens_path(user_id: user.username)
fill_in "Name", with: name fill_in "Name", with: name
......
...@@ -46,16 +46,16 @@ describe 'issuable list', feature: true do ...@@ -46,16 +46,16 @@ describe 'issuable list', feature: true do
end end
def create_issuables(issuable_type) def create_issuables(issuable_type)
3.times do 3.times do |n|
issuable = issuable =
if issuable_type == :issue if issuable_type == :issue
create(:issue, project: project, author: user) create(:issue, project: project, author: user)
else 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 end
2.times do 2.times do
create(:note_on_issue, noteable: issuable, project: project, note: 'Test note') create(:note_on_issue, noteable: issuable, project: project)
end end
create(:award_emoji, :downvote, awardable: issuable) create(:award_emoji, :downvote, awardable: issuable)
...@@ -65,9 +65,8 @@ describe 'issuable list', feature: true do ...@@ -65,9 +65,8 @@ describe 'issuable list', feature: true do
if issuable_type == :issue if issuable_type == :issue
issue = Issue.reorder(:iid).first issue = Issue.reorder(:iid).first
merge_request = create(:merge_request, merge_request = create(:merge_request,
title: FFaker::Lorem.sentence,
source_project: project, source_project: project,
source_branch: FFaker::Name.name) source_branch: generate(:branch))
MergeRequestsClosingIssues.create!(issue: issue, merge_request: merge_request) MergeRequestsClosingIssues.create!(issue: issue, merge_request: merge_request)
end end
......
...@@ -27,7 +27,7 @@ describe 'Profile > Personal Access Tokens', feature: true, js: true do ...@@ -27,7 +27,7 @@ describe 'Profile > Personal Access Tokens', feature: true, js: true do
describe "token creation" do describe "token creation" do
it "allows creation of a personal access token" do it "allows creation of a personal access token" do
name = FFaker::Product.brand name = 'My PAT'
visit profile_personal_access_tokens_path visit profile_personal_access_tokens_path
fill_in "Name", with: name fill_in "Name", with: name
...@@ -52,7 +52,7 @@ describe 'Profile > Personal Access Tokens', feature: true, js: true do ...@@ -52,7 +52,7 @@ describe 'Profile > Personal Access Tokens', feature: true, js: true do
it "displays an error message" do it "displays an error message" do
disallow_personal_access_token_saves! disallow_personal_access_token_saves!
visit profile_personal_access_tokens_path 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 { click_on "Create Personal Access Token" }.not_to change { PersonalAccessToken.count }
expect(page).to have_content("Name cannot be nil") expect(page).to have_content("Name cannot be nil")
......
require 'spec_helper' 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 include WaitForAjax
before { allow_any_instance_of(U2fHelper).to receive(:inject_u2f_api?).and_return(true) } 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: ...@@ -11,8 +11,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
wait_for_ajax wait_for_ajax
end end
def register_u2f_device(u2f_device = nil) def register_u2f_device(u2f_device = nil, name: 'My device')
name = FFaker::Name.first_name
u2f_device ||= FakeU2fDevice.new(page, name) u2f_device ||= FakeU2fDevice.new(page, name)
u2f_device.respond_to_u2f_registration u2f_device.respond_to_u2f_registration
click_on 'Setup New U2F Device' click_on 'Setup New U2F Device'
...@@ -62,7 +61,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature: ...@@ -62,7 +61,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
expect(page).to have_content('Your U2F device was registered') expect(page).to have_content('Your U2F device was registered')
# Second device # 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('Your U2F device was registered')
expect(page).to have_content(first_device.name) expect(page).to have_content(first_device.name)
...@@ -76,7 +75,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature: ...@@ -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") expect(page).to have_content("You've already enabled two-factor authentication using mobile")
first_u2f_device = register_u2f_device 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 click_on "Delete", match: :first
...@@ -99,7 +98,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature: ...@@ -99,7 +98,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
user.update_attribute(:otp_required_for_login, true) user.update_attribute(:otp_required_for_login, true)
visit profile_account_path visit profile_account_path
manage_two_factor_authentication 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(page).to have_content('Your U2F device was registered')
expect(U2fRegistration.count).to eq(2) expect(U2fRegistration.count).to eq(2)
...@@ -198,7 +197,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature: ...@@ -198,7 +197,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
current_user.update_attribute(:otp_required_for_login, true) current_user.update_attribute(:otp_required_for_login, true)
visit profile_account_path visit profile_account_path
manage_two_factor_authentication manage_two_factor_authentication
register_u2f_device register_u2f_device(name: 'My other device')
logout logout
# Try authenticating user with the old U2F device # Try authenticating user with the old U2F device
...@@ -231,7 +230,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature: ...@@ -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 describe "when a given U2F device has not been registered" do
it "does not allow logging in with that particular device" 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) login_as(user)
unregistered_device.respond_to_u2f_authentication unregistered_device.respond_to_u2f_authentication
expect(page).to have_content('We heard back from your U2F device') 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: ...@@ -252,7 +251,7 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature:
# Register second device # Register second device
visit profile_two_factor_auth_path visit profile_two_factor_auth_path
expect(page).to have_content("Your U2F device needs to be set up.") 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 logout
# Authenticate as both devices # Authenticate as both devices
......
...@@ -183,7 +183,7 @@ describe Gitlab::GitAccess, lib: true do ...@@ -183,7 +183,7 @@ describe Gitlab::GitAccess, lib: true do
describe '#check_push_access!' do describe '#check_push_access!' do
before { merge_into_protected_branch } before { merge_into_protected_branch }
let(:unprotected_branch) { FFaker::Internet.user_name } let(:unprotected_branch) { 'unprotected_branch' }
let(:changes) do let(:changes) do
{ push_new_branch: "#{Gitlab::Git::BLANK_SHA} 570e7b2ab refs/heads/wow", { push_new_branch: "#{Gitlab::Git::BLANK_SHA} 570e7b2ab refs/heads/wow",
...@@ -211,9 +211,9 @@ describe Gitlab::GitAccess, lib: true do ...@@ -211,9 +211,9 @@ describe Gitlab::GitAccess, lib: true do
target_branch = project.repository.lookup('feature') target_branch = project.repository.lookup('feature')
source_branch = project.repository.create_file( source_branch = project.repository.create_file(
user, user,
FFaker::InternetSE.login_user_name, 'John Doe',
FFaker::HipsterIpsum.paragraph, 'This is the file content',
message: FFaker::HipsterIpsum.sentence, message: 'This is a good commit message',
branch_name: unprotected_branch) branch_name: unprotected_branch)
rugged = project.repository.rugged rugged = project.repository.rugged
author = { email: "email@example.com", time: Time.now, name: "Example Git User" } author = { email: "email@example.com", time: Time.now, name: "Example Git User" }
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Git, lib: true do describe Gitlab::Git, lib: true do
let(:committer_email) { FFaker::Internet.email } let(:committer_email) { 'user@example.org' }
let(:committer_name) { 'John Doe' }
# 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("\.") }
describe 'committer_hash' do describe 'committer_hash' do
it "returns a hash containing the given email and name" do it "returns a hash containing the given email and name" do
......
...@@ -37,7 +37,7 @@ describe Notify do ...@@ -37,7 +37,7 @@ describe Notify do
context 'for issues' do context 'for issues' do
let(:issue) { create(:issue, author: current_user, assignee: assignee, project: project) } 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 describe 'that are new' do
subject { Notify.new_issue_email(issue.assignee_id, issue.id) } subject { Notify.new_issue_email(issue.assignee_id, issue.id) }
...@@ -187,7 +187,7 @@ describe Notify do ...@@ -187,7 +187,7 @@ describe Notify do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:merge_author) { create(:user) } 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) { 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 describe 'that are new' do
subject { Notify.new_merge_request_email(merge_request.assignee_id, merge_request.id) } subject { Notify.new_merge_request_email(merge_request.assignee_id, merge_request.id) }
......
...@@ -13,7 +13,7 @@ describe 'CycleAnalytics#plan', feature: true do ...@@ -13,7 +13,7 @@ describe 'CycleAnalytics#plan', feature: true do
data_fn: -> (context) do data_fn: -> (context) do
{ {
issue: context.create(:issue, project: context.project), issue: context.create(:issue, project: context.project),
branch_name: context.random_git_name branch_name: context.generate(:branch)
} }
end, end,
start_time_conditions: [["issue associated with a milestone", start_time_conditions: [["issue associated with a milestone",
...@@ -35,7 +35,7 @@ describe 'CycleAnalytics#plan', feature: true do ...@@ -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 context "when a regular label (instead of a list label) is added to the issue" do
it "returns nil" do it "returns nil" do
branch_name = random_git_name branch_name = generate(:branch)
label = create(:label) label = create(:label)
issue = create(:issue, project: project) issue = create(:issue, project: project)
issue.update(label_ids: [label.id]) issue.update(label_ids: [label.id])
......
...@@ -23,7 +23,7 @@ describe 'CycleAnalytics#production', feature: true do ...@@ -23,7 +23,7 @@ describe 'CycleAnalytics#production', feature: true do
# Make other changes on master # Make other changes on master
sha = context.project.repository.create_file( sha = context.project.repository.create_file(
context.user, context.user,
context.random_git_name, context.generate(:branch),
'content', 'content',
message: 'commit message', message: 'commit message',
branch_name: 'master') branch_name: 'master')
......
...@@ -28,7 +28,7 @@ describe 'CycleAnalytics#staging', feature: true do ...@@ -28,7 +28,7 @@ describe 'CycleAnalytics#staging', feature: true do
# Make other changes on master # Make other changes on master
sha = context.project.repository.create_file( sha = context.project.repository.create_file(
context.user, context.user,
context.random_git_name, context.generate(:branch),
'content', 'content',
message: 'commit message', message: 'commit message',
branch_name: 'master') branch_name: 'master')
......
...@@ -24,21 +24,8 @@ describe Repository, models: true do ...@@ -24,21 +24,8 @@ describe Repository, models: true do
repository.commit(merge_commit_id) repository.commit(merge_commit_id)
end end
let(:author_email) { FFaker::Internet.email } let(:author_email) { 'user@example.org' }
let(:author_name) { 'John Doe' }
# 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("\.") }
describe '#branch_names_contains' do describe '#branch_names_contains' do
subject { repository.branch_names_contains(sample_commit.id) } subject { repository.branch_names_contains(sample_commit.id) }
......
...@@ -11,21 +11,8 @@ describe API::Files, api: true do ...@@ -11,21 +11,8 @@ describe API::Files, api: true do
ref: 'master' ref: 'master'
} }
end end
let(:author_email) { FFaker::Internet.email } let(:author_email) { 'user@example.org' }
let(:author_name) { 'John Doe' }
# 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("\.") }
before { project.team << [user, :developer] } before { project.team << [user, :developer] }
......
...@@ -19,7 +19,7 @@ describe API::Issues, api: true do ...@@ -19,7 +19,7 @@ describe API::Issues, api: true do
project: project, project: project,
state: :closed, state: :closed,
milestone: milestone, milestone: milestone,
created_at: generate(:issue_created_at), created_at: generate(:past_time),
updated_at: 3.hours.ago updated_at: 3.hours.ago
end end
let!(:confidential_issue) do let!(:confidential_issue) do
...@@ -28,7 +28,7 @@ describe API::Issues, api: true do ...@@ -28,7 +28,7 @@ describe API::Issues, api: true do
project: project, project: project,
author: author, author: author,
assignee: assignee, assignee: assignee,
created_at: generate(:issue_created_at), created_at: generate(:past_time),
updated_at: 2.hours.ago updated_at: 2.hours.ago
end end
let!(:issue) do let!(:issue) do
...@@ -37,7 +37,7 @@ describe API::Issues, api: true do ...@@ -37,7 +37,7 @@ describe API::Issues, api: true do
assignee: user, assignee: user,
project: project, project: project,
milestone: milestone, milestone: milestone,
created_at: generate(:issue_created_at), created_at: generate(:past_time),
updated_at: 1.hour.ago updated_at: 1.hour.ago
end end
let!(:label) do let!(:label) do
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe API::Members, api: true do describe API::Members, api: true do
include ApiHelpers include ApiHelpers
let(:master) { create(:user) } let(:master) { create(:user, username: 'master_user') }
let(:developer) { create(:user) } let(:developer) { create(:user) }
let(:access_requester) { create(:user) } let(:access_requester) { create(:user) }
let(:stranger) { create(:user) } let(:stranger) { create(:user) }
......
...@@ -341,7 +341,6 @@ describe API::Projects, :api do ...@@ -341,7 +341,6 @@ describe API::Projects, :api do
it "assigns attributes to project" do it "assigns attributes to project" do
project = attributes_for(:project, { project = attributes_for(:project, {
path: 'camelCasePath', path: 'camelCasePath',
description: FFaker::Lorem.sentence,
issues_enabled: false, issues_enabled: false,
merge_requests_enabled: false, merge_requests_enabled: false,
wiki_enabled: false, wiki_enabled: false,
...@@ -475,7 +474,6 @@ describe API::Projects, :api do ...@@ -475,7 +474,6 @@ describe API::Projects, :api do
it 'assigns attributes to project' do it 'assigns attributes to project' do
project = attributes_for(:project, { project = attributes_for(:project, {
description: FFaker::Lorem.sentence,
issues_enabled: false, issues_enabled: false,
merge_requests_enabled: false, merge_requests_enabled: false,
wiki_enabled: false, wiki_enabled: false,
......
...@@ -26,8 +26,8 @@ describe API::V3::Files, api: true do ...@@ -26,8 +26,8 @@ describe API::V3::Files, api: true do
ref: 'master' ref: 'master'
} }
end end
let(:author_email) { FFaker::Internet.email } let(:author_email) { 'user@example.org' }
let(:author_name) { FFaker::Name.name.chomp("\.") } let(:author_name) { 'John Doe' }
before { project.team << [user, :developer] } before { project.team << [user, :developer] }
......
...@@ -19,7 +19,7 @@ describe API::V3::Issues, api: true do ...@@ -19,7 +19,7 @@ describe API::V3::Issues, api: true do
project: project, project: project,
state: :closed, state: :closed,
milestone: milestone, milestone: milestone,
created_at: generate(:issue_created_at), created_at: generate(:past_time),
updated_at: 3.hours.ago updated_at: 3.hours.ago
end end
let!(:confidential_issue) do let!(:confidential_issue) do
...@@ -28,7 +28,7 @@ describe API::V3::Issues, api: true do ...@@ -28,7 +28,7 @@ describe API::V3::Issues, api: true do
project: project, project: project,
author: author, author: author,
assignee: assignee, assignee: assignee,
created_at: generate(:issue_created_at), created_at: generate(:past_time),
updated_at: 2.hours.ago updated_at: 2.hours.ago
end end
let!(:issue) do let!(:issue) do
...@@ -37,7 +37,7 @@ describe API::V3::Issues, api: true do ...@@ -37,7 +37,7 @@ describe API::V3::Issues, api: true do
assignee: user, assignee: user,
project: project, project: project,
milestone: milestone, milestone: milestone,
created_at: generate(:issue_created_at), created_at: generate(:past_time),
updated_at: 1.hour.ago updated_at: 1.hour.ago
end end
let!(:label) do let!(:label) do
......
...@@ -356,7 +356,6 @@ describe API::V3::Projects, api: true do ...@@ -356,7 +356,6 @@ describe API::V3::Projects, api: true do
it "assigns attributes to project" do it "assigns attributes to project" do
project = attributes_for(:project, { project = attributes_for(:project, {
path: 'camelCasePath', path: 'camelCasePath',
description: FFaker::Lorem.sentence,
issues_enabled: false, issues_enabled: false,
merge_requests_enabled: false, merge_requests_enabled: false,
wiki_enabled: false, wiki_enabled: false,
...@@ -501,7 +500,6 @@ describe API::V3::Projects, api: true do ...@@ -501,7 +500,6 @@ describe API::V3::Projects, api: true do
it 'assigns attributes to project' do it 'assigns attributes to project' do
project = attributes_for(:project, { project = attributes_for(:project, {
description: FFaker::Lorem.sentence,
issues_enabled: false, issues_enabled: false,
merge_requests_enabled: false, merge_requests_enabled: false,
wiki_enabled: false, wiki_enabled: false,
......
module CycleAnalyticsHelpers 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') project.repository.add_branch(user, branch_name, 'master')
create_commit("Commit for ##{issue.iid}", issue.project, user, branch_name) create_commit("Commit for ##{issue.iid}", issue.project, user, branch_name)
end end
...@@ -7,9 +7,7 @@ module CycleAnalyticsHelpers ...@@ -7,9 +7,7 @@ module CycleAnalyticsHelpers
def create_commit(message, project, user, branch_name, count: 1) def create_commit(message, project, user, branch_name, count: 1)
oldrev = project.repository.commit(branch_name).sha oldrev = project.repository.commit(branch_name).sha
commit_shas = Array.new(count) do |index| commit_shas = Array.new(count) do |index|
filename = random_git_name commit_sha = project.repository.create_file(user, generate(:branch), "content", message: message, branch_name: branch_name)
commit_sha = project.repository.create_file(user, filename, "content", message: message, branch_name: branch_name)
project.repository.commit(commit_sha) project.repository.commit(commit_sha)
commit_sha commit_sha
...@@ -24,13 +22,13 @@ module CycleAnalyticsHelpers ...@@ -24,13 +22,13 @@ module CycleAnalyticsHelpers
def create_merge_request_closing_issue(issue, message: nil, source_branch: nil) def create_merge_request_closing_issue(issue, message: nil, source_branch: nil)
if !source_branch || project.repository.commit(source_branch).blank? 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') project.repository.add_branch(user, source_branch, 'master')
end end
sha = project.repository.create_file( sha = project.repository.create_file(
user, user,
random_git_name, generate(:branch),
'content', 'content',
message: 'commit message', message: 'commit message',
branch_name: source_branch) branch_name: source_branch)
......
...@@ -63,9 +63,9 @@ module FilterSpecHelper ...@@ -63,9 +63,9 @@ module FilterSpecHelper
# #
# Returns a String # Returns a String
def invalidate_reference(reference) def invalidate_reference(reference)
if reference =~ /\A(.+)?.\d+\z/ if reference =~ /\A(.+)?[^\d]\d+\z/
# Integer-based reference with optional project prefix # 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)/ elsif reference =~ /\A(.+@)?(\h{7,40}\z)/
# SHA-based reference with optional prefix # SHA-based reference with optional prefix
reference.gsub(/\h{7,40}\z/) { |v| v.reverse } 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| ...@@ -2,12 +2,12 @@ shared_examples 'issuables list meta-data' do |issuable_type, action = nil|
before do before do
@issuable_ids = [] @issuable_ids = []
2.times do 2.times do |n|
issuable = issuable =
if issuable_type == :issue if issuable_type == :issue
create(issuable_type, project: project) create(issuable_type, project: project)
else 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 end
@issuable_ids << issuable.id @issuable_ids << issuable.id
......
...@@ -7,7 +7,7 @@ shared_examples 'new issuable record that supports slash commands' do ...@@ -7,7 +7,7 @@ shared_examples 'new issuable record that supports slash commands' do
let(:assignee) { create(:user) } let(:assignee) { create(:user) }
let!(:milestone) { create(:milestone, project: project) } let!(:milestone) { create(:milestone, project: project) }
let!(:labels) { create_list(:label, 3, 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(:params) { base_params.merge(defined?(default_params) ? default_params : {}).merge(example_params) }
let(:issuable) { described_class.new(project, user, params).execute } 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