Commit e6f69622ad7438edac966a2ebf725df2d87db46b

Authored by Daniela Feitosa
2 parents 12917e41 5717fe77

Merge branch 'fix_event_block_display_bug' into 'master'

Fix event block display bug

Bug fix for block when there was no event to be displayed

Issue #594

See merge request !118
src/noosfero-spb/software_communities/lib/software_events_block.rb
... ... @@ -8,6 +8,10 @@ class SoftwareEventsBlock < Block
8 8 _('This block displays the software community events in a list.')
9 9 end
10 10  
  11 + def default_title
  12 + _('Other events')
  13 + end
  14 +
11 15 def content(args={})
12 16 block = self
13 17  
... ... @@ -34,8 +38,8 @@ class SoftwareEventsBlock < Block
34 38 get_events.where("slug NOT IN (?)", event_slug)
35 39 end
36 40  
37   - def has_events_to_display?
38   - not get_events.empty?
  41 + def has_events_to_display? current_event_slug=""
  42 + not get_events_except(current_event_slug).empty?
39 43 end
40 44  
41 45 def should_display_title?
... ...
src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb
... ... @@ -46,12 +46,22 @@ class SoftwareEventsBlockTest < ActiveSupport::TestCase
46 46 should "tell if there are events to be displayed" do
47 47 assert_equal true, @software_events_block.has_events_to_display?
48 48  
49   - @community.events.update_all :start_date => (DateTime.now - 2.days),
50   - :end_date => (DateTime.now - 1.day)
  49 + update_all_events (DateTime.now - 2.days), (DateTime.now - 1.day)
51 50  
52 51 assert_equal false, @software_events_block.has_events_to_display?
53 52 end
54 53  
  54 + should "tell if there are events to be displayed when given a event page slug" do
  55 + update_all_events (DateTime.now - 2.days), (DateTime.now - 1.day)
  56 +
  57 + last_event = @community.events.last
  58 + last_event.end_date = DateTime.now + 10.days
  59 + last_event.save!
  60 +
  61 + assert_equal true, @software_events_block.has_events_to_display?
  62 + assert_equal false, @software_events_block.has_events_to_display?(last_event.slug)
  63 + end
  64 +
55 65 should "tell that the block must show the title in other areas that are no the main area" do
56 66 assert_equal false, @software_events_block.should_display_title?
57 67  
... ... @@ -60,4 +70,10 @@ class SoftwareEventsBlockTest < ActiveSupport::TestCase
60 70  
61 71 assert_equal true, @software_events_block.should_display_title?
62 72 end
  73 +
  74 + private
  75 +
  76 + def update_all_events start_date, end_date
  77 + @community.events.update_all :start_date => start_date, :end_date => end_date
  78 + end
63 79 end
... ...
src/noosfero-spb/software_communities/views/blocks/software_events.html.erb
1   -<div class="software-community-events-block">
2   - <% if block.has_events_to_display? %>
  1 +<% if block.has_events_to_display? params[:page] %>
  2 + <div class="software-community-events-block">
3 3 <ul class="software-community-events-list">
4   -
5 4 <% if block.should_display_title? %>
6 5 <li class="software-events-list-item">
7 6 <span class="software-events-list-item-title">
... ... @@ -18,5 +17,5 @@
18 17 <% end %>
19 18  
20 19 </ul>
21   - <% end %>
22   -</div>
  20 + </div>
  21 +<% end %>
... ...