Commit 3f6495ca7497659a99ad928edcb7c3c3258aef98
1 parent
d40fb9ce
Exists in
master
and in
29 other branches
ActionItem26: adding a basic event model + CMS implementation
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1873 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
95 additions
and
0 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -0,0 +1,20 @@ | @@ -0,0 +1,20 @@ | ||
1 | +class Event < Article | ||
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 | ||
12 | + | ||
13 | + settings_items :description, :type => :string | ||
14 | + settings_items :url, :type => :string | ||
15 | + | ||
16 | + settings_items :start_date, :type => :date | ||
17 | + settings_items :end_date, :type => :date | ||
18 | + | ||
19 | + validates_presence_of :title, :start_date | ||
20 | +end |
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | + | ||
2 | +<%# TODO add Textile help here %> | ||
3 | +<%= render :file => 'shared/tiny_mce' %> | ||
4 | + | ||
5 | +<%= f.text_field('name', :size => '64') %> | ||
6 | + | ||
7 | +<%= labelled_form_field(_('Description:'), text_area(:article, :description, :cols => 64)) %> | ||
8 | + | ||
9 | +<%= labelled_form_field(_('Start date'), date_select(:article, :start_date)) %> | ||
10 | + | ||
11 | +<%= labelled_form_field(_('End date'), date_select(:article, :end_date)) %> |
test/functional/favorite_enterprises_controller_test.rb
@@ -47,6 +47,8 @@ class FavoriteEnterprisesControllerTest < Test::Unit::TestCase | @@ -47,6 +47,8 @@ class FavoriteEnterprisesControllerTest < Test::Unit::TestCase | ||
47 | assert_difference profile.favorite_enterprises, :count do | 47 | assert_difference profile.favorite_enterprises, :count do |
48 | post :add, :id => favorite_enterprise.id, :confirmation => '1' | 48 | post :add, :id => favorite_enterprise.id, :confirmation => '1' |
49 | assert_response :redirect | 49 | assert_response :redirect |
50 | + | ||
51 | + profile.favorite_enterprises.reload | ||
50 | end | 52 | end |
51 | end | 53 | end |
52 | 54 | ||
@@ -65,6 +67,8 @@ class FavoriteEnterprisesControllerTest < Test::Unit::TestCase | @@ -65,6 +67,8 @@ class FavoriteEnterprisesControllerTest < Test::Unit::TestCase | ||
65 | assert_difference profile.favorite_enterprises, :count, -1 do | 67 | assert_difference profile.favorite_enterprises, :count, -1 do |
66 | post :remove, :id => favorite_enterprise.id, :confirmation => '1' | 68 | post :remove, :id => favorite_enterprise.id, :confirmation => '1' |
67 | assert_redirected_to :action => 'index' | 69 | assert_redirected_to :action => 'index' |
70 | + | ||
71 | + profile.favorite_enterprises.reload | ||
68 | end | 72 | end |
69 | end | 73 | end |
70 | 74 |
@@ -0,0 +1,59 @@ | @@ -0,0 +1,59 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class EventTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + should 'be an article' do | ||
6 | + assert_kind_of Article, Event.new | ||
7 | + end | ||
8 | + | ||
9 | + should 'provide description' do | ||
10 | + assert_kind_of String, Event.description | ||
11 | + end | ||
12 | + | ||
13 | + should 'provide short description' do | ||
14 | + assert_kind_of String, Event.short_description | ||
15 | + end | ||
16 | + | ||
17 | + should 'have a description' do | ||
18 | + e = Event.new(:description => 'some useful description') | ||
19 | + assert_equal 'some useful description', e.description | ||
20 | + end | ||
21 | + | ||
22 | + should 'have a url' do | ||
23 | + e = Event.new(:url => 'http://some.nice.site/') | ||
24 | + assert_equal 'http://some.nice.site/', e.url | ||
25 | + end | ||
26 | + | ||
27 | + should 'have a start date' do | ||
28 | + e = Event.new | ||
29 | + e.start_date = Date.today | ||
30 | + assert_kind_of Date, e.start_date | ||
31 | + end | ||
32 | + | ||
33 | + should 'require start date' do | ||
34 | + e = Event.new | ||
35 | + e.valid? | ||
36 | + assert e.errors.invalid?(:start_date) | ||
37 | + e.start_date = Date.today | ||
38 | + e.valid? | ||
39 | + assert !e.errors.invalid?(:start_date) | ||
40 | + end | ||
41 | + | ||
42 | + should 'have a end date' do | ||
43 | + e = Event.new | ||
44 | + e.end_date = Date.today | ||
45 | + assert_kind_of Date, e.end_date | ||
46 | + end | ||
47 | + | ||
48 | + should 'be indexed by title' do | ||
49 | + profile = create_user('testuser').person | ||
50 | + e = Event.create!(:name => 'my surprisingly nice event', :start_date => Date.new(2008, 06, 06), :profile => profile) | ||
51 | + assert_includes Event.find_by_contents('surprisingly'), e | ||
52 | + end | ||
53 | + | ||
54 | + should 'be indexed by description' do | ||
55 | + profile = create_user('testuser').person | ||
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 | ||
58 | + end | ||
59 | +end |