-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unassigned requests for StagingWorkflow
We have created the association between StagingWorkflow, StagingProject and BsRequest. Unassigned requests are all the requests related to the StagingWorkflow's main project that are not associated to any of the staging projects. Co-authored-by: Eduardo Navarro <enavarro@suse.com> Co-authored-by: Victor Pereira <vpereira@suse.com> Co-authored-by: Moisés Déniz Alemán <mdeniz@suse.com>
- Loading branch information
Showing
8 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class StagingWorkflow < ApplicationRecord | ||
belongs_to :project, inverse_of: :staging | ||
has_many :staging_projects, class_name: 'Project', inverse_of: :staging_workflow, dependent: :nullify | ||
|
||
has_many :target_of_bs_requests, through: :project | ||
has_many :staged_requests, class_name: 'BsRequest', through: :staging_projects | ||
|
||
def unassigned_requests | ||
target_of_bs_requests.in_states(['new', 'review']) - staged_requests - ignored_requests | ||
end | ||
|
||
def ignored_requests | ||
BsRequest.none # TODO: define this method | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
src/api/db/migrate/20181016103905_add_staged_request_id_to_bs_requests.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class AddStagedRequestIdToBsRequests < ActiveRecord::Migration[5.2] | ||
def change | ||
change_table :bs_requests, bulk: true do |t| | ||
t.integer :staging_project_id | ||
t.index :staging_project_id | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FactoryBot.define do | ||
factory :staging_workflow do | ||
factory :staging_workflow_with_staging_projects do | ||
transient do | ||
staging_project_count { 2 } | ||
end | ||
|
||
after(:create) do |staging_workflow, evaluator| | ||
evaluator.staging_project_count.times do | ||
staging_workflow.staging_projects << create(:staging_project, workflow_project_name: staging_workflow.project.name) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe StagingWorkflow, type: :model do | ||
let(:project) { create(:project_with_package) } | ||
let(:staging_workflow) { create(:staging_workflow_with_staging_projects, project: project) } | ||
let(:staging_project) { staging_workflow.staging_projects.first } | ||
let(:source_project) { create(:project, name: 'source_project') } | ||
let(:target_package) { create(:package, name: 'target_package', project: project) } | ||
let(:source_package) { create(:package, name: 'source_package', project: source_project) } | ||
let(:bs_request) do | ||
create(:bs_request_with_submit_action, | ||
target_project: project.name, | ||
target_package: target_package.name, | ||
source_project: source_project.name, | ||
source_package: source_package.name) | ||
end | ||
|
||
describe '#unassigned_request' do | ||
subject { staging_workflow.unassigned_requests } | ||
|
||
context 'without requests in the main project' do | ||
it { expect(subject).to be_empty } | ||
end | ||
|
||
context 'with requests but not in staging projects' do | ||
before { bs_request } | ||
|
||
it { expect(subject).to contain_exactly(bs_request) } | ||
end | ||
|
||
context 'with requests but all of them are in staging projects' do | ||
before do | ||
bs_request.staging_project = staging_project | ||
bs_request.save | ||
end | ||
|
||
it { expect(subject).to be_empty } | ||
end | ||
|
||
context 'with requests and some are in staging projects and some not' do | ||
let!(:bs_request_2) do | ||
create(:bs_request_with_submit_action, | ||
target_project: project.name, | ||
target_package: target_package.name, | ||
source_project: source_project.name, | ||
source_package: source_package.name) | ||
end | ||
|
||
before do | ||
bs_request.staging_project = staging_project | ||
bs_request.save | ||
end | ||
|
||
it { expect(subject).to contain_exactly(bs_request_2) } | ||
end | ||
end | ||
end |