From 5717fe772dac4a2cdd670d658aa15e9e927cd586 Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Wed, 6 Jan 2016 14:08:47 -0200 Subject: [PATCH] Fix bug when there was no event to be displayed --- src/noosfero-spb/software_communities/lib/software_events_block.rb | 8 ++++++-- src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb | 20 ++++++++++++++++++-- src/noosfero-spb/software_communities/views/blocks/software_events.html.erb | 9 ++++----- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/noosfero-spb/software_communities/lib/software_events_block.rb b/src/noosfero-spb/software_communities/lib/software_events_block.rb index a028d5c..3126474 100644 --- a/src/noosfero-spb/software_communities/lib/software_events_block.rb +++ b/src/noosfero-spb/software_communities/lib/software_events_block.rb @@ -8,6 +8,10 @@ class SoftwareEventsBlock < Block _('This block displays the software community events in a list.') end + def default_title + _('Other events') + end + def content(args={}) block = self @@ -34,8 +38,8 @@ class SoftwareEventsBlock < Block get_events.where("slug NOT IN (?)", event_slug) end - def has_events_to_display? - not get_events.empty? + def has_events_to_display? current_event_slug="" + not get_events_except(current_event_slug).empty? end def should_display_title? diff --git a/src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb b/src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb index fc9818f..b903617 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_events_block_test.rb @@ -46,12 +46,22 @@ class SoftwareEventsBlockTest < ActiveSupport::TestCase should "tell if there are events to be displayed" do assert_equal true, @software_events_block.has_events_to_display? - @community.events.update_all :start_date => (DateTime.now - 2.days), - :end_date => (DateTime.now - 1.day) + update_all_events (DateTime.now - 2.days), (DateTime.now - 1.day) assert_equal false, @software_events_block.has_events_to_display? end + should "tell if there are events to be displayed when given a event page slug" do + update_all_events (DateTime.now - 2.days), (DateTime.now - 1.day) + + last_event = @community.events.last + last_event.end_date = DateTime.now + 10.days + last_event.save! + + assert_equal true, @software_events_block.has_events_to_display? + assert_equal false, @software_events_block.has_events_to_display?(last_event.slug) + end + should "tell that the block must show the title in other areas that are no the main area" do assert_equal false, @software_events_block.should_display_title? @@ -60,4 +70,10 @@ class SoftwareEventsBlockTest < ActiveSupport::TestCase assert_equal true, @software_events_block.should_display_title? end + + private + + def update_all_events start_date, end_date + @community.events.update_all :start_date => start_date, :end_date => end_date + end end diff --git a/src/noosfero-spb/software_communities/views/blocks/software_events.html.erb b/src/noosfero-spb/software_communities/views/blocks/software_events.html.erb index 65dec68..e167800 100644 --- a/src/noosfero-spb/software_communities/views/blocks/software_events.html.erb +++ b/src/noosfero-spb/software_communities/views/blocks/software_events.html.erb @@ -1,7 +1,6 @@ -
- <% if block.has_events_to_display? %> +<% if block.has_events_to_display? params[:page] %> +
    - <% if block.should_display_title? %>
  • @@ -18,5 +17,5 @@ <% end %>
- <% end %> -
+
+<% end %> -- libgit2 0.21.2