Skip to content

Commit

Permalink
Use strings instead of constans to get rid of circular dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
danidoni authored and hellcp-work committed Apr 19, 2024
1 parent 0510314 commit aa898e2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/api/app/models/decision.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Decision < ApplicationRecord
TYPES = [::DecisionFavored, ::DecisionCleared].freeze
TYPES = %w[DecisionFavored DecisionCleared].freeze

validates :reason, presence: true, length: { maximum: 65_535 }
validates :type, presence: true, length: { maximum: 255 }
Expand All @@ -23,7 +23,8 @@ def description

# List of all viable types for a reportable, used in the decision creation form
def self.types(reportable)
TYPES.filter_map do |decision_type|
TYPES.filter_map do |decision_type_name|
decision_type = decision_type_name.constantize
[decision_type.display_name, decision_type.name] if decision_type.display?(reportable)

Check warning on line 28 in src/api/app/models/decision.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/models/decision.rb#L26-L28

Added lines #L26 - L28 were not covered by tests
end.compact.to_h
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/lib/tasks/dev/reports.rake
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace :dev do

Report.find_each do |report|
# Reports with even id will be 'cleared' (0). Those with odd id will be 'favor' (1).
Decision.create!(reason: "Just because! #{report.id}", moderator: admin, type: Decision::TYPES[(report.id % 2)].name, reports: [report])
Decision.create!(reason: "Just because! #{report.id}", moderator: admin, type: Decision::TYPES[(report.id % 2)], reports: [report])
end

# The same decision applies to more than one report about the same object/reportable.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'decision' # To break the circular dependency between Decision and DecisionFavored and DecisionCleared

RSpec.describe NotificationActionDescriptionComponent, type: :component do
context 'when the notification is for a Event::RequestStatechange event with a request having only a target' do
let(:target_project) { create(:project, name: 'project_123') }
Expand Down

0 comments on commit aa898e2

Please sign in to comment.