mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-27 20:38:48 +01:00
Move Project#create_from_todo to its own class
The point of this is to keep as many things out of the ActiveRecord objects as possible and use them as just a thin database abstraction layer.
This commit is contained in:
parent
18883c6ecc
commit
883ea2b968
5 changed files with 50 additions and 24 deletions
22
test/unit/project_from_todo_test.rb
Normal file
22
test/unit/project_from_todo_test.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
require_relative '../test_helper'
|
||||
require_relative '../../lib/project_from_todo'
|
||||
|
||||
class ProjectFromTodoTest < ActiveSupport::TestCase
|
||||
fixtures :todos
|
||||
|
||||
def test_create_project_from_valid_todo
|
||||
todo = todos(:upgrade_rails)
|
||||
project = ProjectFromTodo.new(todo).create
|
||||
assert_equal project.name, todo.description
|
||||
assert_equal project.description, todo.notes
|
||||
assert_equal project.default_context, todo.context
|
||||
end
|
||||
|
||||
def test_invalid_project_from_invalid_todo
|
||||
todo = todos(:upgrade_rails)
|
||||
todo.description = ""
|
||||
project = ProjectFromTodo.new(todo).create
|
||||
assert_not_nil project
|
||||
assert_equal false, project.valid?
|
||||
end
|
||||
end
|
||||
|
|
@ -167,14 +167,6 @@ class ProjectTest < ActiveSupport::TestCase
|
|||
assert_equal 3, @moremoney.todos.not_completed.count
|
||||
end
|
||||
|
||||
def test_convert_from_todo
|
||||
todo = todos(:upgrade_rails)
|
||||
project = Project.create_from_todo(todo)
|
||||
assert_equal project.name, todo.description
|
||||
assert_equal project.description, todo.notes
|
||||
assert_equal project.default_context, todo.context
|
||||
end
|
||||
|
||||
def test_new_record_before_save
|
||||
assert !@timemachine.new_record_before_save?, "existing records should not be new_record"
|
||||
p = Project.where(:name => "I do not exist").first_or_create
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue