Permalink
Browse files

adding the release date to the Game model.

  • Loading branch information...
1 parent b747d1c commit b8eafc48d330416db83fac1695f4e4becc468b3f @eightbitraptor committed Mar 6, 2012
Showing with 26 additions and 3 deletions.
  1. +9 −0 db/migrate/20120306184905_add_release_date_to_games.rb
  2. +4 −3 db/schema.rb
  3. +13 −0 spec/models/game_spec.rb
@@ -0,0 +1,9 @@
+class AddReleaseDateToGames < ActiveRecord::Migration
+ def change
+ add_column :games,
+ :release_date,
+ :datetime,
+ null: false,
+ default: Time.new(1900, 01, 01)
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120121164910) do
+ActiveRecord::Schema.define(:version => 20120306184905) do
create_table "consoles", :force => true do |t|
t.string "name"
@@ -25,8 +25,9 @@
t.string "title"
t.string "publisher"
t.integer "console_id"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.datetime "release_date", :default => '1899-12-31 23:00:00', :null => false
end
end
View
@@ -5,4 +5,17 @@
it { should validate_presence_of :publisher }
it { should belong_to :console }
+
+ context "#release_date" do
+ it "defaults to 01-01-1900" do
+ game = Game.new(title: 'foo', publisher: 'bar')
+ game.release_date.should == Time.new(1900, 01, 01)
+ end
+
+ it "can be overridden" do
+ date = Date.today
+ game = Game.new(title: 'foo', publisher: 'bar', release_date: date)
+ game.release_date.should == date
+ end
+ end
end

0 comments on commit b8eafc4

Please sign in to comment.