Move filtering todos by projects not pending deletion into a scope on the todo model

This commit is contained in:
DJ Mountney 2016-05-30 10:59:14 -07:00
parent 4ecc10fade
commit 4280575fc0
2 changed files with 2 additions and 7 deletions

View file

@ -23,13 +23,7 @@ class TodosFinder
end
def execute
items = current_user.todos
# Filter out todos linked to project pending deletion
items = items.joins(
'INNER JOIN projects ON projects.id = todos.project_id AND projects.pending_delete = false'
)
items = current_user.todos.not_pending_delete
items = by_action_id(items)
items = by_author(items)
items = by_project(items)

View file

@ -19,6 +19,7 @@ class Todo < ActiveRecord::Base
scope :pending, -> { with_state(:pending) }
scope :done, -> { with_state(:done) }
scope :not_pending_delete, -> { joins('INNER JOIN projects ON projects.id = todos.project_id AND projects.pending_delete = false') }
state_machine :state, initial: :pending do
event :done do