Commit 07b9b80a authored by Lin Jen-Shin's avatar Lin Jen-Shin

Fix tests to use the new API

parent 8384d0d8
...@@ -3,29 +3,31 @@ require 'securerandom' ...@@ -3,29 +3,31 @@ require 'securerandom'
# Compare 2 branches for one repo or between repositories # Compare 2 branches for one repo or between repositories
# and return Gitlab::Git::Compare object that responds to commits and diffs # and return Gitlab::Git::Compare object that responds to commits and diffs
class CompareService class CompareService
attr_reader :source_project, :source_sha attr_reader :source_project, :source_branch
def initialize(new_source_project, source_branch) def initialize(new_source_project, source_branch_name)
@source_project = new_source_project @source_project = new_source_project
@source_sha = new_source_project.commit(source_branch).try(:sha) @source_branch = new_source_project.commit(source_branch_name)
end end
def execute(target_project, target_branch, straight: false) def execute(target_project, target_branch, straight: false)
source_sha = source_branch.try(:sha)
return unless source_sha return unless source_sha
# If compare with other project we need to fetch ref first # If compare with other project we need to fetch ref first
if target_project == source_project if target_project == source_project
compare(target_project, target_branch, straight) compare(source_sha, target_project, target_branch, straight)
else else
target_project.repository.with_tmp_ref(source_project, source_branch) do target_project.repository.with_tmp_ref(source_project, source_branch) do
compare(target_project, target_branch, straight) compare(source_sha, target_project, target_branch, straight)
end end
end end
end end
private private
def compare(target_project, target_branch, straight) def compare(source_sha, target_project, target_branch, straight)
raw_compare = Gitlab::Git::Compare.new( raw_compare = Gitlab::Git::Compare.new(
target_project.repository.raw_repository, target_project.repository.raw_repository,
target_branch, target_branch,
......
...@@ -14,7 +14,8 @@ describe Projects::TemplatesController do ...@@ -14,7 +14,8 @@ describe Projects::TemplatesController do
before do before do
project.add_user(user, Gitlab::Access::MASTER) project.add_user(user, Gitlab::Access::MASTER)
project.repository.commit_file(user, file_path_1, "something valid", "test 3", "master", false) project.repository.commit_file(user, file_path_1, 'something valid',
message: 'test 3', branch_name: 'master', update: false)
end end
describe '#show' do describe '#show' do
......
...@@ -91,8 +91,40 @@ FactoryGirl.define do ...@@ -91,8 +91,40 @@ FactoryGirl.define do
factory :project, parent: :empty_project do factory :project, parent: :empty_project do
path { 'gitlabhq' } path { 'gitlabhq' }
after :create do |project| transient do
create_template nil
end
after :create do |project, evaluator|
TestEnv.copy_repo(project) TestEnv.copy_repo(project)
if evaluator.create_template
args = evaluator.create_template
project.add_user(args[:user], args[:access])
project.repository.commit_file(
args[:user],
".gitlab/#{args[:path]}/bug.md",
'something valid',
message: 'test 3',
branch_name: 'master',
update: false)
project.repository.commit_file(
args[:user],
".gitlab/#{args[:path]}/template_test.md",
'template_test',
message: 'test 1',
branch_name: 'master',
update: false)
project.repository.commit_file(
args[:user],
".gitlab/#{args[:path]}/feature_proposal.md",
'feature_proposal',
message: 'test 2',
branch_name: 'master',
update: false)
end
end end
end end
......
...@@ -6,7 +6,8 @@ feature 'project owner creates a license file', feature: true, js: true do ...@@ -6,7 +6,8 @@ feature 'project owner creates a license file', feature: true, js: true do
let(:project_master) { create(:user) } let(:project_master) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
background do background do
project.repository.remove_file(project_master, 'LICENSE', 'Remove LICENSE', 'master') project.repository.remove_file(project_master, 'LICENSE',
message: 'Remove LICENSE', branch_name: 'master')
project.team << [project_master, :master] project.team << [project_master, :master]
login_as(project_master) login_as(project_master)
visit namespace_project_path(project.namespace, project) visit namespace_project_path(project.namespace, project)
......
...@@ -18,8 +18,20 @@ feature 'issuable templates', feature: true, js: true do ...@@ -18,8 +18,20 @@ feature 'issuable templates', feature: true, js: true do
let(:description_addition) { ' appending to description' } let(:description_addition) { ' appending to description' }
background do background do
project.repository.commit_file(user, '.gitlab/issue_templates/bug.md', template_content, 'added issue template', 'master', false) project.repository.commit_file(
project.repository.commit_file(user, '.gitlab/issue_templates/test.md', longtemplate_content, 'added issue template', 'master', false) user,
'.gitlab/issue_templates/bug.md',
template_content,
message: 'added issue template',
branch_name: 'master',
update: false)
project.repository.commit_file(
user,
'.gitlab/issue_templates/test.md',
longtemplate_content,
message: 'added issue template',
branch_name: 'master',
update: false)
visit edit_namespace_project_issue_path project.namespace, project, issue visit edit_namespace_project_issue_path project.namespace, project, issue
fill_in :'issue[title]', with: 'test issue title' fill_in :'issue[title]', with: 'test issue title'
end end
...@@ -68,7 +80,13 @@ feature 'issuable templates', feature: true, js: true do ...@@ -68,7 +80,13 @@ feature 'issuable templates', feature: true, js: true do
let(:issue) { create(:issue, author: user, assignee: user, project: project) } let(:issue) { create(:issue, author: user, assignee: user, project: project) }
background do background do
project.repository.commit_file(user, '.gitlab/issue_templates/bug.md', template_content, 'added issue template', 'master', false) project.repository.commit_file(
user,
'.gitlab/issue_templates/bug.md',
template_content,
message: 'added issue template',
branch_name: 'master',
update: false)
visit edit_namespace_project_issue_path project.namespace, project, issue visit edit_namespace_project_issue_path project.namespace, project, issue
fill_in :'issue[title]', with: 'test issue title' fill_in :'issue[title]', with: 'test issue title'
fill_in :'issue[description]', with: prior_description fill_in :'issue[description]', with: prior_description
...@@ -87,7 +105,13 @@ feature 'issuable templates', feature: true, js: true do ...@@ -87,7 +105,13 @@ feature 'issuable templates', feature: true, js: true do
let(:merge_request) { create(:merge_request, :with_diffs, source_project: project) } let(:merge_request) { create(:merge_request, :with_diffs, source_project: project) }
background do background do
project.repository.commit_file(user, '.gitlab/merge_request_templates/feature-proposal.md', template_content, 'added merge request template', 'master', false) project.repository.commit_file(
user,
'.gitlab/merge_request_templates/feature-proposal.md',
template_content,
message: 'added merge request template',
branch_name: 'master',
update: false)
visit edit_namespace_project_merge_request_path project.namespace, project, merge_request visit edit_namespace_project_merge_request_path project.namespace, project, merge_request
fill_in :'merge_request[title]', with: 'test merge request title' fill_in :'merge_request[title]', with: 'test merge request title'
end end
...@@ -112,7 +136,13 @@ feature 'issuable templates', feature: true, js: true do ...@@ -112,7 +136,13 @@ feature 'issuable templates', feature: true, js: true do
fork_project.team << [fork_user, :master] fork_project.team << [fork_user, :master]
create(:forked_project_link, forked_to_project: fork_project, forked_from_project: project) create(:forked_project_link, forked_to_project: fork_project, forked_from_project: project)
login_as fork_user login_as fork_user
project.repository.commit_file(fork_user, '.gitlab/merge_request_templates/feature-proposal.md', template_content, 'added merge request template', 'master', false) project.repository.commit_file(
fork_user,
'.gitlab/merge_request_templates/feature-proposal.md',
template_content,
message: 'added merge request template',
branch_name: 'master',
update: false)
visit edit_namespace_project_merge_request_path project.namespace, project, merge_request visit edit_namespace_project_merge_request_path project.namespace, project, merge_request
fill_in :'merge_request[title]', with: 'test merge request title' fill_in :'merge_request[title]', with: 'test merge request title'
end end
......
...@@ -209,7 +209,13 @@ describe Gitlab::GitAccess, lib: true do ...@@ -209,7 +209,13 @@ describe Gitlab::GitAccess, lib: true do
stub_git_hooks stub_git_hooks
project.repository.add_branch(user, unprotected_branch, 'feature') project.repository.add_branch(user, unprotected_branch, 'feature')
target_branch = project.repository.lookup('feature') target_branch = project.repository.lookup('feature')
source_branch = project.repository.commit_file(user, FFaker::InternetSE.login_user_name, FFaker::HipsterIpsum.paragraph, FFaker::HipsterIpsum.sentence, unprotected_branch, false) source_branch = project.repository.commit_file(
user,
FFaker::InternetSE.login_user_name,
FFaker::HipsterIpsum.paragraph,
message: FFaker::HipsterIpsum.sentence,
branch_name: unprotected_branch,
update: false)
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" }
......
...@@ -4,16 +4,15 @@ describe Gitlab::Template::IssueTemplate do ...@@ -4,16 +4,15 @@ describe Gitlab::Template::IssueTemplate do
subject { described_class } subject { described_class }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) }
let(:file_path_1) { '.gitlab/issue_templates/bug.md' } let(:project) do
let(:file_path_2) { '.gitlab/issue_templates/template_test.md' } create(:project,
let(:file_path_3) { '.gitlab/issue_templates/feature_proposal.md' } create_template: {
user: user,
before do access: Gitlab::Access::MASTER,
project.add_user(user, Gitlab::Access::MASTER) path: 'issue_templates'
project.repository.commit_file(user, file_path_1, "something valid", "test 3", "master", false) }
project.repository.commit_file(user, file_path_2, "template_test", "test 1", "master", false) )
project.repository.commit_file(user, file_path_3, "feature_proposal", "test 2", "master", false)
end end
describe '.all' do describe '.all' do
......
...@@ -4,16 +4,15 @@ describe Gitlab::Template::MergeRequestTemplate do ...@@ -4,16 +4,15 @@ describe Gitlab::Template::MergeRequestTemplate do
subject { described_class } subject { described_class }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) }
let(:file_path_1) { '.gitlab/merge_request_templates/bug.md' } let(:project) do
let(:file_path_2) { '.gitlab/merge_request_templates/template_test.md' } create(:project,
let(:file_path_3) { '.gitlab/merge_request_templates/feature_proposal.md' } create_template: {
user: user,
before do access: Gitlab::Access::MASTER,
project.add_user(user, Gitlab::Access::MASTER) path: 'merge_request_templates'
project.repository.commit_file(user, file_path_1, "something valid", "test 3", "master", false) }
project.repository.commit_file(user, file_path_2, "template_test", "test 1", "master", false) )
project.repository.commit_file(user, file_path_3, "feature_proposal", "test 2", "master", false)
end end
describe '.all' do describe '.all' do
......
...@@ -21,7 +21,13 @@ describe 'CycleAnalytics#production', feature: true do ...@@ -21,7 +21,13 @@ describe 'CycleAnalytics#production', feature: true do
["production deploy happens after merge request is merged (along with other changes)", ["production deploy happens after merge request is merged (along with other changes)",
lambda do |context, data| lambda do |context, data|
# Make other changes on master # Make other changes on master
sha = context.project.repository.commit_file(context.user, context.random_git_name, "content", "commit message", 'master', false) sha = context.project.repository.commit_file(
context.user,
context.random_git_name,
'content',
message: 'commit message',
branch_name: 'master',
update: false)
context.project.repository.commit(sha) context.project.repository.commit(sha)
context.deploy_master context.deploy_master
......
...@@ -28,10 +28,10 @@ describe 'CycleAnalytics#staging', feature: true do ...@@ -28,10 +28,10 @@ describe 'CycleAnalytics#staging', feature: true do
sha = context.project.repository.commit_file( sha = context.project.repository.commit_file(
context.user, context.user,
context.random_git_name, context.random_git_name,
"content", 'content',
"commit message", message: 'commit message',
'master', branch_name: 'master',
false) update: false)
context.project.repository.commit(sha) context.project.repository.commit(sha)
context.deploy_master context.deploy_master
......
...@@ -66,7 +66,13 @@ describe MergeRequests::ResolveService do ...@@ -66,7 +66,13 @@ describe MergeRequests::ResolveService do
context 'when the source project is a fork and does not contain the HEAD of the target branch' do context 'when the source project is a fork and does not contain the HEAD of the target branch' do
let!(:target_head) do let!(:target_head) do
project.repository.commit_file(user, 'new-file-in-target', '', 'Add new file in target', 'conflict-start', false) project.repository.commit_file(
user,
'new-file-in-target',
'',
message: 'Add new file in target',
branch_name: 'conflict-start',
update: false)
end end
before do before do
......
...@@ -35,7 +35,13 @@ module CycleAnalyticsHelpers ...@@ -35,7 +35,13 @@ module CycleAnalyticsHelpers
project.repository.add_branch(user, source_branch, 'master') project.repository.add_branch(user, source_branch, 'master')
end end
sha = project.repository.commit_file(user, random_git_name, "content", "commit message", source_branch, false) sha = project.repository.commit_file(
user,
random_git_name,
'content',
message: 'commit message',
branch_name: source_branch,
update: false)
project.repository.commit(sha) project.repository.commit(sha)
opts = { opts = {
......
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