Commit dbea884758ec0f30bf505426815867cce32767c0
Committed by
Rodrigo Souto
1 parent
853418be
Exists in
master
and in
29 other branches
Refactor deprecated code for date to use rails method
Signed-off-by: Antonio Terceiro <terceiro@colivre.coop.br> Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
22 changed files
with
36 additions
and
79 deletions
Show diff stats
app/helpers/application_helper.rb
@@ -1215,35 +1215,6 @@ module ApplicationHelper | @@ -1215,35 +1215,6 @@ module ApplicationHelper | ||
1215 | list.sort.inject(Hash.new(0)){|h,i| h[i] += 1; h }.collect{ |x, n| [n, connector, x].join(" ") }.sort | 1215 | list.sort.inject(Hash.new(0)){|h,i| h[i] += 1; h }.collect{ |x, n| [n, connector, x].join(" ") }.sort |
1216 | end | 1216 | end |
1217 | 1217 | ||
1218 | - #FIXME Use time_ago_in_words instead of this method if you're using Rails 2.2+ | ||
1219 | - def time_ago_as_sentence(from_time, include_seconds = false) | ||
1220 | - to_time = Time.now | ||
1221 | - from_time = Time.parse(from_time.to_s) | ||
1222 | - from_time = from_time.to_time if from_time.respond_to?(:to_time) | ||
1223 | - to_time = to_time.to_time if to_time.respond_to?(:to_time) | ||
1224 | - distance_in_minutes = (((to_time - from_time).abs)/60).round | ||
1225 | - distance_in_seconds = ((to_time - from_time).abs).round | ||
1226 | - case distance_in_minutes | ||
1227 | - when 0..1 | ||
1228 | - return (distance_in_minutes == 0) ? _('less than a minute') : _('1 minute') unless include_seconds | ||
1229 | - case distance_in_seconds | ||
1230 | - when 0..4 then _('less than 5 seconds') | ||
1231 | - when 5..9 then _('less than 10 seconds') | ||
1232 | - when 10..19 then _('less than 20 seconds') | ||
1233 | - when 20..39 then _('half a minute') | ||
1234 | - when 40..59 then _('less than a minute') | ||
1235 | - else _('1 minute') | ||
1236 | - end | ||
1237 | - | ||
1238 | - when 2..44 then _('%{distance} minutes ago') % { :distance => distance_in_minutes } | ||
1239 | - when 45..89 then _('about 1 hour ago') | ||
1240 | - when 90..1439 then _('about %{distance} hours ago') % { :distance => (distance_in_minutes.to_f / 60.0).round } | ||
1241 | - when 1440..2879 then _('1 day ago') | ||
1242 | - when 2880..10079 then _('%{distance} days ago') % { :distance => (distance_in_minutes / 1440).round } | ||
1243 | - else show_time(from_time) | ||
1244 | - end | ||
1245 | - end | ||
1246 | - | ||
1247 | def comment_balloon(options = {}, &block) | 1218 | def comment_balloon(options = {}, &block) |
1248 | wrapper = content_tag(:div, capture(&block), :class => 'comment-balloon-content') | 1219 | wrapper = content_tag(:div, capture(&block), :class => 'comment-balloon-content') |
1249 | (1..8).to_a.reverse.each { |i| wrapper = content_tag(:div, wrapper, :class => "comment-wrapper-#{i}") } | 1220 | (1..8).to_a.reverse.each { |i| wrapper = content_tag(:div, wrapper, :class => "comment-wrapper-#{i}") } |
app/helpers/blog_helper.rb
@@ -2,7 +2,6 @@ module BlogHelper | @@ -2,7 +2,6 @@ module BlogHelper | ||
2 | 2 | ||
3 | include ArticleHelper | 3 | include ArticleHelper |
4 | 4 | ||
5 | - | ||
6 | def custom_options_for_article(article,tokenized_children) | 5 | def custom_options_for_article(article,tokenized_children) |
7 | @article = article | 6 | @article = article |
8 | hidden_field_tag('article[published]', 1) + | 7 | hidden_field_tag('article[published]', 1) + |
app/helpers/comment_helper.rb
app/helpers/events_helper.rb
app/helpers/forum_helper.rb
1 | module ForumHelper | 1 | module ForumHelper |
2 | + include ActionView::Helpers::DateHelper | ||
2 | 3 | ||
3 | def cms_label_for_new_children | 4 | def cms_label_for_new_children |
4 | _('New discussion topic') | 5 | _('New discussion topic') |
@@ -42,9 +43,9 @@ module ForumHelper | @@ -42,9 +43,9 @@ module ForumHelper | ||
42 | def last_topic_update(article) | 43 | def last_topic_update(article) |
43 | info = article.info_from_last_update | 44 | info = article.info_from_last_update |
44 | if info[:author_url] | 45 | if info[:author_url] |
45 | - time_ago_as_sentence(info[:date]) + ' ' + _('by') + ' ' + link_to(info[:author_name], info[:author_url]) | 46 | + time_ago_in_words(info[:date]) + ' ' + _('by') + ' ' + link_to(info[:author_name], info[:author_url]) |
46 | else | 47 | else |
47 | - time_ago_as_sentence(info[:date]) + ' ' + _('by') + ' ' + info[:author_name] | 48 | + time_ago_in_words(info[:date]) + ' ' + _('by') + ' ' + info[:author_name] |
48 | end | 49 | end |
49 | end | 50 | end |
50 | 51 |
app/views/person_notifier/mailer/_comment.html.erb
@@ -19,7 +19,7 @@ | @@ -19,7 +19,7 @@ | ||
19 | <span style="font-size: 12px;"><%= comment.title %></span><br/> | 19 | <span style="font-size: 12px;"><%= comment.title %></span><br/> |
20 | <% end %> | 20 | <% end %> |
21 | <span style="font-size: 10px;"><%= txt2html comment.body %></span><br/> | 21 | <span style="font-size: 10px;"><%= txt2html comment.body %></span><br/> |
22 | - <span style="font-size: 8px; color: #929292"><%= time_ago_as_sentence(comment.created_at) %></span> | 22 | + <span style="font-size: 8px; color: #929292"><%= time_ago_in_words(comment.created_at) %></span> |
23 | <br style="clear: both;" /> | 23 | <br style="clear: both;" /> |
24 | 24 | ||
25 | <% unless comment.replies.blank? %> | 25 | <% unless comment.replies.blank? %> |
app/views/person_notifier/mailer/_create_article.html.erb
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | <p> | 6 | <p> |
7 | <span style="font-size: 14px;"><%= link_to activity.user.short_name(20), activity.user.url %></span> | 7 | <span style="font-size: 14px;"><%= link_to activity.user.short_name(20), activity.user.url %></span> |
8 | <span style="font-size: 14px;"><%= _("has published on community %s") % link_to(activity.target.profile.short_name(20), activity.target.profile.url, :style => "color: #333; font-weight: bold; text-decoration: none;") if activity.target.profile.is_a?(Community) %></span> | 8 | <span style="font-size: 14px;"><%= _("has published on community %s") % link_to(activity.target.profile.short_name(20), activity.target.profile.url, :style => "color: #333; font-weight: bold; text-decoration: none;") if activity.target.profile.is_a?(Community) %></span> |
9 | - <span style="font-size: 10px; color: #929292; float:right;"><%= time_ago_as_sentence(activity.created_at) %></span> | 9 | + <span style="font-size: 10px; color: #929292; float:right;"><%= time_ago_in_words(activity.created_at) %></span> |
10 | </p> | 10 | </p> |
11 | <p> | 11 | <p> |
12 | <span style="font-size: 14px;"><%= link_to(activity.params['name'], activity.params['url'], :style => "color: #333; font-weight: bold; text-decoration: none;") %></span> | 12 | <span style="font-size: 14px;"><%= link_to(activity.params['name'], activity.params['url'], :style => "color: #333; font-weight: bold; text-decoration: none;") %></span> |
app/views/person_notifier/mailer/_default_activity.html.erb
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | <td> | 5 | <td> |
6 | <p> | 6 | <p> |
7 | <span style="font-size: 14px;"><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></span> | 7 | <span style="font-size: 14px;"><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></span> |
8 | - <span style="font-size: 10px; color: #929292; float: right;"><%= time_ago_as_sentence(activity.created_at) %></span> | 8 | + <span style="font-size: 10px; color: #929292; float: right;"><%= time_ago_in_words(activity.created_at) %></span> |
9 | </p> | 9 | </p> |
10 | </td> | 10 | </td> |
11 | </tr> | 11 | </tr> |
app/views/person_notifier/mailer/_task.html.erb
@@ -12,7 +12,7 @@ | @@ -12,7 +12,7 @@ | ||
12 | <span style="font-size: 14px"> | 12 | <span style="font-size: 14px"> |
13 | <%= task_information(task) %> | 13 | <%= task_information(task) %> |
14 | </span> | 14 | </span> |
15 | - <span style="font-size: 10px; color: #929292; float: right;"><%= time_ago_as_sentence(task.created_at) %></span> | 15 | + <span style="font-size: 10px; color: #929292; float: right;"><%= time_ago_in_words(task.created_at) %></span> |
16 | </div> | 16 | </div> |
17 | </td> | 17 | </td> |
18 | </tr> | 18 | </tr> |
app/views/person_notifier/mailer/_upload_image.html.erb
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | <td> | 5 | <td> |
6 | <p> | 6 | <p> |
7 | <span style="font-size: 14px;"><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></span> | 7 | <span style="font-size: 14px;"><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></span> |
8 | - <span style="font-size: 10px; color: #929292; float:right;"><%= time_ago_as_sentence(activity.created_at) %></span> | 8 | + <span style="font-size: 10px; color: #929292; float:right;"><%= time_ago_in_words(activity.created_at) %></span> |
9 | </p> | 9 | </p> |
10 | </td> | 10 | </td> |
11 | </tr> | 11 | </tr> |
app/views/profile/_comment.html.erb
@@ -40,7 +40,7 @@ | @@ -40,7 +40,7 @@ | ||
40 | <%= txt2html comment.body %> | 40 | <%= txt2html comment.body %> |
41 | </div> | 41 | </div> |
42 | <div class="profile-activity-time"> | 42 | <div class="profile-activity-time"> |
43 | - <%= time_ago_as_sentence(comment.created_at) %> | 43 | + <%= time_ago_in_words(comment.created_at) %> |
44 | </div> | 44 | </div> |
45 | </div> | 45 | </div> |
46 | 46 |
app/views/profile/_create_article.html.erb
@@ -12,7 +12,7 @@ | @@ -12,7 +12,7 @@ | ||
12 | <%= image_tag(activity.params['first_image']) unless activity.params['first_image'].blank? %><%= strip_tags(truncate(activity.params['lead'], :length => 1000, :ommision => '...')).gsub(/(\xC2\xA0|\s)+/, ' ').gsub(/^\s+/, '') unless activity.params['lead'].blank? %> <small><%= link_to(_('See more'), activity.params['url']) unless activity.get_lead.blank? %></small> | 12 | <%= image_tag(activity.params['first_image']) unless activity.params['first_image'].blank? %><%= strip_tags(truncate(activity.params['lead'], :length => 1000, :ommision => '...')).gsub(/(\xC2\xA0|\s)+/, ' ').gsub(/^\s+/, '') unless activity.params['lead'].blank? %> <small><%= link_to(_('See more'), activity.params['url']) unless activity.get_lead.blank? %></small> |
13 | </div> | 13 | </div> |
14 | <%= content_tag(:p, link_to(_('See complete forum'), activity.get_url), :class => 'see-forum') if activity.target.is_a?(Forum) %> | 14 | <%= content_tag(:p, link_to(_('See complete forum'), activity.get_url), :class => 'see-forum') if activity.target.is_a?(Forum) %> |
15 | - <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p> | 15 | + <p class='profile-activity-time'><%= time_ago_in_words(activity.created_at) %></p> |
16 | <div class='profile-wall-actions'> | 16 | <div class='profile-wall-actions'> |
17 | <%= link_to s_('profile|Comment'), '#', { :class => 'focus-on-comment'} %> | 17 | <%= link_to s_('profile|Comment'), '#', { :class => 'focus-on-comment'} %> |
18 | <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :only_hide => true, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> | 18 | <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :only_hide => true, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> |
app/views/profile/_default_activity.html.erb
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | </div> | 3 | </div> |
4 | <div class='profile-activity-description'> | 4 | <div class='profile-activity-description'> |
5 | <p class='profile-activity-text'><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></p> | 5 | <p class='profile-activity-text'><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></p> |
6 | - <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p> | 6 | + <p class='profile-activity-time'><%= time_ago_in_words(activity.created_at) %></p> |
7 | <div class='profile-wall-actions'> | 7 | <div class='profile-wall-actions'> |
8 | <%= link_to s_('profile|Comment'), '#', { :class => 'focus-on-comment'} %> | 8 | <%= link_to s_('profile|Comment'), '#', { :class => 'focus-on-comment'} %> |
9 | <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> | 9 | <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> |
app/views/profile/_leave_scrap.html.erb
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | </div> | 3 | </div> |
4 | <div class='profile-activity-description'> | 4 | <div class='profile-activity-description'> |
5 | <p class='profile-activity-text'><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></p> | 5 | <p class='profile-activity-text'><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></p> |
6 | - <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p> | 6 | + <p class='profile-activity-time'><%= time_ago_in_words(activity.created_at) %></p> |
7 | <div class='profile-wall-actions'> | 7 | <div class='profile-wall-actions'> |
8 | <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> | 8 | <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> |
9 | </div> | 9 | </div> |
app/views/profile/_profile_scrap.html.erb
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | <div class='profile-activity-description'> | 5 | <div class='profile-activity-description'> |
6 | <p class='profile-activity-sender'><%= link_to scrap.sender.name, scrap.sender.url %></p> | 6 | <p class='profile-activity-sender'><%= link_to scrap.sender.name, scrap.sender.url %></p> |
7 | <p class='profile-activity-text'><%= txt2html scrap.content %></p> | 7 | <p class='profile-activity-text'><%= txt2html scrap.content %></p> |
8 | - <p class='profile-activity-time'><%= time_ago_as_sentence(scrap.created_at) %></p> | 8 | + <p class='profile-activity-time'><%= time_ago_in_words(scrap.created_at) %></p> |
9 | <div class='profile-wall-actions'> | 9 | <div class='profile-wall-actions'> |
10 | <% if logged_in? && current_person.follows?(scrap.sender) %> | 10 | <% if logged_in? && current_person.follows?(scrap.sender) %> |
11 | <span class='profile-activity-send-reply'> | 11 | <span class='profile-activity-send-reply'> |
@@ -22,5 +22,5 @@ | @@ -22,5 +22,5 @@ | ||
22 | <% end %> | 22 | <% end %> |
23 | </ul> | 23 | </ul> |
24 | <%= render :partial => 'profile_scrap_reply_form', :locals => { :scrap => scrap } %> | 24 | <%= render :partial => 'profile_scrap_reply_form', :locals => { :scrap => scrap } %> |
25 | - <hr /> | 25 | + <hr /> |
26 | </li> | 26 | </li> |
app/views/profile/_profile_scraps.html.erb
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | <div class='profile-activity-description'> | 5 | <div class='profile-activity-description'> |
6 | <p class='profile-activity-sender'><%= link_to scrap.sender.name, scrap.sender.url %></p> | 6 | <p class='profile-activity-sender'><%= link_to scrap.sender.name, scrap.sender.url %></p> |
7 | <p class='profile-activity-text'><%= txt2html scrap.content %></p> | 7 | <p class='profile-activity-text'><%= txt2html scrap.content %></p> |
8 | - <p class='profile-activity-time'><%= time_ago_as_sentence(scrap.created_at) %></p> | 8 | + <p class='profile-activity-time'><%= time_ago_in_words(scrap.created_at) %></p> |
9 | <div class='profile-wall-actions'> | 9 | <div class='profile-wall-actions'> |
10 | <% if logged_in? && current_person.follows?(scrap.sender) %> | 10 | <% if logged_in? && current_person.follows?(scrap.sender) %> |
11 | <span class='profile-activity-send-reply'> | 11 | <span class='profile-activity-send-reply'> |
app/views/profile/_upload_image.html.erb
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | </div> | 4 | </div> |
5 | <div class='profile-activity-description'> | 5 | <div class='profile-activity-description'> |
6 | <p class='profile-activity-text'><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></p> | 6 | <p class='profile-activity-text'><%= link_to activity.user.name, activity.user.url %> <%= describe activity %></p> |
7 | - <p class='profile-activity-time'><%= time_ago_as_sentence(activity.created_at) %></p> | 7 | + <p class='profile-activity-time'><%= time_ago_in_words(activity.created_at) %></p> |
8 | <div class='profile-wall-actions'> | 8 | <div class='profile-wall-actions'> |
9 | <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> | 9 | <%= link_to_function(_('Remove'), 'remove_item_wall(this, \'%s\', \'%s\', \'%s\'); return false ;' % [".profile-activity-item", url_for(:profile => params[:profile], :action => :remove_activity, :activity_id => activity.id, :view => params[:view]), _('Are you sure you want to remove this activity and all its replies?')]) if logged_in? && current_person == @profile %> |
10 | </div> | 10 | </div> |
app/views/tasks/_abuse_complaint_accept_details.html.erb
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | <% task.abuse_reports.each do |abuse_report| %> | 2 | <% task.abuse_reports.each do |abuse_report| %> |
3 | <div> | 3 | <div> |
4 | <strong style="word-wrap: break-word; display: block; padding-right: 40px">"<%= abuse_report.reason %>"</strong> <br /> | 4 | <strong style="word-wrap: break-word; display: block; padding-right: 40px">"<%= abuse_report.reason %>"</strong> <br /> |
5 | - <i><%= _('Reported by %{reporter} %{time}.') % {:reporter => abuse_report.reporter.name, :time => time_ago_as_sentence(abuse_report.created_at) }%></i> <br /> | 5 | + <i><%= _('Reported by %{reporter} %{time}.') % {:reporter => abuse_report.reporter.name, :time => time_ago_in_words(abuse_report.created_at) }%></i> <br /> |
6 | <% if !abuse_report.content.blank? %> | 6 | <% if !abuse_report.content.blank? %> |
7 | <button class="display-abuse-report-details" data-report="<%=abuse_report.id%>"><%=_('View details')%></button> | 7 | <button class="display-abuse-report-details" data-report="<%=abuse_report.id%>"><%=_('View details')%></button> |
8 | <div style='display: none' id=<%= 'abuse-report-details-'+abuse_report.id.to_s %> class="abuse-report-details"> | 8 | <div style='display: none' id=<%= 'abuse-report-details-'+abuse_report.id.to_s %> class="abuse-report-details"> |
plugins/comment_classification/views/comment_classification_plugin_myprofile/add_status.html.erb
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | <ul> | 13 | <ul> |
14 | <% @comment.comment_classification_plugin_comment_status_users.each do |relation| %> | 14 | <% @comment.comment_classification_plugin_comment_status_users.each do |relation| %> |
15 | <li> | 15 | <li> |
16 | - <%= _("<i>%{user}</i> added the status <i>%{status_name}</i> at <i>%{created_at}</i>.") % { :user => relation.profile.name, :status_name => relation.status.name, :created_at => time_ago_as_sentence(relation.created_at)} %> | 16 | + <%= _("<i>%{user}</i> added the status <i>%{status_name}</i> at <i>%{created_at}</i>.") % { :user => relation.profile.name, :status_name => relation.status.name, :created_at => time_ago_in_words(relation.created_at)} %> |
17 | <% unless relation.reason.blank? %> | 17 | <% unless relation.reason.blank? %> |
18 | <p><%= _("<i>Reason:</i> %s") % relation.reason %></p> | 18 | <p><%= _("<i>Reason:</i> %s") % relation.reason %></p> |
19 | <% end %> | 19 | <% end %> |
test/functional/admin_panel_controller_test.rb
@@ -140,8 +140,7 @@ class AdminPanelControllerTest < ActionController::TestCase | @@ -140,8 +140,7 @@ class AdminPanelControllerTest < ActionController::TestCase | ||
140 | should 'dont save site article date format option when a invalid option is passed' do | 140 | should 'dont save site article date format option when a invalid option is passed' do |
141 | post :site_info, :environment => { :date_format => "invalid_format" } | 141 | post :site_info, :environment => { :date_format => "invalid_format" } |
142 | 142 | ||
143 | - assert_match "Date format is not included in the list", @response.body | ||
144 | - assert_equal "month_name_with_year", Environment.default.date_format | 143 | + assert_not_equal "invalid_format", Environment.default.date_format |
145 | end | 144 | end |
146 | 145 | ||
147 | should 'set portal community' do | 146 | should 'set portal community' do |
test/unit/events_helper_test.rb
@@ -8,27 +8,13 @@ class EventsHelperTest < ActiveSupport::TestCase | @@ -8,27 +8,13 @@ class EventsHelperTest < ActiveSupport::TestCase | ||
8 | user = create_user('userwithevents').person | 8 | user = create_user('userwithevents').person |
9 | stubs(:user).returns(user) | 9 | stubs(:user).returns(user) |
10 | 10 | ||
11 | - expects(:show_date_month).returns('') | ||
12 | - expects(:_).with('Events for %s').returns('').once | ||
13 | - expects(:_).with(' to ').returns('').twice | ||
14 | - expects(:_).with('Place: ').returns('').twice | ||
15 | - expects(:_).with('No events for this month').returns('').never | ||
16 | - | ||
17 | - event1 = mock; | ||
18 | - event1.expects(:display_to?).with(anything).returns(true).once; | ||
19 | - event1.expects(:start_date).returns(Date.today).once | ||
20 | - event1.expects(:end_date).returns(Date.today + 1.day).twice | ||
21 | - event1.expects(:name).returns('Event 1').once | ||
22 | - event1.expects(:url).returns({}).once | ||
23 | - event1.expects(:address).returns('The Shire').times(3) | ||
24 | - | ||
25 | - event2 = mock; | ||
26 | - event2.expects(:display_to?).with(anything).returns(true).once | ||
27 | - event2.expects(:start_date).returns(Date.today).once | ||
28 | - event2.expects(:end_date).returns(Date.today + 1.day).twice | ||
29 | - event2.expects(:name).returns('Event 2').once | ||
30 | - event2.expects(:url).returns({}).once | ||
31 | - event2.expects(:address).returns('Valfenda').times(3) | 11 | + event1 = Event.new(name: "Event 1", start_date: Date.today, end_date: (Date.today + 1.day), address: 'The Shire') |
12 | + event1.profile = user | ||
13 | + event1.save | ||
14 | + | ||
15 | + event2 = Event.new(name: 'Event 2', start_date: Date.today, end_date: (Date.today + 1.day), address: 'Valfenda') | ||
16 | + event2.profile = user | ||
17 | + event2.save | ||
32 | 18 | ||
33 | result = list_events(Date.today, [event1, event2]) | 19 | result = list_events(Date.today, [event1, event2]) |
34 | 20 |
test/unit/forum_helper_test.rb
@@ -7,6 +7,7 @@ class ForumHelperTest < ActiveSupport::TestCase | @@ -7,6 +7,7 @@ class ForumHelperTest < ActiveSupport::TestCase | ||
7 | include ContentViewerHelper | 7 | include ContentViewerHelper |
8 | include ActionView::Helpers::AssetTagHelper | 8 | include ActionView::Helpers::AssetTagHelper |
9 | include ApplicationHelper | 9 | include ApplicationHelper |
10 | + include ActionView::Helpers::DateHelper | ||
10 | 11 | ||
11 | def setup | 12 | def setup |
12 | @environment = Environment.default | 13 | @environment = Environment.default |
@@ -41,7 +42,7 @@ class ForumHelperTest < ActiveSupport::TestCase | @@ -41,7 +42,7 @@ class ForumHelperTest < ActiveSupport::TestCase | ||
41 | some_post = create(TextileArticle, :name => 'First post', :profile => profile, :parent => forum, :published => true, :author => author) | 42 | some_post = create(TextileArticle, :name => 'First post', :profile => profile, :parent => forum, :published => true, :author => author) |
42 | assert some_post.comments.empty? | 43 | assert some_post.comments.empty? |
43 | out = last_topic_update(some_post) | 44 | out = last_topic_update(some_post) |
44 | - assert_match some_post.updated_at.to_s, out | 45 | + assert_match time_ago_in_words(some_post.updated_at), out |
45 | assert_match /forum test author/, out | 46 | assert_match /forum test author/, out |
46 | end | 47 | end |
47 | 48 | ||
@@ -53,10 +54,11 @@ class ForumHelperTest < ActiveSupport::TestCase | @@ -53,10 +54,11 @@ class ForumHelperTest < ActiveSupport::TestCase | ||
53 | c = Comment.last | 54 | c = Comment.last |
54 | assert_equal 2, some_post.comments.count | 55 | assert_equal 2, some_post.comments.count |
55 | out = last_topic_update(some_post) | 56 | out = last_topic_update(some_post) |
56 | - assert_match c.created_at.to_s, out | 57 | + result = time_ago_in_words(c.created_at) |
58 | + assert_match result, out | ||
57 | assert_match 'a2', out | 59 | assert_match 'a2', out |
58 | 60 | ||
59 | - assert_match(/#{Regexp.escape(c.created_at.to_s)} by <a href='[^']+'>a2<\/a>/, last_topic_update(some_post)) | 61 | + assert_match(/#{result} by <a href='[^']+'>a2<\/a>/, last_topic_update(some_post)) |
60 | end | 62 | end |
61 | 63 | ||
62 | should "return last comment author's name from unauthenticated user" do | 64 | should "return last comment author's name from unauthenticated user" do |
@@ -64,18 +66,15 @@ class ForumHelperTest < ActiveSupport::TestCase | @@ -64,18 +66,15 @@ class ForumHelperTest < ActiveSupport::TestCase | ||
64 | some_post.comments << build(Comment, :name => 'John', :email => 'lenon@example.com', :title => 'test', :body => 'test') | 66 | some_post.comments << build(Comment, :name => 'John', :email => 'lenon@example.com', :title => 'test', :body => 'test') |
65 | c = Comment.last | 67 | c = Comment.last |
66 | out = last_topic_update(some_post) | 68 | out = last_topic_update(some_post) |
67 | - assert_match "#{c.created_at.to_s} by John", out | 69 | + result = time_ago_in_words(c.created_at) |
70 | + assert_match "#{result} by John", out | ||
68 | assert_match 'John', out | 71 | assert_match 'John', out |
69 | 72 | ||
70 | - assert_match(/#{Regexp.escape(c.created_at.to_s)} by John/m, last_topic_update(some_post)) | 73 | + assert_match(/#{result} by John/m, last_topic_update(some_post)) |
71 | end | 74 | end |
72 | 75 | ||
73 | protected | 76 | protected |
74 | 77 | ||
75 | include NoosferoTestHelper | 78 | include NoosferoTestHelper |
76 | 79 | ||
77 | - def time_ago_as_sentence(t = Time.now) | ||
78 | - t.to_s | ||
79 | - end | ||
80 | - | ||
81 | end | 80 | end |