diff --git a/tracks/app/models/project.rb b/tracks/app/models/project.rb index 54c0469f..561b6a30 100644 --- a/tracks/app/models/project.rb +++ b/tracks/app/models/project.rb @@ -33,6 +33,10 @@ class Project < ActiveRecord::Base attr_protected :user + def self.null_object + NullProject.new + end + def description_present? attribute_present?("description") end @@ -42,3 +46,15 @@ class Project < ActiveRecord::Base end end + +class NullProject + + def hidden? + false + end + + def nil? + true + end + +end \ No newline at end of file diff --git a/tracks/app/models/todo.rb b/tracks/app/models/todo.rb index 5201ecf0..0f7ea2e0 100644 --- a/tracks/app/models/todo.rb +++ b/tracks/app/models/todo.rb @@ -14,6 +14,12 @@ class Todo < ActiveRecord::Base validates_length_of :notes, :maximum => 60000, :allow_nil => true # validates_chronic_date :due, :allow_nil => true + alias_method :original_project, :project + + def project + original_project.nil? ? Project.null_object : original_project + end + def self.not_done( id=id ) self.find(:all, :conditions =>[ "done = ? AND context_id = ?", false, id], :order =>"due IS NULL, due ASC, created_at ASC") end