Commit 705d0a434ff561f665b28d9bd5e341b4fb5377c8
1 parent
1c9dcfde
Exists in
master
and in
29 other branches
ActionItem26: adding some extra validations
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1876 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
34 additions
and
8 deletions
Show diff stats
app/models/event.rb
1 | class Event < Article | 1 | class Event < Article |
2 | 2 | ||
3 | - def self.description | ||
4 | - _('A calendar event') | ||
5 | - end | ||
6 | - | ||
7 | - def self.short_description | ||
8 | - _('Event') | ||
9 | - end | ||
10 | - | ||
11 | acts_as_having_settings :field => :body | 3 | acts_as_having_settings :field => :body |
12 | 4 | ||
13 | settings_items :description, :type => :string | 5 | settings_items :description, :type => :string |
@@ -17,4 +9,23 @@ class Event < Article | @@ -17,4 +9,23 @@ class Event < Article | ||
17 | settings_items :end_date, :type => :date | 9 | settings_items :end_date, :type => :date |
18 | 10 | ||
19 | validates_presence_of :title, :start_date | 11 | validates_presence_of :title, :start_date |
12 | + | ||
13 | + validates_each :start_date do |event,field,value| | ||
14 | + if event.end_date && event.start_date && event.start_date > event.end_date | ||
15 | + event.errors.add(:start_date, _('%{fn} cannot come before end date.')) | ||
16 | + end | ||
17 | + end | ||
18 | + | ||
19 | + def self.description | ||
20 | + _('A calendar event') | ||
21 | + end | ||
22 | + | ||
23 | + def self.short_description | ||
24 | + _('Event') | ||
25 | + end | ||
26 | + | ||
27 | + def icon_name | ||
28 | + 'event' | ||
29 | + end | ||
30 | + | ||
20 | end | 31 | end |
test/unit/event_test.rb
@@ -56,4 +56,19 @@ class EventTest < ActiveSupport::TestCase | @@ -56,4 +56,19 @@ class EventTest < ActiveSupport::TestCase | ||
56 | e = Event.create!(:name => 'bli', :start_date => Date.new(2008, 06, 06), :profile => profile, :description => 'my surprisingly long description about my freaking nice event') | 56 | e = Event.create!(:name => 'bli', :start_date => Date.new(2008, 06, 06), :profile => profile, :description => 'my surprisingly long description about my freaking nice event') |
57 | assert_includes Event.find_by_contents('surprisingly'), e | 57 | assert_includes Event.find_by_contents('surprisingly'), e |
58 | end | 58 | end |
59 | + | ||
60 | + should 'use its own icon' do | ||
61 | + assert_equal 'event', Event.new.icon_name | ||
62 | + end | ||
63 | + | ||
64 | + should 'not allow end date before start date' do | ||
65 | + e = Event.new(:start_date => Date.new(2008, 01, 01), :end_date => Date.new(2007,01,01)) | ||
66 | + e.valid? | ||
67 | + assert e.errors.invalid?(:start_date) | ||
68 | + | ||
69 | + e.end_date = Date.new(2008,01,05) | ||
70 | + e.valid? | ||
71 | + assert !e.errors.invalid?(:start_date) | ||
72 | + end | ||
73 | + | ||
59 | end | 74 | end |