2012-04-16 19:40:50 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-04-19 20:08:33 +01:00
|
|
|
def set_data_for_pull
|
2014-01-21 04:51:49 +00:00
|
|
|
@project = FactoryGirl.create(:project_with_commit, owner: @user)
|
2012-04-19 20:08:33 +01:00
|
|
|
|
|
|
|
@clone_path = File.join(APP_CONFIG['root_path'], 'repo_clone', @project.id.to_s)
|
|
|
|
FileUtils.mkdir_p(@clone_path)
|
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
@other_project = FactoryGirl.create(:project_with_commit, owner: @user)
|
2012-04-19 20:08:33 +01:00
|
|
|
|
2015-02-19 01:28:02 +00:00
|
|
|
allow_any_instance_of(Project).to receive(:versions).and_return(%w(v1.0 v2.0))
|
2012-04-19 20:08:33 +01:00
|
|
|
end
|
|
|
|
|
2012-04-16 19:40:50 +01:00
|
|
|
describe PullRequest do
|
2014-10-20 20:18:34 +01:00
|
|
|
before { stub_symlink_methods }
|
|
|
|
|
2012-04-19 20:08:33 +01:00
|
|
|
context 'for owner user' do
|
2012-10-01 13:29:36 +01:00
|
|
|
before do
|
2012-04-19 20:08:33 +01:00
|
|
|
@user = FactoryGirl.create(:user)
|
|
|
|
set_data_for_pull
|
2014-01-21 04:51:49 +00:00
|
|
|
@pull = @project.pull_requests.new(issue_attributes: {title: 'test', body: 'testing'})
|
2012-10-03 13:18:02 +01:00
|
|
|
@pull.issue.user, @pull.issue.project = @user, @pull.to_project
|
|
|
|
@pull.to_ref = 'master'
|
|
|
|
@pull.from_project, @pull.from_ref = @project, 'non_conflicts'
|
2012-04-19 20:08:33 +01:00
|
|
|
@pull.save
|
2012-04-28 18:28:57 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
@other_pull = @project.pull_requests.new(issue_attributes: {title: 'test_other', body: 'testing_other'})
|
2012-10-03 13:18:02 +01:00
|
|
|
@other_pull.issue.user, @other_pull.issue.project = @user, @other_pull.to_project
|
|
|
|
@other_pull.to_ref = 'master'
|
|
|
|
@other_pull.from_project, @other_pull.from_ref = @other_project, 'non_conflicts'
|
2012-04-28 18:28:57 +01:00
|
|
|
@other_pull.save
|
2012-04-19 20:08:33 +01:00
|
|
|
end
|
|
|
|
|
2013-08-13 16:56:27 +01:00
|
|
|
it 'ensures that path to pull_request repository has been changed after rename of project' do
|
|
|
|
@pull.check
|
2014-01-21 04:51:49 +00:00
|
|
|
@project.update_attributes(name: "#{@project.name}-new")
|
2013-08-13 16:56:27 +01:00
|
|
|
@pull.reload
|
2015-04-13 10:03:27 +01:00
|
|
|
expect(Dir.exists? @pull.path).to be_truthy
|
2013-08-13 16:56:27 +01:00
|
|
|
end
|
|
|
|
|
2012-05-23 17:09:11 +01:00
|
|
|
it 'master should merge with non_conflicts branch' do
|
2012-04-19 20:08:33 +01:00
|
|
|
@pull.check
|
2015-04-13 10:03:27 +01:00
|
|
|
expect(@pull.status).to eq('ready')
|
2012-04-19 20:08:33 +01:00
|
|
|
end
|
|
|
|
|
2012-05-23 17:09:11 +01:00
|
|
|
it 'master should not merge with conflicts branch' do
|
2012-10-03 13:18:02 +01:00
|
|
|
@pull.from_ref = 'conflicts'
|
2012-04-19 20:08:33 +01:00
|
|
|
@pull.check
|
2015-04-13 10:03:27 +01:00
|
|
|
expect(@pull.status).to eq('blocked')
|
2012-04-19 20:08:33 +01:00
|
|
|
end
|
|
|
|
|
2012-06-09 10:09:38 +01:00
|
|
|
it 'should already merged when already up-to-date branches' do
|
2012-10-03 13:18:02 +01:00
|
|
|
@pull.from_ref = 'master'
|
2012-04-19 20:08:33 +01:00
|
|
|
@pull.check
|
2015-04-13 10:03:27 +01:00
|
|
|
expect(@pull.status).to eq('merged')
|
2012-04-19 20:08:33 +01:00
|
|
|
end
|
2012-04-28 18:28:57 +01:00
|
|
|
|
|
|
|
context 'for other head project' do
|
2012-05-23 17:09:11 +01:00
|
|
|
it 'master should merge with non_conflicts branch' do
|
2012-04-28 18:28:57 +01:00
|
|
|
@other_pull.check
|
2015-04-13 10:03:27 +01:00
|
|
|
expect(@other_pull.status).to eq('ready')
|
2012-04-28 18:28:57 +01:00
|
|
|
end
|
|
|
|
|
2012-05-23 17:09:11 +01:00
|
|
|
it 'master should not merge with conflicts branch' do
|
2012-10-03 13:18:02 +01:00
|
|
|
@other_pull.from_ref = 'conflicts'
|
2012-05-02 16:36:39 +01:00
|
|
|
@other_pull.check
|
2015-04-13 10:03:27 +01:00
|
|
|
expect(@other_pull.status).to eq('blocked')
|
2012-04-28 18:28:57 +01:00
|
|
|
end
|
|
|
|
|
2012-06-09 10:09:38 +01:00
|
|
|
it 'should already merged when already up-to-date branches' do
|
2012-10-03 13:18:02 +01:00
|
|
|
@other_pull.from_ref = 'master'
|
2012-05-02 16:36:39 +01:00
|
|
|
@other_pull.check
|
2015-04-13 10:03:27 +01:00
|
|
|
expect(@other_pull.status).to eq('merged')
|
2012-04-28 18:28:57 +01:00
|
|
|
end
|
|
|
|
end
|
2012-05-21 14:24:16 +01:00
|
|
|
|
2012-05-23 17:09:11 +01:00
|
|
|
it "should not create same pull" do
|
2015-04-13 10:03:27 +01:00
|
|
|
expect {
|
|
|
|
@same_pull = @project.pull_requests.new(issue_attributes: {title: 'same', body: 'testing'})
|
|
|
|
@same_pull.issue.user, @same_pull.issue.project = @user, @same_pull.to_project
|
|
|
|
@same_pull.to_ref = 'master'
|
|
|
|
@same_pull.from_project, @same_pull.from_ref = @project, 'non_conflicts'
|
|
|
|
@same_pull.save
|
|
|
|
}.to change { PullRequest.count }.by(0)
|
|
|
|
#expect(@project.pull_requests.joins(:issue).where(issues: {title: @same_pull.title}).count).to == 0
|
2012-05-21 14:24:16 +01:00
|
|
|
end
|
|
|
|
|
2012-05-23 17:09:11 +01:00
|
|
|
it "should not create pull with wrong base ref" do
|
2015-04-13 10:03:27 +01:00
|
|
|
expect {
|
|
|
|
@wrong_pull = @project.pull_requests.new(issue_attributes: {title: 'wrong base', body: 'testing'})
|
|
|
|
@wrong_pull.issue.user, @wrong_pull.issue.project = @user, @wrong_pull.to_project
|
|
|
|
@wrong_pull.to_ref = 'wrong'
|
|
|
|
@wrong_pull.from_project, @wrong_pull.from_ref = @project, 'non_conflicts'
|
|
|
|
@wrong_pull.save
|
|
|
|
}.to change { PullRequest.count }.by(0)
|
2012-05-23 17:09:11 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not create pull with wrong head ref" do
|
2015-04-13 10:03:27 +01:00
|
|
|
expect {
|
|
|
|
@wrong_pull = @project.pull_requests.new(issue_attributes: {title: 'wrong head', body: 'testing'})
|
|
|
|
@wrong_pull.issue.user, @wrong_pull.issue.project = @user, @wrong_pull.to_project
|
|
|
|
@wrong_pull.to_ref = 'master'
|
|
|
|
@wrong_pull.from_project, @wrong_pull.from_ref = @project, 'wrong'
|
|
|
|
@wrong_pull.save
|
|
|
|
}.to change { PullRequest.count }.by(0)
|
2012-05-22 19:23:00 +01:00
|
|
|
end
|
2013-01-28 16:42:00 +00:00
|
|
|
|
|
|
|
it "should create pull with tag" do
|
2015-04-13 10:03:27 +01:00
|
|
|
expect {
|
|
|
|
system("cd #{@project.path} && git tag 4.7.5.3 $(git rev-parse #{@pull.from_ref})") # TODO REDO through grit
|
|
|
|
@pull = @project.pull_requests.new(issue_attributes: {title: 'tag', body: 'testing'})
|
|
|
|
@pull.issue.user, @pull.issue.project = @user, @pull.to_project
|
|
|
|
@pull.to_ref = 'master'
|
|
|
|
@pull.from_project, @pull.from_ref = @project, '4.7.5.3'
|
|
|
|
@pull.save
|
|
|
|
}.to change { @project.pull_requests.count }.by(1)
|
2013-01-28 16:42:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should close pull when deleting from branch" do
|
2015-04-13 10:03:27 +01:00
|
|
|
expect {
|
|
|
|
system("cd #{@project.path} && git branch -D #{@pull.from_branch}")
|
|
|
|
@pull.check
|
|
|
|
}.to change {
|
|
|
|
@project.pull_requests.joins(:issue).where(issues: {title: @pull.title, status: 'closed'}).count
|
|
|
|
}.by(1)
|
2013-01-28 16:42:00 +00:00
|
|
|
end
|
2012-04-19 20:08:33 +01:00
|
|
|
end
|
2012-04-18 18:08:53 +01:00
|
|
|
|
2012-10-01 13:29:36 +01:00
|
|
|
before do
|
2012-04-18 18:08:53 +01:00
|
|
|
FileUtils.rm_rf(APP_CONFIG['root_path'])
|
|
|
|
end
|
|
|
|
|
2013-01-18 16:14:10 +00:00
|
|
|
it { should belong_to(:issue).validate(true) }
|
2012-10-03 13:18:02 +01:00
|
|
|
it { should belong_to(:to_project) }
|
|
|
|
it { should belong_to(:from_project) }
|
2012-04-18 18:08:53 +01:00
|
|
|
|
2014-10-20 20:18:34 +01:00
|
|
|
context '#update_statistic' do
|
|
|
|
let(:issue) { FactoryGirl.build(:issue) }
|
|
|
|
let(:pull_request) { FactoryGirl.build(:pull_request, issue: issue) }
|
|
|
|
|
|
|
|
it 'updates styatistics' do
|
|
|
|
allow(PullRequest).to receive(:check_ref).and_return(true)
|
|
|
|
issue.new_pull_request = true
|
|
|
|
expect do
|
|
|
|
pull_request.save
|
|
|
|
end.to change(Statistic, :count).by(1)
|
|
|
|
expect(Statistic.last.key).to eq "#{Statistic::KEY_PULL_REQUEST}.#{Issue::STATUS_OPEN}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-01 13:29:36 +01:00
|
|
|
after do
|
2012-04-18 18:08:53 +01:00
|
|
|
FileUtils.rm_rf(APP_CONFIG['root_path'])
|
2012-10-01 13:29:36 +01:00
|
|
|
FileUtils.rm_rf File.join(Rails.root, "tmp", Rails.env, "pull_requests")
|
2012-04-18 18:08:53 +01:00
|
|
|
end
|
2012-04-16 19:40:50 +01:00
|
|
|
end
|