@ -168,6 +168,78 @@ RSpec.describe MergeRequest, type: :model do
end
end
end
end
describe " # organisations_with_schemes " do
let ( :merge_request ) { create ( :merge_request , absorbing_organisation : ) }
let ( :absorbing_organisation ) { create ( :organisation ) }
let ( :merging_organisation_1 ) { create ( :organisation ) }
let ( :merging_organisation_2 ) { create ( :organisation ) }
before do
create ( :merge_request_organisation , merge_request : , merging_organisation : merging_organisation_1 )
create ( :merge_request_organisation , merge_request : , merging_organisation : merging_organisation_2 )
end
context " when absorbing organisation has schemes " do
before do
create ( :scheme , owning_organisation : absorbing_organisation )
end
context " and some merging organisations have schemes " do
before do
create ( :scheme , owning_organisation : merging_organisation_1 )
end
it " returns correct organisations with schemes " do
expect ( absorbing_organisation . owned_schemes . count ) . to eq ( 1 )
expect ( merging_organisation_1 . owned_schemes . count ) . to eq ( 1 )
expect ( merging_organisation_2 . owned_schemes . count ) . to eq ( 0 )
expect ( merge_request . organisations_with_schemes . count ) . to eq ( 2 )
expect ( merge_request . organisations_with_schemes ) . to include ( merging_organisation_1 )
expect ( merge_request . organisations_with_schemes ) . to include ( absorbing_organisation )
end
end
context " and no merging organisations have schemes " do
it " returns correct organisations with schemes " do
expect ( absorbing_organisation . owned_schemes . count ) . to eq ( 1 )
expect ( merging_organisation_1 . owned_schemes . count ) . to eq ( 0 )
expect ( merging_organisation_2 . owned_schemes . count ) . to eq ( 0 )
expect ( merge_request . organisations_with_schemes . count ) . to eq ( 1 )
expect ( merge_request . organisations_with_schemes ) . to include ( absorbing_organisation )
end
end
end
context " when absorbing organisation has no schemes " do
context " and some merging organisations have schemes " do
before do
create ( :scheme , owning_organisation : merging_organisation_1 )
end
it " returns correct organisations with schemes " do
expect ( merging_organisation_1 . owned_schemes . count ) . to eq ( 1 )
expect ( absorbing_organisation . owned_schemes . count ) . to eq ( 0 )
expect ( merging_organisation_2 . owned_schemes . count ) . to eq ( 0 )
expect ( merge_request . organisations_with_schemes . count ) . to eq ( 1 )
expect ( merge_request . organisations_with_schemes ) . to include ( merging_organisation_1 )
end
end
context " and no merging organisations have schemes " do
it " returns correct organisations with schemes " do
expect ( absorbing_organisation . owned_schemes . count ) . to eq ( 0 )
expect ( merging_organisation_1 . owned_schemes . count ) . to eq ( 0 )
expect ( merging_organisation_2 . owned_schemes . count ) . to eq ( 0 )
expect ( merge_request . organisations_with_schemes . count ) . to eq ( 0 )
end
end
end
end
describe " # organisations_without_users " do
describe " # organisations_without_users " do
context " when absorbing organisation has users " do
context " when absorbing organisation has users " do
let ( :merge_request ) { create ( :merge_request , absorbing_organisation : ) }
let ( :merge_request ) { create ( :merge_request , absorbing_organisation : ) }
@ -249,4 +321,80 @@ RSpec.describe MergeRequest, type: :model do
end
end
end
end
end
end
describe " # organisations_without_schemes " do
let ( :merge_request ) { create ( :merge_request , absorbing_organisation : ) }
let ( :absorbing_organisation ) { create ( :organisation ) }
let ( :merging_organisation_1 ) { create ( :organisation ) }
let ( :merging_organisation_2 ) { create ( :organisation ) }
before do
create ( :merge_request_organisation , merge_request : , merging_organisation : merging_organisation_1 )
create ( :merge_request_organisation , merge_request : , merging_organisation : merging_organisation_2 )
end
context " when absorbing organisation has schemes " do
before do
create ( :scheme , owning_organisation : absorbing_organisation )
end
context " and some merging organisations have schemes " do
before do
create ( :scheme , owning_organisation : merging_organisation_1 )
end
it " returns correct organisations with schemes " do
expect ( absorbing_organisation . owned_schemes . count ) . to eq ( 1 )
expect ( merging_organisation_1 . owned_schemes . count ) . to eq ( 1 )
expect ( merging_organisation_2 . owned_schemes . count ) . to eq ( 0 )
expect ( merge_request . organisations_without_schemes . count ) . to eq ( 1 )
expect ( merge_request . organisations_without_schemes ) . to include ( merging_organisation_2 )
end
end
context " and no merging organisations have schemes " do
it " returns correct organisations with schemes " do
expect ( absorbing_organisation . owned_schemes . count ) . to eq ( 1 )
expect ( merging_organisation_1 . owned_schemes . count ) . to eq ( 0 )
expect ( merging_organisation_2 . owned_schemes . count ) . to eq ( 0 )
expect ( merge_request . organisations_without_schemes . count ) . to eq ( 2 )
expect ( merge_request . organisations_without_schemes ) . to include ( merging_organisation_1 )
expect ( merge_request . organisations_without_schemes ) . to include ( merging_organisation_2 )
end
end
end
context " when absorbing organisation has no schemes " do
context " and some merging organisations have schemes " do
before do
create ( :scheme , owning_organisation : merging_organisation_1 )
end
it " returns correct organisations with schemes " do
expect ( merging_organisation_1 . owned_schemes . count ) . to eq ( 1 )
expect ( absorbing_organisation . owned_schemes . count ) . to eq ( 0 )
expect ( merging_organisation_2 . owned_schemes . count ) . to eq ( 0 )
expect ( merge_request . organisations_without_schemes . count ) . to eq ( 2 )
expect ( merge_request . organisations_without_schemes ) . to include ( absorbing_organisation )
expect ( merge_request . organisations_without_schemes ) . to include ( merging_organisation_2 )
end
end
context " and no merging organisations have schemes " do
it " returns correct organisations with schemes " do
expect ( absorbing_organisation . owned_schemes . count ) . to eq ( 0 )
expect ( merging_organisation_1 . owned_schemes . count ) . to eq ( 0 )
expect ( merging_organisation_2 . owned_schemes . count ) . to eq ( 0 )
expect ( merge_request . organisations_without_schemes . count ) . to eq ( 3 )
expect ( merge_request . organisations_without_schemes ) . to include ( absorbing_organisation )
expect ( merge_request . organisations_without_schemes ) . to include ( merging_organisation_1 )
expect ( merge_request . organisations_without_schemes ) . to include ( merging_organisation_2 )
end
end
end
end
end
end