The default values for Context#created_at and Project#created_at introduced in [440] were breaking rails' timestamp mixin and leaving created_at fields null. This changeset includes a migration to ensure that those columns contain no null values and backs out those changes. This fixes #454 but does risk reintroducing #438.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@461 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2007-02-27 04:07:22 +00:00
parent 146c6a62f9
commit 0a01b138a0
8 changed files with 34 additions and 42 deletions

View file

@ -40,15 +40,6 @@ class Context < ActiveRecord::Base
s += "Context is #{hidden? ? 'Hidden' : 'Active'}. "
s += "</p>"
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
end

View file

@ -59,15 +59,7 @@ class Project < ActiveRecord::Base
def title
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?

View file

@ -0,0 +1,25 @@
class SetNilTimestamps < ActiveRecord::Migration
class Project < ActiveRecord::Base; end
class Context < ActiveRecord::Base; end
def self.up
Project.find_all_by_created_at(nil).each do |p|
Project.update( p.id, {:created_at => Time.now.utc} )
end
Project.find_all_by_updated_at(nil).each do |p|
Project.update( p.id, {:updated_at => Time.now.utc} )
end
Context.find_all_by_created_at(nil).each do |p|
Context.update( p.id, {:created_at => Time.now.utc} )
end
Context.find_all_by_updated_at(nil).each do |p|
Context.update( p.id, {:updated_at => Time.now.utc} )
end
end
def self.down
#nothing to do here...
end
end

View file

@ -2,7 +2,7 @@
# migrations feature of ActiveRecord to incrementally modify your database, and
# then regenerate this schema definition.
ActiveRecord::Schema.define(:version => 29) do
ActiveRecord::Schema.define(:version => 30) do
create_table "contexts", :force => true do |t|
t.column "name", :string, :default => "", :null => false

View file

@ -57,8 +57,8 @@ library:
position: 6
hide: false
user_id: 1
created_at: nil
updated_at: nil
created_at: <%= today %>
updated_at: <%= today %>
freetime:
id: 7

View file

@ -24,8 +24,8 @@ moremoney:
position: 2
state: 'active'
user_id: 1
created_at: nil
updated_at: nil
created_at: <%= today %>
updated_at: <%= today %>
gardenclean:
id: 3

View file

@ -112,13 +112,5 @@ class ContextTest < Test::Unit::TestCase
def test_title_reader_returns_name
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

View file

@ -146,13 +146,5 @@ class ProjectTest < Test::Unit::TestCase
def test_title_reader_returns_name
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