Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ gem 'bcrypt', '~> 3.1.7'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false

gem 'state_machines-activerecord'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: %i[mri mingw x64_mingw]
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
state_machines (0.5.0)
state_machines-activemodel (0.7.1)
activemodel (>= 4.1)
state_machines (>= 0.5.0)
state_machines-activerecord (0.6.0)
activerecord (>= 4.1)
state_machines-activemodel (>= 0.5.0)
thor (1.0.1)
thread_safe (0.3.6)
tilt (2.0.10)
Expand Down Expand Up @@ -229,6 +236,7 @@ DEPENDENCIES
rubocop
sass-rails (>= 6)
selenium-webdriver
state_machines-activerecord
web-console (>= 3.3.0)
webdrivers
webpacker (~> 4.0)
Expand Down
41 changes: 41 additions & 0 deletions app/models/task.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
class Task < ApplicationRecord
belongs_to :author, class_name: 'User'
belongs_to :assignee, class_name: 'User', optional: true

validates :name, presence: true
validates :description, presence: true
validates :author, presence: true
validates :description, length: { maximum: 500 }

state_machine initial: :new_task do
Comment thread
Leenday marked this conversation as resolved.
state :new_task
state :in_development
state :in_qa
state :in_codereview
state :ready_for_release
state :released
state :archived

event :develop do
transition %i[new_task in_qa in_codereview] => :in_development
end

event :qa do
transition in_development: :in_qa
end

event :codereview do
transition in_qa: :in_codereview
end

event :reviwed do
transition in_codereview: :ready_for_release
end

event :release do
transition ready_for_release: :released
end

event :archive do
transition %i[new_task released] => :archived
end
end
end
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
class User < ApplicationRecord
has_secure_password
has_many :my_tasks, class_name: 'Task', foreign_key: :author_id
has_many :assigned_tasks, class_name: 'Task', foreign_key: :assignee_id

validates :first_name, presence: true, length: { minimum: 2 }
validates :last_name, presence: true, length: { minimum: 2 }
validates :email, presence: true, uniqueness: true, format: { with: /\w*@{1}\w*/ }
end
5 changes: 3 additions & 2 deletions test/factories/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
factory :task do
name
description
author_id { 1 }
assignee_id { 1 }
state
expired_at

association :author, factory: :manager
association :assignee, factory: :developer
end
end