diff --git a/tracks/app/models/context.rb b/tracks/app/models/context.rb index 2a0f5538..df2cb434 100644 --- a/tracks/app/models/context.rb +++ b/tracks/app/models/context.rb @@ -41,5 +41,14 @@ class Context < ActiveRecord::Base s += "

" s end + + def created_at + read_attribute(:created_at) || Time.now.utc + end + + def updated_at + read_attribute(:updated_at) || Time.now.utc + end + end diff --git a/tracks/app/models/project.rb b/tracks/app/models/project.rb index 9f29b671..a583cb55 100644 --- a/tracks/app/models/project.rb +++ b/tracks/app/models/project.rb @@ -60,6 +60,14 @@ class Project < ActiveRecord::Base name end + def created_at + read_attribute(:created_at) || Time.now + end + + def updated_at + read_attribute(:updated_at) || Time.now + end + def summary(undone_todo_count) project_description = '' project_description += sanitize(markdown( description )) if description_present? diff --git a/tracks/config/environment.rb.tmpl b/tracks/config/environment.rb.tmpl index d1e352ee..8feebe5e 100644 --- a/tracks/config/environment.rb.tmpl +++ b/tracks/config/environment.rb.tmpl @@ -30,7 +30,7 @@ Rails::Initializer.run do |config| # config.active_record.observers = :cacher, :garbage_collector # Make Active Record use UTC-base instead of local time - # config.active_record.default_timezone = :utc + config.active_record.default_timezone = :utc # Use Active Record's schema dumper instead of SQL when creating the test database # (enables use of different database adapters for development and test environments) diff --git a/tracks/test/fixtures/contexts.yml b/tracks/test/fixtures/contexts.yml index 15d3af66..7c3a5ca0 100644 --- a/tracks/test/fixtures/contexts.yml +++ b/tracks/test/fixtures/contexts.yml @@ -57,8 +57,8 @@ library: position: 6 hide: false user_id: 1 - created_at: <%= today %> - updated_at: <%= today %> + created_at: nil + updated_at: nil freetime: id: 7 diff --git a/tracks/test/fixtures/projects.yml b/tracks/test/fixtures/projects.yml index 36404845..16b2c75c 100644 --- a/tracks/test/fixtures/projects.yml +++ b/tracks/test/fixtures/projects.yml @@ -24,8 +24,8 @@ moremoney: position: 2 state: 'active' user_id: 1 - created_at: <%= today %> - updated_at: <%= today %> + created_at: nil + updated_at: nil gardenclean: id: 3 diff --git a/tracks/test/functional/contexts_controller_test.rb b/tracks/test/functional/contexts_controller_test.rb index 8804be75..cd033984 100644 --- a/tracks/test/functional/contexts_controller_test.rb +++ b/tracks/test/functional/contexts_controller_test.rb @@ -59,7 +59,7 @@ class ContextsControllerTest < TodoContainerControllerTestBase %w(guid link).each do |node| assert_xml_select node, /http:\/\/test.host\/contexts\/.+/ end - assert_xml_select 'pubDate', contexts(:agenda).created_at.to_s(:rfc822) + assert_xml_select 'pubDate', /(#{contexts(:agenda).created_at.to_s(:rfc822)}|#{contexts(:library).created_at.to_s(:rfc822)})/ end end end @@ -94,7 +94,7 @@ class ContextsControllerTest < TodoContainerControllerTestBase assert_xml_select 'entry', 3 do assert_xml_select 'title', /.+/ assert_xml_select 'content[type="html"]', /<p>\d+ actions. Context is (active|hidden). <\/p>/ - assert_xml_select 'published', contexts(:agenda).created_at.to_s(:rfc822) + assert_xml_select 'published', /(#{contexts(:agenda).created_at.to_s(:rfc822)}|#{contexts(:library).created_at.to_s(:rfc822)})/ end end end diff --git a/tracks/test/functional/projects_controller_test.rb b/tracks/test/functional/projects_controller_test.rb index 4fbec5ae..d926bbd1 100644 --- a/tracks/test/functional/projects_controller_test.rb +++ b/tracks/test/functional/projects_controller_test.rb @@ -97,11 +97,11 @@ class ProjectsControllerTest < TodoContainerControllerTestBase %w(guid link).each do |node| assert_xml_select node, /http:\/\/test.host\/projects\/.+/ end - assert_xml_select 'pubDate', projects(:timemachine).created_at.to_s(:rfc822) + assert_xml_select 'pubDate', /(#{projects(:timemachine).updated_at.to_s(:rfc822)}|#{projects(:moremoney).updated_at.to_s(:rfc822)}})/ end end end - + def test_rss_feed_not_accessible_to_anonymous_user_without_token @request.session['user_id'] = nil get :index, { :format => "rss" } @@ -132,11 +132,11 @@ class ProjectsControllerTest < TodoContainerControllerTestBase assert_xml_select 'entry', 3 do assert_xml_select 'title', /.+/ assert_xml_select 'content[type="html"]', /<p>\d+ actions. Project is (active|hidden|completed). <\/p>/ - assert_xml_select 'published', projects(:timemachine).created_at.to_s(:rfc822) + assert_xml_select 'published', /(#{projects(:timemachine).updated_at.to_s(:rfc822)}|#{projects(:moremoney).updated_at.to_s(:rfc822)}})/ end end end - + def test_atom_feed_not_accessible_to_anonymous_user_without_token @request.session['user_id'] = nil get :index, { :format => "atom" } diff --git a/tracks/test/unit/context_test.rb b/tracks/test/unit/context_test.rb index 3afdbe89..028e4d86 100644 --- a/tracks/test/unit/context_test.rb +++ b/tracks/test/unit/context_test.rb @@ -6,6 +6,7 @@ class ContextTest < Test::Unit::TestCase def setup @agenda = contexts(:agenda) @email = contexts(:email) + @library = contexts(:library) end def test_validate_presence_of_name @@ -112,4 +113,12 @@ class ContextTest < Test::Unit::TestCase assert_equal @agenda.name, @agenda.title end + def test_created_at_returns_now_when_field_null + assert_equal Time.now.utc.to_s, @library.created_at.to_s + end + + def test_updated_at_returns_now_when_field_null + assert_equal Time.now.utc.to_s, @library.updated_at.to_s + end + end diff --git a/tracks/test/unit/project_test.rb b/tracks/test/unit/project_test.rb index 7b18729f..24f0a45f 100644 --- a/tracks/test/unit/project_test.rb +++ b/tracks/test/unit/project_test.rb @@ -147,4 +147,12 @@ class ProjectTest < Test::Unit::TestCase assert_equal @timemachine.name, @timemachine.title end + def test_created_at_returns_now_when_field_null + assert_equal Time.now.to_s, @moremoney.created_at.to_s + end + + def test_updated_at_returns_now_when_field_null + assert_equal Time.now.to_s, @moremoney.updated_at.to_s + end + end