Merge pull request #667 from warpc/90-refactoring

[refs #90] refactoring pull request:
* base_project -> to_project;
* base_ref -> to_ref.
This commit is contained in:
Vladimir Sharshov 2012-10-03 07:08:39 -07:00
commit fb80764a74
16 changed files with 144 additions and 142 deletions

View File

@ -2,12 +2,12 @@ $(document).ready(function() {
var upd_action = $('#update_action').val();
var form = $('#new_pull_request');
$('#pull_request_base_project').on('autocompleteselect', function(event, data){
var ref = $('#base_ref');
ref.parent().load(data.item.get_refs_url+' #base_ref', {"selected": ref.val()});
$('#pull_request_to_project').on('autocompleteselect', function(event, data){
var ref = $('#to_ref');
ref.parent().load(data.item.get_refs_url+' #to_ref', {"selected": ref.val()});
});
$('#pull_request_base_project, input#base_refs, input#head_refs').on('autocompleteselect', function(event, data){
$('#pull_request_to_project, input#to_refs, input#from_refs').on('autocompleteselect', function(event, data){
form.attr('action', upd_action)
.attr('method', 'get');
$('#update_pull').fadeIn('fast');

View File

@ -1571,8 +1571,6 @@ table.tablesorter.platform-maintainers.static-search thead tr.search th input[ty
.edit_comment .comment-left {
margin-top: 0;
}
}
#open-comment > h3.tmargin0 {
@ -1647,7 +1645,7 @@ form#new_pull_request {
}
}
#repo-wrapper form#new_pull_request .wrapper {
#repo-wrapper form#new_pull_request .wrapper {
background: none;
border: none;
height: 36px;

View File

@ -4,24 +4,24 @@ class Projects::PullRequestsController < Projects::BaseController
skip_before_filter :authenticate_user!, :only => [:index, :show] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :project
load_resource :issue, :through => :project, :find_by => :serial_id, :parent => false, :except => [:index, :autocomplete_base_project]
load_and_authorize_resource :instance_name => :pull, :through => :issue, :singleton => true, :except => [:index, :autocomplete_base_project]
load_resource :issue, :through => :project, :find_by => :serial_id, :parent => false, :except => [:index, :autocomplete_to_project]
load_and_authorize_resource :instance_name => :pull, :through => :issue, :singleton => true, :except => [:index, :autocomplete_to_project]
def new
base_project = set_base_project(false)
authorize! :read, base_project
to_project = find_destination_project(false)
authorize! :read, to_project
@pull = base_project.pull_requests.new
@pull.issue = base_project.issues.new
@pull = to_project.pull_requests.new
@pull.issue = to_project.issues.new
set_attrs
if PullRequest.check_ref(@pull, 'base', @pull.base_ref) && PullRequest.check_ref(@pull, 'head', @pull.head_ref) || @pull.uniq_merge
if PullRequest.check_ref(@pull, 'to', @pull.to_ref) && PullRequest.check_ref(@pull, 'from', @pull.from_ref) || @pull.uniq_merge
flash.now[:warning] = @pull.errors.full_messages.join('. ')
else
@pull.check(false) # don't make event transaction
if @pull.already?
@pull.destroy
flash.now[:warning] = I18n.t('projects.pull_requests.up_to_date', :base_ref => @pull.base_ref, :head_ref => @pull.head_ref)
flash.now[:warning] = I18n.t('projects.pull_requests.up_to_date', :to_ref => @pull.to_ref, :from_ref => @pull.from_ref)
else
load_diff_commits_data
end
@ -33,28 +33,28 @@ class Projects::PullRequestsController < Projects::BaseController
raise 'expect pull_request params' # for debug
redirect :back
end
base_project = set_base_project
authorize! :read, base_project
to_project = find_destination_project
authorize! :read, to_project
@pull = base_project.pull_requests.new pull_params
@pull.issue.user, @pull.issue.project, @pull.head_project = current_user, base_project, @project
@pull = to_project.pull_requests.new pull_params
@pull.issue.user, @pull.issue.project, @pull.from_project = current_user, to_project, @project
if @pull.valid? # FIXME more clean/clever logics
@pull.save # set pull id
@pull.check(false) # don't make event transaction
if @pull.already?
@pull.destroy
flash.now[:error] = I18n.t('projects.pull_requests.up_to_date', :base_ref => @pull.base_ref, :head_ref => @pull.head_ref)
flash.now[:error] = I18n.t('projects.pull_requests.up_to_date', :to_ref => @pull.to_ref, :from_ref => @pull.from_ref)
render :new
else
@pull.send(@pull.status)
redirect_to project_pull_request_path(@pull.base_project, @pull)
redirect_to project_pull_request_path(@pull.to_project, @pull)
end
else
flash.now[:error] = t('flash.pull_request.save_error')
flash.now[:warning] = @pull.errors.full_messages.join('. ')
if @pull.errors.try(:messages) && @pull.errors.messages[:base_ref].nil? && @pull.errors.messages[:head_ref].nil?
if @pull.errors.try(:messages) && @pull.errors.messages[:to_ref].nil? && @pull.errors.messages[:from_ref].nil?
@pull.check(false) # don't make event transaction
load_diff_commits_data
end
@ -70,7 +70,7 @@ class Projects::PullRequestsController < Projects::BaseController
@pull.check if @pull.open?
end
end
redirect_to project_pull_request_path(@pull.base_project, @pull)
redirect_to project_pull_request_path(@pull.to_project, @pull)
end
def merge
@ -79,7 +79,7 @@ class Projects::PullRequestsController < Projects::BaseController
flash.now[:error] = t('flash.pull_request.save_error')
flash.now[:warning] = @pull.errors.full_messages.join('. ')
end
redirect_to project_pull_request_path(@pull.base_project, @pull)
redirect_to project_pull_request_path(@pull.to_project, @pull)
end
def show
@ -107,7 +107,7 @@ class Projects::PullRequestsController < Projects::BaseController
end
end
def autocomplete_base_project
def autocomplete_to_project
items = Project.accessible_by(current_ability, :membered) | @project.ancestors
items.select! {|e| Regexp.new(params[:term].downcase).match(e.name_with_owner.downcase) && e.repo.branches.count > 0}
render :json => json_for_autocomplete_base(items)
@ -132,7 +132,7 @@ class Projects::PullRequestsController < Projects::BaseController
@base_commit = @pull.common_ancestor
@head_commit = repo.commits(@pull.head_branch).first
@commits = repo.commits_between(repo.commits(@pull.base_ref).first, @head_commit)
@commits = repo.commits_between(repo.commits(@pull.to_ref).first, @head_commit)
@total_commits = @commits.count
@commits = @commits.last(100)
@ -140,15 +140,11 @@ class Projects::PullRequestsController < Projects::BaseController
@stats = @pull.diff_stats repo, @base_commit, @head_commit
end
def set_base_project bang=true
args = params[:base_project].try(:split, '/') || []
if bang
raise ActiveRecord::RecordNotFound if args.length != 2
Project.find_by_owner_and_name! *args
else
return @project.parent || @project.root if args.length != 2
Project.find_by_owner_and_name(*args) || @project.parent || @project.root
end
def find_destination_project bang=true
args = params[:to_project].try(:split, '/') || []
project = (args.length == 2) ? Project.find_by_owner_and_name(*args) : nil
raise ActiveRecord::RecordNotFound if bang && !project
project.try(:parent) || @project
end
def set_attrs
@ -156,8 +152,8 @@ class Projects::PullRequestsController < Projects::BaseController
@pull.issue.title = pull_params[:issue_attributes][:title].presence
@pull.issue.body = pull_params[:issue_attributes][:body].presence
end
@pull.head_project = @project
@pull.base_ref = (pull_params[:base_ref].presence if pull_params) || @pull.base_project.default_branch
@pull.head_ref = params[:treeish].presence || (pull_params[:head_ref].presence if pull_params) || @pull.head_project.default_branch
@pull.from_project = @project
@pull.to_ref = (pull_params[:to_ref].presence if pull_params) || @pull.to_project.default_branch
@pull.from_ref = params[:treeish].presence || (pull_params[:from_ref].presence if pull_params) || @pull.from_project.default_branch
end
end

View File

@ -13,8 +13,8 @@ module PullRequestHelper
def pull_status pull
if %w(blocked merged closed ready open).include? pull.status
t("projects.pull_requests.#{pull.status}", :user => pull.issue.closer.try(:uname), :base_ref => show_ref(pull, 'base'),
:head_ref => show_ref(pull, 'head'), :time => pull.issue.closed_at).html_safe
t("projects.pull_requests.#{pull.status}", :user => pull.issue.closer.try(:uname), :to_ref => show_ref(pull, 'to'),
:from_ref => show_ref(pull, 'from'), :time => pull.issue.closed_at).html_safe
else
raise "pull id (#{pull.id}) wrong status #{pull.status} "
end
@ -22,9 +22,9 @@ module PullRequestHelper
def pull_header pull
str = "#{t '.header'} #{t 'from'} <span class='label-bootstrap label-info font14'> \
#{show_ref pull, 'head'}</span> \
#{show_ref pull, 'from'}</span> \
#{t 'into'} <span class='label-bootstrap label-info font14'> \
#{show_ref pull, 'base'}</span>"
#{show_ref pull, 'to'}</span>"
str << " #{t 'by'} #{link_to pull.user.uname, user_path(pull.user)}" if pull.persisted?
str.html_safe
end

View File

@ -17,7 +17,7 @@ class Ability
can :get_id, Project, :visibility => 'open' # api
can :archive, Project, :visibility => 'open'
can :read, Issue, :project => {:visibility => 'open'}
can :read, PullRequest, :base_project => {:visibility => 'open'}
can :read, PullRequest, :to_project => {:visibility => 'open'}
can :search, BuildList
can [:read, :log, :everything], BuildList, :project => {:visibility => 'open'}
can :read, ProductBuildList#, :product => {:platform => {:visibility => 'open'}} # double nested hash don't work
@ -124,11 +124,11 @@ class Ability
can(:update, Issue) {|issue| issue.user_id == user.id or local_admin?(issue.project)}
cannot :manage, Issue, :project => {:has_issues => false} # switch off issues
can :read, PullRequest, :base_project => {:owner_type => 'User', :owner_id => user.id}
can :read, PullRequest, :base_project => {:owner_type => 'Group', :owner_id => user.group_ids}
can(:read, PullRequest, read_relations_for('pull_requests', 'base_projects')) {|pull| can? :read, pull.base_project rescue nil}
can :read, PullRequest, :to_project => {:owner_type => 'User', :owner_id => user.id}
can :read, PullRequest, :to_project => {:owner_type => 'Group', :owner_id => user.group_ids}
can(:read, PullRequest, read_relations_for('pull_requests', 'to_projects')) {|pull| can? :read, pull.to_project rescue nil}
can :create, PullRequest
can([:update, :merge], PullRequest) {|pull| pull.user_id == user.id or local_admin?(pull.base_project)}
can([:update, :merge], PullRequest) {|pull| pull.user_id == user.id or local_admin?(pull.to_project)}
can(:create, Comment) {|comment| can? :read, comment.project}
can(:update, Comment) {|comment| comment.user == user or comment.project.owner == user or local_admin?(comment.project)}

View File

@ -8,7 +8,7 @@ class Project < ActiveRecord::Base
belongs_to :maintainer, :class_name => "User"
has_many :issues, :dependent => :destroy
has_many :pull_requests, :dependent => :destroy, :foreign_key => 'base_project_id'
has_many :pull_requests, :dependent => :destroy, :foreign_key => 'to_project_id'
has_many :labels, :dependent => :destroy
has_many :build_lists, :dependent => :destroy

View File

@ -1,13 +1,13 @@
class PullRequest < ActiveRecord::Base
STATUSES = %w(ready already blocked merged closed)
belongs_to :issue, :autosave => true, :dependent => :destroy, :touch => true, :validate => true
belongs_to :base_project, :class_name => 'Project', :foreign_key => 'base_project_id'
belongs_to :head_project, :class_name => 'Project', :foreign_key => 'head_project_id'
belongs_to :to_project, :class_name => 'Project', :foreign_key => 'to_project_id'
belongs_to :from_project, :class_name => 'Project', :foreign_key => 'from_project_id'
delegate :user, :user_id, :title, :body, :serial_id, :assignee, :status, :to_param,
:created_at, :updated_at, :comments, :status=, :to => :issue, :allow_nil => true
validate :uniq_merge
validates_each :head_ref, :base_ref do |record, attr, value|
validates_each :from_ref, :to_ref do |record, attr, value|
check_ref record, attr, value
end
@ -15,7 +15,7 @@ class PullRequest < ActiveRecord::Base
after_destroy :clean_dir
accepts_nested_attributes_for :issue
attr_accessible :issue_attributes, :base_ref, :head_ref
attr_accessible :issue_attributes, :to_ref, :from_ref
scope :needed_checking, includes(:issue).where(:issues => {:status => ['open', 'blocked', 'ready']})
@ -89,22 +89,22 @@ class PullRequest < ActiveRecord::Base
end
def path
filename = [id, head_project.owner.uname, head_project.name].compact.join('-')
File.join(APP_CONFIG['root_path'], 'pull_requests', base_project.owner.uname, base_project.name, filename)
filename = [id, from_project.owner.uname, from_project.name].compact.join('-')
File.join(APP_CONFIG['root_path'], 'pull_requests', to_project.owner.uname, to_project.name, filename)
end
def head_branch
if base_project != head_project
"head_#{head_ref}"
if to_project != from_project
"head_#{from_ref}"
else
head_ref
from_ref
end
end
def common_ancestor
return @common_ancestor if @common_ancestor
repo = Grit::Repo.new(path)
base_commit = repo.commits(base_ref).first
base_commit = repo.commits(to_ref).first
head_commit = repo.commits(head_branch).first
@common_ancestor = repo.commit(repo.git.merge_base({}, base_commit, head_commit)) || base_commit
end
@ -144,13 +144,13 @@ class PullRequest < ActiveRecord::Base
end
def self.check_ref(record, attr, value)
project = attr == :head_ref ? record.head_project : record.base_project
project = attr == :from_ref ? record.from_project : record.to_project
record.errors.add attr, I18n.t('projects.pull_requests.wrong_ref') unless project.repo.branches_and_tags.map(&:name).include?(value)
end
def uniq_merge
if base_project.pull_requests.needed_checking.where(:head_project_id => head_project, :base_ref => base_ref, :head_ref => head_ref).where('pull_requests.id <> :id or :id is null', :id => id).count > 0
errors.add(:base_branch, I18n.t('projects.pull_requests.duplicate', :head_ref => head_ref))
if to_project.pull_requests.needed_checking.where(:from_project_id => from_project, :to_ref => to_ref, :from_ref => from_ref).where('pull_requests.id <> :id or :id is null', :id => id).count > 0
errors.add(:base_branch, I18n.t('projects.pull_requests.duplicate', :from_ref => from_ref))
end
end
@ -158,34 +158,34 @@ class PullRequest < ActiveRecord::Base
def merge
clone
message = "Merge pull request ##{serial_id} from #{head_project.name_with_owner}:#{head_ref}\r\n #{title}"
%x(cd #{path} && git checkout #{base_ref} && git merge --no-ff #{head_branch} -m '#{message}')
message = "Merge pull request ##{serial_id} from #{from_project.name_with_owner}:#{from_ref}\r\n #{title}"
%x(cd #{path} && git checkout #{to_ref} && git merge --no-ff #{head_branch} -m '#{message}')
end
def clone
git = Grit::Git.new(path)
unless git.exist?
#~ FileUtils.mkdir_p(path)
#~ system("git clone --local --no-hardlinks #{base_project.path} #{path}")
options = {:bare => false, :shared => false, :branch => base_ref} # shared?
#~ system("git clone --local --no-hardlinks #{to_project.path} #{path}")
options = {:bare => false, :shared => false, :branch => to_ref} # shared?
git.fs_mkdir('..')
git.clone(options, base_project.path, path)
if base_project != head_project
git.clone(options, to_project.path, path)
if to_project != from_project
Dir.chdir(path) do
system 'git', 'remote', 'add', 'head', head_project.path
system 'git', 'remote', 'add', 'head', from_project.path
end
end
clean
end
Dir.chdir(path) do
system 'git', 'checkout', base_ref
system 'git', 'pull', 'origin', base_ref
if base_project == head_project
system 'git', 'checkout', head_ref
system 'git', 'pull', 'origin', head_ref
system 'git', 'checkout', to_ref
system 'git', 'pull', 'origin', to_ref
if to_project == from_project
system 'git', 'checkout', from_ref
system 'git', 'pull', 'origin', from_ref
else
system 'git', 'fetch', 'head', "+#{head_ref}:#{head_branch}"
system 'git', 'fetch', 'head', "+#{from_ref}:#{head_branch}"
end
end
# TODO catch errors
@ -193,14 +193,14 @@ class PullRequest < ActiveRecord::Base
def clean
Dir.chdir(path) do
base_project.repo.branches.each {|branch| system 'git', 'checkout', branch.name}
system 'git', 'checkout', base_ref
to_project.repo.branches.each {|branch| system 'git', 'checkout', branch.name}
system 'git', 'checkout', to_ref
base_project.repo.branches.each do |branch|
system 'git', 'branch', '-D', branch.name unless [base_ref, head_branch].include? branch.name
to_project.repo.branches.each do |branch|
system 'git', 'branch', '-D', branch.name unless [to_ref, head_branch].include? branch.name
end
base_project.repo.tags.each do |tag|
system 'git', 'tag', '-d', tag.name unless [base_ref, head_branch].include? tag.name
to_project.repo.tags.each do |tag|
system 'git', 'tag', '-d', tag.name unless [to_ref, head_branch].include? tag.name
end
end
end

View File

@ -1 +1 @@
=render 'projects/pull_requests/ref_select', :kind => 'base', :project => @project, :current => @selected
=render 'projects/pull_requests/ref_select', :kind => 'to', :project => @project, :current => @selected

View File

@ -9,15 +9,15 @@
=hidden_field_tag :update_action, new_project_pull_request_path
=form_for @pull, :url => (@pull.already? ? new_project_pull_request_path : project_pull_requests_path), :html => {:class => 'well well-large', :method => (@pull.already? ? :get : :post)} do |f|
.leftlist=f.label :head_project, t("#{ar}.head_project"), :class => :label
.leftlist=f.label :from_project, t("#{ar}.from_project"), :class => :label
%div
.l=text_field_tag :head_project, @pull.head_project.name_with_owner, :readonly => :readonly, :style => 'background-color: #DDD;'
=render 'ref_select', :kind => 'head', :project => @pull.head_project, :current => @pull.head_ref
.l=text_field_tag :from_project, @pull.from_project.name_with_owner, :readonly => :readonly, :style => 'background-color: #DDD;'
=render 'ref_select', :kind => 'from', :project => @pull.from_project, :current => @pull.from_ref
.both
.leftlist=f.label :base_project, t("#{ar}.base_project"), :class => :label
.leftlist=f.label :to_project, t("#{ar}.to_project"), :class => :label
%div
.l=f.autocomplete_field :base_project, autocomplete_base_project_project_pull_requests_path, :value => @pull.base_project.name_with_owner, :id_element => 'pull_request_base_project_id', :name => 'base_project'
=render 'ref_select', :kind => 'base', :project => @pull.base_project, :current => @pull.base_ref
.l=f.autocomplete_field :to_project, autocomplete_to_project_project_pull_requests_path, :value => @pull.to_project.name_with_owner, :id_element => 'pull_request_to_project_id', :name => 'to_project'
=render 'ref_select', :kind => 'to', :project => @pull.to_project, :current => @pull.to_ref
.both
.leftlist.big-list
.rightlist=f.submit t('.update'), :class => 'btn btn-primary disabled', 'data-loading-text' => t('layout.processing'), :style => @pull.already? ? '' : 'display: none;', :id => 'update_pull'

View File

@ -12,14 +12,14 @@ en:
close: Close Pull Request
reopen: Reopen Pull Request
merge: Merge
duplicate: 'There is already a pull request for %{head_ref}'
up_to_date: 'The %{base_ref} branch is already up-to-date with %{head_ref}'
duplicate: 'There is already a pull request for %{from_ref}'
up_to_date: 'The %{to_ref} branch is already up-to-date with %{from_ref}'
wrong_ref: Wrong branch or tag
blocked: This pull request cannot be automatically merged.
ready: This pull request can be automatically merged.
merged: |
%{user} merged into <span class="label-bootstrap label-info font14">%{base_ref}</span>
from <span class="label-bootstrap label-info font14">%{head_ref}</span> at %{time}
%{user} merged into <span class="label-bootstrap label-info font14">%{to_ref}</span>
from <span class="label-bootstrap label-info font14">%{from_ref}</span> at %{time}
closed: '%{user} closed this pull request at %{time}'
is_big: This pull request is big! We're only showing the most recent %{count} commits.
open: ''
@ -44,11 +44,11 @@ en:
activerecord:
attributes:
pull_requests:
base_ref: Base
head_ref: Head
to_ref: Source
from_ref: Receiver
refs: 'branch · tag'
base_project: Into
head_project: From
to_project: Into
from_project: From
layout:
pull_requests:

View File

@ -14,14 +14,14 @@ ru:
close: Закрыть пул реквест
reopen: Переоткрыть пул реквест
merge: Мерж
duplicate: 'Уже существует пул реквест %{head_ref}'
up_to_date: 'Ветка %{base_ref} на данный момент уже содержит последние изменения %{head_ref}'
duplicate: 'Уже существует пул реквест %{from_ref}'
up_to_date: 'Ветка %{to_ref} на данный момент уже содержит последние изменения %{from_ref}'
wrong_ref: Неправильная ветка или тег
blocked: Невозможно автоматически смержить данный пул реквест.
ready: Данный пул реквест можно смержить автоматически.
merged: |
%{user} смержил <span class="label-bootstrap label-info font14">%{base_ref}</span>
с <span class="label-bootstrap label-info font14">%{head_ref}</span> в %{time}'
%{user} смержил <span class="label-bootstrap label-info font14">%{to_ref}</span>
с <span class="label-bootstrap label-info font14">%{from_ref}</span> в %{time}'
closed: '%{user} закрыл пул реквест в %{time}'
is_big: Этот пул реквест слишком большой! Мы показываем только последние %{count} комитов.
open: ''
@ -46,11 +46,11 @@ ru:
activerecord:
attributes:
pull_requests:
base_ref: База
head_ref: Источник
to_ref: Приемник
from_ref: Источник
refs: 'ветка · тег'
base_project: Куда
head_project: Откуда
to_project: Куда
from_project: Откуда
layout:
pull_requests:

View File

@ -206,7 +206,7 @@ Rosa::Application.routes.draw do
get :find, :on => :collection
end
resources :pull_requests, :except => :destroy do
get :autocomplete_base_project, :on => :collection
get :autocomplete_to_project, :on => :collection
put :merge, :on => :member
end
post '/preview' => 'projects#preview', :as => 'md_preview'

View File

@ -0,0 +1,8 @@
class RenameBaseHeadInPullRequests < ActiveRecord::Migration
def change
rename_column :pull_requests, :base_project_id, :to_project_id
rename_column :pull_requests, :base_ref, :to_ref
rename_column :pull_requests, :head_project_id, :from_project_id
rename_column :pull_requests, :head_ref, :from_ref
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120914160741) do
ActiveRecord::Schema.define(:version => 20121003081546) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -343,15 +343,15 @@ ActiveRecord::Schema.define(:version => 20120914160741) do
create_table "pull_requests", :force => true do |t|
t.integer "issue_id", :null => false
t.integer "base_project_id", :null => false
t.integer "head_project_id", :null => false
t.string "base_ref", :null => false
t.string "head_ref", :null => false
t.integer "to_project_id", :null => false
t.integer "from_project_id", :null => false
t.string "to_ref", :null => false
t.string "from_ref", :null => false
end
add_index "pull_requests", ["base_project_id"], :name => "index_pull_requests_on_base_project_id"
add_index "pull_requests", ["head_project_id"], :name => "index_pull_requests_on_head_project_id"
add_index "pull_requests", ["from_project_id"], :name => "index_pull_requests_on_head_project_id"
add_index "pull_requests", ["issue_id"], :name => "index_pull_requests_on_issue_id"
add_index "pull_requests", ["to_project_id"], :name => "index_pull_requests_on_base_project_id"
create_table "register_requests", :force => true do |t|
t.string "name"

View File

@ -11,16 +11,16 @@ shared_context "pull request controller" do
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.path})
@pull = @project.pull_requests.new :issue_attributes => {:title => 'test', :body => 'testing'}
@pull.issue.user, @pull.issue.project = @project.owner, @pull.base_project
@pull.base_ref = 'master'
@pull.head_project, @pull.head_ref = @project, 'non_conflicts'
@pull.issue.user, @pull.issue.project = @project.owner, @pull.to_project
@pull.to_ref = 'master'
@pull.from_project, @pull.from_ref = @project, 'non_conflicts'
@pull.save
@create_params = {
:pull_request => {:issue_attributes => {:title => 'create', :body => 'creating'},
:base_ref => 'non_conflicts',
:head_ref => 'master'},
:base_project => @project.name_with_owner,
:to_ref => 'non_conflicts',
:from_ref => 'master'},
:to_project => @project.name_with_owner,
:owner_name => @project.owner.uname,
:project_name => @project.name }
@update_params = @create_params.merge(
@ -66,12 +66,12 @@ shared_examples_for 'pull request user with project reader rights' do
end
it "should not create same pull" do
post :create, @create_params.merge({:pull_request => {:issue_attributes => {:title => 'same', :body => 'creating'}, :head_ref => 'non_conflicts', :base_ref => 'master'}, :base_project_id => @project.id})
post :create, @create_params.merge({:pull_request => {:issue_attributes => {:title => 'same', :body => 'creating'}, :from_ref => 'non_conflicts', :to_ref => 'master'}, :to_project_id => @project.id})
PullRequest.joins(:issue).where(:issues => {:title => 'same', :body => 'creating'}).count.should == 0
end
it "should not create already up-to-date pull" do
post :create, @create_params.merge({:pull_request => {:issue_attributes => {:title => 'already', :body => 'creating'}, :base_ref => 'master', :head_ref => 'master'}, :base_project_id => @project.id})
post :create, @create_params.merge({:pull_request => {:issue_attributes => {:title => 'already', :body => 'creating'}, :to_ref => 'master', :from_ref => 'master'}, :to_project_id => @project.id})
PullRequest.joins(:issue).where(:issues => {:title => 'already', :body => 'creating'}).count.should == 0
end
end
@ -79,12 +79,12 @@ end
shared_examples_for 'user with pull request update rights' do
it 'should be able to perform update action' do
put :update, @update_params
response.should redirect_to(project_pull_request_path(@pull.base_project, @pull))
response.should redirect_to(project_pull_request_path(@pull.to_project, @pull))
end
it 'should be able to perform merge action' do
put :merge, @update_params
response.should redirect_to(project_pull_request_path(@pull.base_project, @pull))
response.should redirect_to(project_pull_request_path(@pull.to_project, @pull))
end
let(:pull) { @project.pull_requests.find(@pull) }

View File

@ -24,15 +24,15 @@ describe PullRequest do
@user = FactoryGirl.create(:user)
set_data_for_pull
@pull = @project.pull_requests.new(:issue_attributes => {:title => 'test', :body => 'testing'})
@pull.issue.user, @pull.issue.project = @user, @pull.base_project
@pull.base_ref = 'master'
@pull.head_project, @pull.head_ref = @project, 'non_conflicts'
@pull.issue.user, @pull.issue.project = @user, @pull.to_project
@pull.to_ref = 'master'
@pull.from_project, @pull.from_ref = @project, 'non_conflicts'
@pull.save
@other_pull = @project.pull_requests.new(:issue_attributes => {:title => 'test_other', :body => 'testing_other'})
@other_pull.issue.user, @other_pull.issue.project = @user, @other_pull.base_project
@other_pull.base_ref = 'master'
@other_pull.head_project, @other_pull.head_ref = @other_project, 'non_conflicts'
@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'
@other_pull.save
end
@ -42,13 +42,13 @@ describe PullRequest do
end
it 'master should not merge with conflicts branch' do
@pull.head_ref = 'conflicts'
@pull.from_ref = 'conflicts'
@pull.check
@pull.status.should == 'blocked'
end
it 'should already merged when already up-to-date branches' do
@pull.head_ref = 'master'
@pull.from_ref = 'master'
@pull.check
@pull.status.should == 'merged'
end
@ -60,13 +60,13 @@ describe PullRequest do
end
it 'master should not merge with conflicts branch' do
@other_pull.head_ref = 'conflicts'
@other_pull.from_ref = 'conflicts'
@other_pull.check
@other_pull.status.should == 'blocked'
end
it 'should already merged when already up-to-date branches' do
@other_pull.head_ref = 'master'
@other_pull.from_ref = 'master'
@other_pull.check
@other_pull.status.should == 'merged'
end
@ -74,27 +74,27 @@ describe PullRequest do
it "should not create same pull" do
@same_pull = @project.pull_requests.new(:issue_attributes => {:title => 'same', :body => 'testing'})
@same_pull.issue.user, @same_pull.issue.project = @user, @same_pull.base_project
@same_pull.base_ref = 'master'
@same_pull.head_project, @same_pull.head_ref = @project, 'non_conflicts'
@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
@project.pull_requests.joins(:issue).where(:issues => {:title => @same_pull.title}).count.should == 0
end
it "should not create pull with wrong base ref" do
@wrong_pull = @project.pull_requests.new(:issue_attributes => {:title => 'wrong base', :body => 'testing'})
@wrong_pull.issue.user, @wrong_pull.issue.project = @user, @wrong_pull.base_project
@wrong_pull.base_ref = 'wrong'
@wrong_pull.head_project, @wrong_pull.head_ref = @project, 'non_conflicts'
@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
@project.pull_requests.joins(:issue).where(:issues => {:title => @wrong_pull.title}).count.should == 0
end
it "should not create pull with wrong head ref" do
@wrong_pull = @project.pull_requests.new(:issue_attributes => {:title => 'wrong head', :body => 'testing'})
@wrong_pull.issue.user, @wrong_pull.issue.project = @user, @wrong_pull.base_project
@wrong_pull.base_ref = 'master'
@wrong_pull.head_project, @wrong_pull.head_ref = @project, 'wrong'
@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
@project.pull_requests.joins(:issue).where(:issues => {:title => @wrong_pull.title}).count.should == 0
end
@ -105,8 +105,8 @@ describe PullRequest do
end
it { should belong_to(:issue) }
it { should belong_to(:base_project) }
it { should belong_to(:head_project) }
it { should belong_to(:to_project) }
it { should belong_to(:from_project) }
after do
FileUtils.rm_rf(APP_CONFIG['root_path'])