mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-29 05:18:49 +01:00
fix #1271. Don't block an already blocked todo. Create tests for this case
This commit is contained in:
parent
4db90386a8
commit
dcb155d90d
6 changed files with 158 additions and 61 deletions
|
|
@ -342,5 +342,49 @@ class TodoTest < ActiveSupport::TestCase
|
|||
assert 2, todos_with_aORc_and_b.count
|
||||
end
|
||||
|
||||
# test named_scopes
|
||||
def test_find_completed
|
||||
# Given 2 completed todos, one completed now and one completed 2 months ago
|
||||
@not_completed1.toggle_completion!
|
||||
@completed.completed_at = 2.months.ago
|
||||
@completed.save!
|
||||
|
||||
completed_old = @completed
|
||||
completed_now = @not_completed1
|
||||
|
||||
# When I use the finders
|
||||
recent_completed_todos = Todo.completed_after(1.month.ago).find(:all)
|
||||
older_completed_todos = Todo.completed_before(1.month.ago).find(:all)
|
||||
|
||||
# Then completed1 should be before and completed2 should be after a month ago
|
||||
assert older_completed_todos.include?(completed_old)
|
||||
assert recent_completed_todos.include?(completed_now)
|
||||
|
||||
# And completed1 should not be after and completed2 should not be before a month ago
|
||||
assert !older_completed_todos.include?(completed_now)
|
||||
assert !recent_completed_todos.include?(completed_old)
|
||||
end
|
||||
|
||||
def test_find_created
|
||||
# Given 2 created todos, one created now and one created 2 months ago
|
||||
user = @completed.user
|
||||
todo_old = user.todos.create!({:description => "created long long ago", :context => @completed.context})
|
||||
todo_old.created_at = 2.months.ago
|
||||
todo_old.save!
|
||||
todo_now = user.todos.create!({:description => "just created", :context => @completed.context})
|
||||
|
||||
# When I use the finders
|
||||
recent_created_todos = Todo.created_after(1.month.ago).find(:all)
|
||||
older_created_todos = Todo.created_before(1.month.ago).find(:all)
|
||||
|
||||
# Then todo1 should be before and todo2 should be after a month ago
|
||||
assert older_created_todos.include?(todo_old)
|
||||
assert recent_created_todos.include?(todo_now)
|
||||
|
||||
# And todo1 should not be after and todo2 should not be before a month ago
|
||||
assert !older_created_todos.include?(todo_now)
|
||||
assert !recent_created_todos.include?(todo_old)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||
require 'date'
|
||||
|
||||
class TodoTest < ActiveSupport::TestCase
|
||||
fixtures :todos, :recurring_todos, :users, :contexts, :preferences, :tags, :taggings, :projects
|
||||
|
||||
def setup
|
||||
@not_completed1 = Todo.find(1).reload
|
||||
@not_completed2 = Todo.find(2).reload
|
||||
@completed = Todo.find(8).reload
|
||||
end
|
||||
|
||||
# test named_scopes
|
||||
def test_find_completed
|
||||
# Given 2 completed todos, one completed now and one completed 2 months ago
|
||||
@not_completed1.toggle_completion!
|
||||
@completed.completed_at = 2.months.ago
|
||||
@completed.save!
|
||||
|
||||
completed_old = @completed
|
||||
completed_now = @not_completed1
|
||||
|
||||
# When I use the finders
|
||||
recent_completed_todos = Todo.completed_after(1.month.ago).find(:all)
|
||||
older_completed_todos = Todo.completed_before(1.month.ago).find(:all)
|
||||
|
||||
# Then completed1 should be before and completed2 should be after a month ago
|
||||
assert older_completed_todos.include?(completed_old)
|
||||
assert recent_completed_todos.include?(completed_now)
|
||||
|
||||
# And completed1 should not be after and completed2 should not be before a month ago
|
||||
assert !older_completed_todos.include?(completed_now)
|
||||
assert !recent_completed_todos.include?(completed_old)
|
||||
end
|
||||
|
||||
def test_find_created
|
||||
# Given 2 created todos, one created now and one created 2 months ago
|
||||
user = @completed.user
|
||||
todo_old = user.todos.create!({:description => "created long long ago", :context => @completed.context})
|
||||
todo_old.created_at = 2.months.ago
|
||||
todo_old.save!
|
||||
todo_now = user.todos.create!({:description => "just created", :context => @completed.context})
|
||||
|
||||
# When I use the finders
|
||||
recent_created_todos = Todo.created_after(1.month.ago).find(:all)
|
||||
older_created_todos = Todo.created_before(1.month.ago).find(:all)
|
||||
|
||||
# Then todo1 should be before and todo2 should be after a month ago
|
||||
assert older_created_todos.include?(todo_old)
|
||||
assert recent_created_todos.include?(todo_now)
|
||||
|
||||
# And todo1 should not be after and todo2 should not be before a month ago
|
||||
assert !older_created_todos.include?(todo_now)
|
||||
assert !recent_created_todos.include?(todo_old)
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue