Commit 5a2e9ad1145a9db4849fb39a774006a37dd9ad5a

Authored by Francisco Marcelo de Araújo Lima Júnior
1 parent 2a1682e1

#community dashboard - add unit test

plugins/community_hub/lib/community_hub_plugin/hub_helper.rb
1 module CommunityHubPlugin::HubHelper 1 module CommunityHubPlugin::HubHelper
2 2
3 - def post_css_classes(post_id, latest_post_id, oldest_post_id)  
4 - classes = "post"  
5 -  
6 - if post_id == latest_post_id  
7 - classes += " latest"  
8 - end  
9 -  
10 - if post_id == oldest_post_id  
11 - classes += " oldest"  
12 - end  
13 -  
14 - classes  
15 - end  
16 -  
17 def mediator?(hub) 3 def mediator?(hub)
18 logged_in? && (hub.author.id == user.id || hub.mediators.include?(user.id)) ? true : false 4 logged_in? && (hub.author.id == user.id || hub.mediators.include?(user.id)) ? true : false
19 end 5 end
@@ -31,15 +17,7 @@ module CommunityHubPlugin::HubHelper @@ -31,15 +17,7 @@ module CommunityHubPlugin::HubHelper
31 end 17 end
32 18
33 def post_time(time) 19 def post_time(time)
34 - if time  
35 - _('%{hour}:%{minutes}') % { :hour => time.hour, :minutes => time.strftime("%M") }  
36 - else  
37 - ''  
38 - end  
39 - end  
40 -  
41 - def embed_code(hub)  
42 - "<iframe width='425' height='350' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='#{url_for(hub.url)}'></iframe>" 20 + _('%{hour}:%{minutes}') % { :hour => time.hour, :minutes => time.strftime("%M") } rescue ''
43 end 21 end
44 22
45 -end  
46 \ No newline at end of file 23 \ No newline at end of file
  24 +end
plugins/community_hub/test/unit/community_hub_plugin/hub_helper_test.rb 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +require File.dirname(__FILE__) + '/../../test_helper'
  2 +
  3 +class HubHelperTest < ActiveSupport::TestCase
  4 +
  5 + include CommunityHubPlugin::HubHelper
  6 + include NoosferoTestHelper
  7 +
  8 + should 'return time formated to hh:mm' do
  9 + t = Time.utc(2014,"jan",1,17,40,0)
  10 + assert_equal post_time(t), "17:40"
  11 + end
  12 +
  13 + should 'return empty string if param is not time' do
  14 + i = 1
  15 + assert_equal post_time(i), ''
  16 + end
  17 +
  18 +end
plugins/community_hub/views/community_hub_plugin_public/_mediation.rhtml
1 <% extend CommunityHubPlugin::HubHelper %> 1 <% extend CommunityHubPlugin::HubHelper %>
2 2
3 -<li id="<%= mediation.id %>" class="<%=post_css_classes(mediation.id, latest_post, oldest_post)%>"> 3 +<li id="<%= mediation.id %>" class="post">
4 4
5 <ul> 5 <ul>
6 <li class="time"><%= post_time(mediation.created_at) %></li> 6 <li class="time"><%= post_time(mediation.created_at) %></li>