Commit aa742f71b87348314767377ca94f6f262f6f3ff5
Committed by
Antonio Terceiro
1 parent
2ee3ddc7
Exists in
master
and in
28 other branches
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,6 +9,11 @@ class Event < Article | ||
| 9 | xss_terminate :only => [ :link ], :on => 'validation' | 9 | xss_terminate :only => [ :link ], :on => 'validation' |
| 10 | xss_terminate :only => [ :description, :link, :address ], :with => 'white_list', :on => 'validation' | 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 | validates_presence_of :title, :start_date | 17 | validates_presence_of :title, :start_date |
| 13 | 18 | ||
| 14 | validates_each :start_date do |event,field,value| | 19 | validates_each :start_date do |event,field,value| |
test/unit/event_test.rb
| @@ -35,8 +35,14 @@ class EventTest < ActiveSupport::TestCase | @@ -35,8 +35,14 @@ class EventTest < ActiveSupport::TestCase | ||
| 35 | assert_kind_of Date, e.start_date | 35 | assert_kind_of Date, e.start_date |
| 36 | end | 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 | should 'require start date' do | 43 | should 'require start date' do |
| 39 | e = Event.new | 44 | e = Event.new |
| 45 | + e.start_date = nil | ||
| 40 | e.valid? | 46 | e.valid? |
| 41 | assert e.errors.invalid?(:start_date) | 47 | assert e.errors.invalid?(:start_date) |
| 42 | e.start_date = Date.today | 48 | e.start_date = Date.today |