Skip to content

Commit

Permalink
Fix Staging::Workflow#unassigned method
Browse files Browse the repository at this point in the history
we don't need to consider staged requests as the current workflow will remove
them anyway from the stageable association.
  • Loading branch information
ChrisBr committed Nov 20, 2018
1 parent 3d717e4 commit 0a0e701
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/api/app/models/staging/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def ready_to_stage
before_update :update_staging_projects_managers_group

def unassigned_requests
target_of_bs_requests.stageable.where.not(id: excluded_requests | staged_requests)
target_of_bs_requests.stageable.where.not(id: excluded_requests)
end

def ready_requests
Expand Down
18 changes: 14 additions & 4 deletions src/api/spec/models/staging/workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
RSpec.describe Staging::Workflow, type: :model do
let(:project) { create(:project_with_package, name: 'MyProject') }
let(:staging_workflow) { create(:staging_workflow_with_staging_projects, project: project) }
let(:group) { staging_workflow.managers_group }
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,
request_state: 'review',
request_state: :review,
target_project: project.name,
target_package: target_package.name,
source_project: source_project.name,
Expand All @@ -23,13 +24,19 @@
it { expect(subject).to be_empty }
end

context 'with requests but not in staging projects' do
context 'with requests without reviews by the staging managers group' do
before { bs_request }

it { expect(subject).to be_empty }
end

context 'with requests with reviews by the staging managers group' do
let!(:review) { create(:review, by_group: group.title, bs_request: bs_request) }

it { expect(subject).to contain_exactly(bs_request) }
end

context 'with requests but all of them are in staging projects' do
context 'with requests but all of them are already assigned' do
before do
bs_request.staging_project = staging_project
bs_request.save
Expand All @@ -39,12 +46,15 @@
end

context 'with requests and some are in staging projects and some not' do
let(:review2) { create(:review, by_group: group.title) }
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)
source_package: source_package.name,
reviews: [review2],
state: :review)
end

before do
Expand Down

0 comments on commit 0a0e701

Please sign in to comment.