--- /dev/null
+class VideoPolicy < ActiveRecord::Base
+ validates_presence_of :day
+ validates_presence_of :fee
+ validates_presence_of :period
+ validates_presence_of :description
+
+ validates_numericality_of :day
+ validates_numericality_of :fee
+ validates_numericality_of :period
+
+ # Find the base fee for today
+ def todays_fee
+ # Gets the current day of the week in 0-6 == Sun-Sat form
+ day_of_week = Time.now.to_date.wday
+ return VideoPolicy.find_by_day(day_of_week).fee
+ end
+
+ # Find the base rental period for today
+ def todays_period
+ # Gets the current day of the week in 0-6 == Sun-Sat form
+ day_of_week = Time.now.to_date.wday
+ return VideoPolicy.find_by_day(day_of_week).period
+ end
+
+ # Find the fee for overdue videos (per day)
+ def overdue_fee
+ overdue_day = 7
+ return VideoPolicy.find_by_day(overdue_day).fee
+ end
+
+ protected
+ def validate
+ errors.add(:fee, "must be greater than $0.01") if fee < 0.01
+ end
+end
--- /dev/null
+class CreateVideoPolicies < ActiveRecord::Migration
+ def self.up
+ create_table :video_policies do |t|
+ t.column :day, :integer, :null => false
+ t.column :fee, :decimal, :precision => 8, :scale => 2, :null => false
+ t.column :period, :integer
+ t.column :description, :string
+ end
+ end
+
+ def self.down
+ drop_table :video_policies
+ end
+end
# migrations feature of ActiveRecord to incrementally modify your database, and
# then regenerate this schema definition.
-ActiveRecord::Schema.define(:version => 21) do
+ActiveRecord::Schema.define(:version => 22) do
create_table "bitems", :force => true do |t|
t.column "customer_id", :integer, :null => false
# Could not dump table "sqlite_sequence" because of following StandardError
# Unknown type '' for column 'name'
+ create_table "video_policies", :force => true do |t|
+ t.column "day", :integer, :null => false
+ t.column "fee", :decimal, :precision => 8, :scale => 2, :null => false
+ t.column "period", :integer
+ t.column "description", :string
+ end
+
create_table "videogenres", :force => true do |t|
t.column "name", :string, :null => false
end
--- /dev/null
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+two:
+ id: 2
--- /dev/null
+require File.dirname(__FILE__) + '/../test_helper'
+
+class VideoPolicyTest < Test::Unit::TestCase
+ fixtures :video_policies
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end