Commit fb1f86684d8764608dbb80ced415671ef4f09a7f
Committed by
Thiago Ribeiro
1 parent
c3e29103
Exists in
master
and in
53 other branches
Add unit tests for software_events_block
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> (cherry picked from commit 3dc54c1d8b1d79bb2d32c872b02c8d0517f1cdee)
Showing
2 changed files
with
44 additions
and
2 deletions
Show diff stats
src/noosfero-spb/software_communities/lib/software_events_block.rb
@@ -9,8 +9,7 @@ class SoftwareEventsBlock < Block | @@ -9,8 +9,7 @@ class SoftwareEventsBlock < Block | ||
9 | end | 9 | end |
10 | 10 | ||
11 | def content(args={}) | 11 | def content(args={}) |
12 | - today = DateTime.now.beginning_of_day | ||
13 | - events = self.owner.events.where("end_date >= ?", today).order(:start_date) | 12 | + events = community_events |
14 | 13 | ||
15 | block = self | 14 | block = self |
16 | 15 | ||
@@ -25,4 +24,9 @@ class SoftwareEventsBlock < Block | @@ -25,4 +24,9 @@ class SoftwareEventsBlock < Block | ||
25 | def cacheable? | 24 | def cacheable? |
26 | false | 25 | false |
27 | end | 26 | end |
27 | + | ||
28 | + def community_events | ||
29 | + today = DateTime.now.beginning_of_day | ||
30 | + self.owner.events.where("end_date >= ?", today).order(:start_date) | ||
31 | + end | ||
28 | end | 32 | end |
src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb
0 → 100644
@@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | ||
3 | + | ||
4 | +class SoftwareEventsBlockTest < ActiveSupport::TestCase | ||
5 | + include PluginTestHelper | ||
6 | + | ||
7 | + def setup | ||
8 | + @community = create_community("A new community") | ||
9 | + @software_events_block = SoftwareEventsBlock.new | ||
10 | + | ||
11 | + box = Box.new | ||
12 | + box.owner = @community | ||
13 | + box.blocks << @software_events_block | ||
14 | + box.save! | ||
15 | + end | ||
16 | + | ||
17 | + should "give community events that have not yet finished ordered by start date" do | ||
18 | + assert_equal true, @software_events_block.community_events.empty? | ||
19 | + | ||
20 | + e1 = Event.new :name=>"Event 1", :body=>"Event 1 body", | ||
21 | + :start_date=>DateTime.now, :end_date=>(DateTime.now + 1.month) | ||
22 | + | ||
23 | + e2 = Event.new :name=>"Event 2", :body=>"Event 2 body", | ||
24 | + :start_date=>(DateTime.now - 10.days), :end_date=>(DateTime.now + 10.days) | ||
25 | + | ||
26 | + e3 = Event.new :name=>"Event 3", :body=>"Event 3 body", | ||
27 | + :start_date=>(DateTime.now - 20.days), :end_date=>(DateTime.now - 10.days) | ||
28 | + | ||
29 | + @community.events << e1 | ||
30 | + @community.events << e2 | ||
31 | + @community.events << e3 | ||
32 | + @community.save! | ||
33 | + | ||
34 | + assert_equal false, @software_events_block.community_events.include?(e3) | ||
35 | + assert_equal e2, @software_events_block.community_events.first | ||
36 | + assert_equal e1, @software_events_block.community_events.last | ||
37 | + end | ||
38 | +end |