Skip to content

Commit

Permalink
feat(fworks): further evaluation workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantk committed Nov 22, 2023
1 parent f8a598b commit c4ff053
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class ActivityLog::Types::Frameworks::Framework::EvaluationCreatedComponent < ViewComponent::Base
class ActivityLog::Types::Frameworks::Framework::EvaluationDraftedComponent < ViewComponent::Base
include ActivityLog::Types::BasicActivityDetails

def initialize(activity_log_item:)
Expand Down
9 changes: 9 additions & 0 deletions app/models/frameworks/evaluation/status_changeable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ module Frameworks::Evaluation::StatusChangeable
transitions from: :in_progress, to: :cancelled, after: :after_cancelling
end
end

scope :active, -> { where(status: %i[draft in_progress]) }
scope :other_active_evaluations_for, ->(evaluation) { active.where.not(id: evaluation.id).where(framework: evaluation.framework) }

validate :framework_has_no_other_active_evaliations
end

def permissible_status_change_options(prepend_current_status: false)
Expand All @@ -53,6 +58,10 @@ def able_to_change_status?

private

def framework_has_no_other_active_evaliations
errors.add(:framework, "Framework is already in active evaluation") if self.class.other_active_evaluations_for(self).any?
end

def after_drafting_of_evaluation
framework.draft_evaluation!(self)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/frameworks/framework/evaluatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module Frameworks::Framework::Evaluatable
extend ActiveSupport::Concern

included do
scope :for_evaluation, -> { by_status(%w[pending_evaluation not_approved]) }
scope :for_evaluation, -> { by_status(%w[not_approved]) }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ def status
:dfe_approved
elsif recommended.n?
:not_approved
elsif recommended.x?
:evaluating
end
end

Expand Down
27 changes: 27 additions & 0 deletions spec/models/frameworks/evaluation/status_changeable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,31 @@
end
end
end

describe "validations" do
context "when framework is already in active evaluation" do
let(:framework) { create(:frameworks_framework) }

it "is invalid" do
# existing evaluation
create(:frameworks_evaluation, framework:, status: "in_progress")

# Check 1 : attempting to create a new one
new_evaluation = build(:frameworks_evaluation, framework:)

# does not allow a framework in active evaluation
expect(new_evaluation).not_to be_valid

# allows a non active framework
new_evaluation.framework = create(:frameworks_framework)
expect(new_evaluation).to be_valid

# Check 2 : saving an existing evaluation
another_existing_evaluation = create(:frameworks_evaluation, framework: create(:frameworks_framework), status: "in_progress")

# you can save the evaluation (the framework is in an active evaluation - BUT it is this one so its ok)
expect(another_existing_evaluation).to be_valid
end
end
end
end

0 comments on commit c4ff053

Please sign in to comment.