Skip to content

Commit

Permalink
Generate date fields by default when Date class is given
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-za committed Apr 30, 2013
1 parent 7bb0682 commit deb5d02
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lib/dsl/data_types/primitives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ def self.default_mock

# Datetime
class Date < Base
def column_defaults
{:type => :date}
end

def self.default_mock
::Date.today
end
end

class Time < Date
def column_defaults
{:type => :datetime}
end
Expand All @@ -30,8 +40,6 @@ def self.default_mock
::Time.now
end
end

class Time < Date; end; # No different to date type

# Integers
class Fixnum < Base
Expand Down
1 change: 1 addition & 0 deletions test/rails_app/app/models/business.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Business < ActiveRecord::Base
mobile :string
operating_days 0..6
date_established :datetime
date_registered Date.today - 10.years
next_sale (Time.now + 10.days)
verified false, :default => false
location :type => :string, :limit => 127
Expand Down
3 changes: 2 additions & 1 deletion test/test_data_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class TestDataSchema < Test::Unit::TestCase

should "generate a datetime column when given a date or time example" do
assert_schema(Business, :date_established, :type => :datetime)
assert_schema(Business, :next_sale, :type => :datetime)
assert_schema(Business, :next_sale, :type => :datetime)
assert_schema(Business, :date_registered, :type => :date)
end

should "generate a smallint column when given a small range" do
Expand Down
1 change: 1 addition & 0 deletions test/verified_output/migrations/create_businesses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def self.up
t.integer :operating_days
t.datetime :date_established
t.datetime :next_sale
t.date :date_registered
t.boolean :verified
t.string :location, :limit=>127
t.text :awards
Expand Down

0 comments on commit deb5d02

Please sign in to comment.