#465 fix redirect to pull request in project with turned off issues

This commit is contained in:
Alexander Machehin 2015-04-23 10:14:22 +05:00
parent 8c34d7b33a
commit 4009af4ff0
4 changed files with 18 additions and 22 deletions

View File

@ -6,6 +6,7 @@ class IssuePolicy < ApplicationPolicy
end end
def show? def show?
return true if record.pull_request.present? # for redirect from a issue to a pull request
return false unless record.project.has_issues? return false unless record.project.has_issues?
ProjectPolicy.new(user, record.project).show? ProjectPolicy.new(user, record.project).show?
end end

View File

@ -28,11 +28,7 @@ shared_context "issues controller" do
@update_params = { name_with_owner: @project.name_with_owner, issue: { title: "issue2" }, format: :json } @update_params = { name_with_owner: @project.name_with_owner, issue: { title: "issue2" }, format: :json }
@pull = @project.pull_requests.new issue_attributes: { title: 'test', body: 'testing' } @pull = create_pull_request(@project)
@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
end end
end end
@ -211,17 +207,6 @@ describe Projects::IssuesController, type: :controller do
end end
end end
# it 'should not be able to perform create action on project' do
# post :create, @create_params
# expect(response).to redirect_to(forbidden_path)
# end
# it 'should not create issue object into db' do
# expect
# post :create, @create_params
# end.to change(Issue, :count).by(0)
# end
it 'should return 404' do it 'should return 404' do
get :show, name_with_owner: @project.name_with_owner, id: 999999 get :show, name_with_owner: @project.name_with_owner, id: 999999
expect(response).to render_template(file: "#{Rails.root}/public/404.html") expect(response).to render_template(file: "#{Rails.root}/public/404.html")
@ -231,6 +216,13 @@ describe Projects::IssuesController, type: :controller do
get :show, name_with_owner: @project.name_with_owner, id: @pull.reload.serial_id get :show, name_with_owner: @project.name_with_owner, id: @pull.reload.serial_id
expect(response).to redirect_to(project_pull_request_path(@project, @pull)) expect(response).to redirect_to(project_pull_request_path(@project, @pull))
end end
it 'should redirect to pull request in project with turned off issues' do
@project.update_attribute :has_issues, false
get :show, name_with_owner: @project.name_with_owner, id: @pull.reload.serial_id
expect(response).to redirect_to(project_pull_request_path(@project, @pull))
end
end end
context 'for project writer user' do context 'for project writer user' do

View File

@ -7,12 +7,7 @@ shared_context "pull request controller" do
stub_symlink_methods stub_symlink_methods
@project = FactoryGirl.create(:project_with_commit) @project = FactoryGirl.create(:project_with_commit)
@pull = create_pull_request(@project)
@pull = @project.pull_requests.new issue_attributes: {title: 'test', body: 'testing'}
@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 = { @create_params = {
pull_request: { issue_attributes: { title: 'create', body: 'creating' }, pull_request: { issue_attributes: { title: 'create', body: 'creating' },

View File

@ -0,0 +1,8 @@
def create_pull_request(project)
pull = project.pull_requests.new issue_attributes: {title: 'test', body: 'testing'}
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
pull
end