Commit aa742f71b87348314767377ca94f6f262f6f3ff5

Authored by Rodrigo Souto
Committed by Antonio Terceiro
1 parent 2ee3ddc7

Setting start_date default value as today

(ActionItem1614)
Showing 2 changed files with 11 additions and 0 deletions   Show diff stats
app/models/event.rb
... ... @@ -9,6 +9,11 @@ class Event < Article
9 9 xss_terminate :only => [ :link ], :on => 'validation'
10 10 xss_terminate :only => [ :description, :link, :address ], :with => 'white_list', :on => 'validation'
11 11  
  12 + def initialize(*args)
  13 + super(*args)
  14 + self.start_date ||= Date.today
  15 + end
  16 +
12 17 validates_presence_of :title, :start_date
13 18  
14 19 validates_each :start_date do |event,field,value|
... ...
test/unit/event_test.rb
... ... @@ -35,8 +35,14 @@ class EventTest < ActiveSupport::TestCase
35 35 assert_kind_of Date, e.start_date
36 36 end
37 37  
  38 + should 'set start date default value as today' do
  39 + e = Event.new
  40 + assert_equal Date.today, e.start_date
  41 + end
  42 +
38 43 should 'require start date' do
39 44 e = Event.new
  45 + e.start_date = nil
40 46 e.valid?
41 47 assert e.errors.invalid?(:start_date)
42 48 e.start_date = Date.today
... ...