Tasks creation (mostly)

This commit is contained in:
2026-03-21 14:48:27 +02:00
parent dbd849589b
commit fb9d884313
15 changed files with 81 additions and 37 deletions
+1
View File
@@ -8,6 +8,7 @@ class Project < ApplicationRecord
has_many :tasks, dependent: :restrict_with_exception
has_many :task_statuses, dependent: :destroy
has_many :workflows, dependent: :destroy
has_rich_text :description
+2 -2
View File
@@ -34,8 +34,8 @@ class Task < ApplicationRecord
private
def associations_should_have_same_project
return if status&.project == project
return if [project, status.project, workflow.project].uniq == [project]
errors.add(:status, "Doesn't belong in the same project")
errors.add(:base, "Project isn't the same across associations")
end
end
+9
View File
@@ -8,6 +8,15 @@ class TaskStatus < ApplicationRecord
validates :name, presence: true, uniqueness: { scope: :project }
validates :category, presence: true
validate :associations_should_have_same_project
scope :default_order, -> { order(:category, :name) }
private
def associations_should_have_same_project
return if workflow.project == project
errors.add(:workflow, "Doesn't belong in the same project")
end
end
+1 -1
View File
@@ -4,7 +4,7 @@ class Workflow < ApplicationRecord
belongs_to :project
has_many :tasks, dependent: :restrict_with_exception
has_mnay :statuses, dependent: :restrict_with_error
has_many :statuses, dependent: :restrict_with_error
enum :icon, { task: 'task', warning: 'warning' }, default: 'task', scopes: false
enum :color, { blue: 'blue', gray: 'gray', yellow: 'yellow', red: 'red' }, default: 'gray', scopes: false