Commit b91d1890 authored by Rémy Coutable's avatar Rémy Coutable

Pass current_user to merge_request.closes_issues in API ans streamline MR API specs

parent 78e36780
......@@ -310,7 +310,7 @@ module API
# GET /projects/:id/merge_requests/:merge_request_id/closes_issues
get "#{path}/closes_issues" do
merge_request = user_project.merge_requests.find(params[:merge_request_id])
issues = ::Kaminari.paginate_array(merge_request.closes_issues)
issues = ::Kaminari.paginate_array(merge_request.closes_issues(current_user))
present paginate(issues), with: Entities::Issue
end
end
......
......@@ -73,12 +73,6 @@ FactoryGirl.define do
merge_user author
end
trait :with_closes_issues do
source_branch "markdown"
target_branch "master"
state :opened
end
factory :closed_merge_request, traits: [:closed]
factory :reopened_merge_request, traits: [:reopened]
factory :merge_request_with_diffs, traits: [:with_diffs]
......
......@@ -448,25 +448,21 @@ describe API::API, api: true do
end
end
describe "GET :id/merge_requests/:merge_request_id/closes_issues" do
let(:merge_request_with_closes_issues) { create(:merge_request, :with_closes_issues, author: user, assignee: user, source_project: project, target_project: project, title: "Closed ##{issue.id}", created_at: base_time + 3.seconds, description: "This should close ##{issue.iid}") }
let(:issue) do
create :issue,
author: user,
assignee: user,
project: project,
milestone: nil
describe 'GET :id/merge_requests/:merge_request_id/closes_issues' do
it 'returns the issue that will be closed on merge' do
issue = create(:issue, project: project)
mr = merge_request.tap do |mr|
mr.update_attribute(:description, "Closes #{issue.to_reference(mr.project)}")
end
it "should return the issues that will be closed on merge" do
get api("/projects/#{project.id}/merge_requests/#{merge_request_with_closes_issues.id}/closes_issues", user)
get api("/projects/#{project.id}/merge_requests/#{mr.id}/closes_issues", user)
expect(response.status).to eq(200)
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(issue.id)
end
it "should return an empty array when there are no issues to be closed" do
it 'returns an empty array when there are no issues to be closed' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/closes_issues", user)
expect(response.status).to eq(200)
expect(json_response).to be_an Array
......
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