mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-03 14:31:47 +01:00
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:
parent
146c6a62f9
commit
0a01b138a0
8 changed files with 34 additions and 42 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
|
|
|||
25
tracks/db/migrate/030_set_nil_timestamps.rb
Normal file
25
tracks/db/migrate/030_set_nil_timestamps.rb
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
4
tracks/test/fixtures/contexts.yml
vendored
4
tracks/test/fixtures/contexts.yml
vendored
|
|
@ -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
|
||||
|
|
|
|||
4
tracks/test/fixtures/projects.yml
vendored
4
tracks/test/fixtures/projects.yml
vendored
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue