Browse Source

Temp fix. request tests

pull/2561/head
Manny Dinssa 2 years ago
parent
commit
55a52e89d4
  1. 1
      app/models/merge_request.rb
  2. 2
      app/models/merge_request_organisation.rb
  3. 14
      spec/requests/merge_requests_controller_spec.rb

1
app/models/merge_request.rb

@ -24,6 +24,7 @@ class MergeRequest < ApplicationRecord
open_collection_period_start_date:, open_collection_period_start_date:,
) )
} }
scope :not_unsubmitted, -> { where.not(status: %w[merge_issues incomplete ready_to_merge processing]) }
def organisation_name_uniqueness def organisation_name_uniqueness
if Organisation.where("lower(name) = ?", new_organisation_name&.downcase).exists? if Organisation.where("lower(name) = ?", new_organisation_name&.downcase).exists?

2
app/models/merge_request_organisation.rb

@ -5,7 +5,7 @@ class MergeRequestOrganisation < ApplicationRecord
validates :merging_organisation, presence: { message: I18n.t("validations.merge_request.merging_organisation_id.blank") } validates :merging_organisation, presence: { message: I18n.t("validations.merge_request.merging_organisation_id.blank") }
validate :validate_merging_organisations validate :validate_merging_organisations
scope :not_unsubmitted, -> { joins(:merge_request).where.not(merge_requests: { status: "unsubmitted" }) } scope :not_unsubmitted, -> { joins(:merge_request).where.not(merge_requests: { status: %w[merge_issues incomplete ready_to_merge processing] }) }
scope :with_merging_organisation, ->(merging_organisation) { where(merging_organisation:) } scope :with_merging_organisation, ->(merging_organisation) { where(merging_organisation:) }
has_paper_trail has_paper_trail

14
spec/requests/merge_requests_controller_spec.rb

@ -14,7 +14,7 @@ RSpec.describe MergeRequestsController, type: :request do
before { sign_in user } before { sign_in user }
describe "#organisations" do describe "#organisations" do
let(:params) { { merge_request: { requesting_organisation_id: "9", status: "unsubmitted" } } } let(:params) { { merge_request: { requesting_organisation_id: "9", status: "incomplete" } } }
context "when creating a new merge request" do context "when creating a new merge request" do
before do before do
@ -29,7 +29,7 @@ RSpec.describe MergeRequestsController, type: :request do
end end
context "when passing a different requesting organisation id" do context "when passing a different requesting organisation id" do
let(:params) { { merge_request: { requesting_organisation_id: other_organisation.id, status: "unsubmitted" } } } let(:params) { { merge_request: { requesting_organisation_id: other_organisation.id, status: "incomplete" } } }
it "creates merge request with current user organisation" do it "creates merge request with current user organisation" do
follow_redirect! follow_redirect!
@ -84,7 +84,7 @@ RSpec.describe MergeRequestsController, type: :request do
let(:params) { { merge_request: { merging_organisation: other_organisation.id } } } let(:params) { { merge_request: { merging_organisation: other_organisation.id } } }
before do before do
MergeRequest.create!(requesting_organisation_id: other_organisation.id, status: "submitted") MergeRequest.create!(requesting_organisation_id: other_organisation.id, status: "request_merged")
patch "/merge-request/#{merge_request.id}/organisations", headers:, params: patch "/merge-request/#{merge_request.id}/organisations", headers:, params:
end end
@ -100,7 +100,7 @@ RSpec.describe MergeRequestsController, type: :request do
let(:params) { { merge_request: { merging_organisation: other_organisation.id } } } let(:params) { { merge_request: { merging_organisation: other_organisation.id } } }
before do before do
MergeRequest.create!(requesting_organisation_id: other_organisation.id, status: "unsubmitted") MergeRequest.create!(requesting_organisation_id: other_organisation.id, status: "incomplete")
patch "/merge-request/#{merge_request.id}/organisations", headers:, params: patch "/merge-request/#{merge_request.id}/organisations", headers:, params:
end end
@ -116,7 +116,7 @@ RSpec.describe MergeRequestsController, type: :request do
let(:params) { { merge_request: { merging_organisation: another_organisation.id } } } let(:params) { { merge_request: { merging_organisation: another_organisation.id } } }
before do before do
existing_merge_request = MergeRequest.create!(requesting_organisation_id: other_organisation.id, status: "submitted") existing_merge_request = MergeRequest.create!(requesting_organisation_id: other_organisation.id, status: "request_merged")
MergeRequestOrganisation.create!(merge_request_id: existing_merge_request.id, merging_organisation_id: another_organisation.id) MergeRequestOrganisation.create!(merge_request_id: existing_merge_request.id, merging_organisation_id: another_organisation.id)
patch "/merge-request/#{merge_request.id}/organisations", headers:, params: patch "/merge-request/#{merge_request.id}/organisations", headers:, params:
end end
@ -134,7 +134,7 @@ RSpec.describe MergeRequestsController, type: :request do
let(:params) { { merge_request: { merging_organisation: another_organisation.id } } } let(:params) { { merge_request: { merging_organisation: another_organisation.id } } }
before do before do
existing_merge_request = MergeRequest.create!(requesting_organisation_id: other_organisation.id, status: "unsubmitted") existing_merge_request = MergeRequest.create!(requesting_organisation_id: other_organisation.id, status: "incomplete")
MergeRequestOrganisation.create!(merge_request_id: existing_merge_request.id, merging_organisation_id: another_organisation.id) MergeRequestOrganisation.create!(merge_request_id: existing_merge_request.id, merging_organisation_id: another_organisation.id)
patch "/merge-request/#{merge_request.id}/organisations", headers:, params: patch "/merge-request/#{merge_request.id}/organisations", headers:, params:
end end
@ -701,7 +701,7 @@ RSpec.describe MergeRequestsController, type: :request do
end end
describe "#organisations" do describe "#organisations" do
let(:params) { { merge_request: { requesting_organisation_id: other_organisation.id, status: "unsubmitted" } } } let(:params) { { merge_request: { requesting_organisation_id: other_organisation.id, status: "incomplete" } } }
before do before do
post "/merge-request", headers:, params: post "/merge-request", headers:, params:

Loading…
Cancel
Save