Tasks creation (mostly)
This commit is contained in:
@@ -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
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user