mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
commit
05c18d139e
2 changed files with 14 additions and 1 deletions
|
|
@ -45,7 +45,7 @@ class Todo < ActiveRecord::Base
|
|||
# other scopes
|
||||
scope :are_due, -> { where 'NOT (todos.due IS NULL)' }
|
||||
scope :due_today, -> { where("todos.due <= ?", Time.zone.now) }
|
||||
scope :with_tag, lambda { |tag_id| joins("INNER JOIN taggings ON todos.id = taggings.taggable_id").where("taggings.tag_id = ? ", tag_id) }
|
||||
scope :with_tag, lambda { |tag_id| joins("INNER JOIN taggings ON todos.id = taggings.taggable_id").where("taggings.tag_id = ? AND taggings.taggable_type='Todo'", tag_id) }
|
||||
scope :with_tags, lambda { |tag_ids| where("EXISTS(SELECT * from taggings t WHERE t.tag_id IN (?) AND t.taggable_id=todos.id AND t.taggable_type='Todo')", tag_ids) }
|
||||
scope :completed_after, lambda { |date| where("todos.completed_at > ?", date) }
|
||||
scope :completed_before, lambda { |date| where("todos.completed_at < ?", date) }
|
||||
|
|
|
|||
|
|
@ -471,6 +471,19 @@ class TodoTest < ActiveSupport::TestCase
|
|||
assert_equal 2, todos_with_aORc_and_b.count
|
||||
end
|
||||
|
||||
def test_find_tagged_todos_of_correct_taggable_type
|
||||
recurring = Todo.where(:recurring_todo_id => 1).first.reload
|
||||
recurring.tag_list = "recurring_tag"
|
||||
recurring.save!
|
||||
recurring.recurring_todo.tag_list = "recurring_tag"
|
||||
recurring.recurring_todo.save!
|
||||
|
||||
tag_id = Tag.where(:name => "recurring_tag").first.id
|
||||
tagged_todos = Todo.with_tag(tag_id)
|
||||
assert_equal 1, tagged_todos.count
|
||||
assert_equal recurring.id, tagged_todos.first.id
|
||||
end
|
||||
|
||||
# test named_scopes
|
||||
def test_find_completed
|
||||
# Given 2 completed todos, one completed now and one completed 2 months ago
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue