-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This also adds some model validations to other models, which I'll add unit tests for in an upcoming commit. Fixtures also needed some fiddling to refer to the named user fixtures.
- Loading branch information
1 parent
128de98
commit b17f4db
Showing
7 changed files
with
91 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
class Setting < ApplicationRecord | ||
belongs_to :user | ||
|
||
validates_presence_of :user_id | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,23 @@ | ||
class Task < ApplicationRecord | ||
belongs_to :task_category | ||
belongs_to :user | ||
|
||
# Validation | ||
STATUS_TYPES = %w[INCOMPLETE COMPLETED].freeze | ||
|
||
validates_presence_of :user_id | ||
|
||
validates :summary, presence: true, | ||
length: { maximum: 150 } | ||
|
||
validates :priority, presence: true, | ||
inclusion: { in: 1..3 } | ||
|
||
validates :status, presence: true, | ||
inclusion: { in: STATUS_TYPES } | ||
|
||
# Scopes | ||
scope :incomplete, -> { where(status: :INCOMPLETE) } | ||
scope :completed, -> { where(status: :COMPLETED) } | ||
scope :no_due_date, -> { where("due_at IS NULL") } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
class TaskCategory < ApplicationRecord | ||
has_many :tasks | ||
belongs_to :user | ||
|
||
# Validation | ||
validates_presence_of :user_id | ||
|
||
validates :name, presence: true, | ||
length: { maximum: 50 }, | ||
uniqueness: { scope: :user_id } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters