|
|
|
|
@ -2,7 +2,7 @@ require "rails_helper"
|
|
|
|
|
|
|
|
|
|
RSpec.describe MergeRequestsController, type: :request do |
|
|
|
|
let(:organisation) { user.organisation } |
|
|
|
|
let!(:other_organisation) { FactoryBot.create(:organisation) } |
|
|
|
|
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Other Test Org") } |
|
|
|
|
let(:headers) { { "Accept" => "text/html" } } |
|
|
|
|
let(:page) { Capybara::Node::Simple.new(response.body) } |
|
|
|
|
let(:user) { FactoryBot.create(:user, :data_coordinator) } |
|
|
|
|
@ -30,8 +30,8 @@ RSpec.describe MergeRequestsController, type: :request do
|
|
|
|
|
describe "#update_organisations" do |
|
|
|
|
let(:params) { { merge_request: { merging_organisation: other_organisation.id } } } |
|
|
|
|
|
|
|
|
|
context "when updating a merge request with a new organisation" do |
|
|
|
|
before do |
|
|
|
|
other_organisation.update!(name: "Other Test Org") |
|
|
|
|
patch "/merge-request/#{merge_request.id}/organisations", headers:, params: |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@ -43,5 +43,39 @@ RSpec.describe MergeRequestsController, type: :request do
|
|
|
|
|
expect(page).to have_link("Remove") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when the user selects an organisation that requested another merge" do |
|
|
|
|
let(:params) { { merge_request: { merging_organisation: other_organisation.id } } } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
MergeRequest.create!(requesting_organisation_id: other_organisation.id) |
|
|
|
|
patch "/merge-request/#{merge_request.id}/organisations", headers:, params: |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not update the merge request" do |
|
|
|
|
merge_request.reload |
|
|
|
|
expect(merge_request.merging_organisations.count).to eq(0) |
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity) |
|
|
|
|
expect(page).to have_content(I18n.t("validations.merge_request.organisation_part_of_another_merge")) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when the user selects an organisation that is a part of another merge" do |
|
|
|
|
let(:another_organisation) { FactoryBot.create(:organisation, name: "Other Test Org") } |
|
|
|
|
let(:params) { { merge_request: { merging_organisation: another_organisation.id } } } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
MergeRequest.create!(requesting_organisation_id: other_organisation.id, merging_organisation_ids: [another_organisation.id]) |
|
|
|
|
patch "/merge-request/#{merge_request.id}/organisations", headers:, params: |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not update the merge request" do |
|
|
|
|
merge_request.reload |
|
|
|
|
expect(merge_request.merging_organisations.count).to eq(0) |
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity) |
|
|
|
|
expect(page).to have_content(I18n.t("validations.merge_request.organisation_part_of_another_merge")) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|