Commit 8f153fe2 authored by Rémy Coutable's avatar Rémy Coutable

Fix brittle specs

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 2a1868b7
FactoryGirl.define do FactoryGirl.define do
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 :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 }
......
...@@ -3,6 +3,8 @@ FactoryGirl.define do ...@@ -3,6 +3,8 @@ FactoryGirl.define do
sequence(:name) { |n| "John Doe#{n}" } sequence(:name) { |n| "John Doe#{n}" }
sequence(:email) { |n| "user#{n}@example.org" } sequence(:email) { |n| "user#{n}@example.org" }
sequence(:email_alias) { |n| "user.alias#{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(:url) { |n| "http://example#{n}.org" }
sequence(:label) { |n| "label#{n}" } sequence(:label) { |n| "label#{n}" }
sequence(:branch) { |n| "my-branch-#{n}" } sequence(:branch) { |n| "my-branch-#{n}" }
......
FactoryGirl.define do FactoryGirl.define do
sequence(:title, aliases: [:content]) { |n| "My snippet #{n}" }
sequence(:file_name) { |n| "snippet-#{n}.rb" }
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
......
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
......
...@@ -51,7 +51,7 @@ describe 'issuable list', feature: true do ...@@ -51,7 +51,7 @@ describe 'issuable list', feature: true do
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, source_project: project, source_branch: "#{n}-feature") create(:merge_request, source_project: project, source_branch: generate(:branch))
end end
2.times do 2.times do
...@@ -66,7 +66,7 @@ describe 'issuable list', feature: true do ...@@ -66,7 +66,7 @@ describe 'issuable list', feature: true do
issue = Issue.reorder(:iid).first issue = Issue.reorder(:iid).first
merge_request = create(:merge_request, merge_request = create(:merge_request,
source_project: project, source_project: project,
source_branch: 'my-bug-fix') source_branch: generate(:branch))
MergeRequestsClosingIssues.create!(issue: issue, merge_request: merge_request) MergeRequestsClosingIssues.create!(issue: issue, merge_request: merge_request)
end end
......
module CycleAnalyticsHelpers module CycleAnalyticsHelpers
def create_commit_referencing_issue(issue, branch_name: nil) def create_commit_referencing_issue(issue, branch_name: generate(:branch))
project.repository.add_branch(user, branch_name || generate(:branch), '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
......
...@@ -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 }
......
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