diff --git a/app/policies/issue_policy.rb b/app/policies/issue_policy.rb index 6ac43e6e7..34a0f0da1 100644 --- a/app/policies/issue_policy.rb +++ b/app/policies/issue_policy.rb @@ -6,6 +6,7 @@ class IssuePolicy < ApplicationPolicy end 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? ProjectPolicy.new(user, record.project).show? end diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index dd1da75e0..8b63f5cb4 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -28,11 +28,7 @@ shared_context "issues controller" do @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.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 = create_pull_request(@project) end end @@ -211,17 +207,6 @@ describe Projects::IssuesController, type: :controller do 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 get :show, name_with_owner: @project.name_with_owner, id: 999999 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 expect(response).to redirect_to(project_pull_request_path(@project, @pull)) 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 context 'for project writer user' do diff --git a/spec/controllers/projects/pull_requests_controller_spec.rb b/spec/controllers/projects/pull_requests_controller_spec.rb index b173730b6..32b8874b1 100644 --- a/spec/controllers/projects/pull_requests_controller_spec.rb +++ b/spec/controllers/projects/pull_requests_controller_spec.rb @@ -7,12 +7,7 @@ shared_context "pull request controller" do stub_symlink_methods @project = FactoryGirl.create(:project_with_commit) - - @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 = create_pull_request(@project) @create_params = { pull_request: { issue_attributes: { title: 'create', body: 'creating' }, diff --git a/spec/support/pull_request.rb b/spec/support/pull_request.rb new file mode 100644 index 000000000..18a422927 --- /dev/null +++ b/spec/support/pull_request.rb @@ -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 \ No newline at end of file