Commit dbea884758ec0f30bf505426815867cce32767c0
Committed by
Rodrigo Souto
1 parent
853418be
Exists in
master
and in
22 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 | 1215 | list.sort.inject(Hash.new(0)){|h,i| h[i] += 1; h }.collect{ |x, n| [n, connector, x].join(" ") }.sort |
1216 | 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 | 1218 | def comment_balloon(options = {}, &block) |
1248 | 1219 | wrapper = content_tag(:div, capture(&block), :class => 'comment-balloon-content') |
1249 | 1220 | (1..8).to_a.reverse.each { |i| wrapper = content_tag(:div, wrapper, :class => "comment-wrapper-#{i}") } | ... | ... |
app/helpers/blog_helper.rb
app/helpers/comment_helper.rb
app/helpers/events_helper.rb
app/helpers/forum_helper.rb
1 | 1 | module ForumHelper |
2 | + include ActionView::Helpers::DateHelper | |
2 | 3 | |
3 | 4 | def cms_label_for_new_children |
4 | 5 | _('New discussion topic') |
... | ... | @@ -42,9 +43,9 @@ module ForumHelper |
42 | 43 | def last_topic_update(article) |
43 | 44 | info = article.info_from_last_update |
44 | 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 | 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 | 49 | end |
49 | 50 | end |
50 | 51 | ... | ... |
app/views/person_notifier/mailer/_comment.html.erb
... | ... | @@ -19,7 +19,7 @@ |
19 | 19 | <span style="font-size: 12px;"><%= comment.title %></span><br/> |
20 | 20 | <% end %> |
21 | 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 | 23 | <br style="clear: both;" /> |
24 | 24 | |
25 | 25 | <% unless comment.replies.blank? %> | ... | ... |
app/views/person_notifier/mailer/_create_article.html.erb
... | ... | @@ -6,7 +6,7 @@ |
6 | 6 | <p> |
7 | 7 | <span style="font-size: 14px;"><%= link_to activity.user.short_name(20), activity.user.url %></span> |
8 | 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 | 10 | </p> |
11 | 11 | <p> |
12 | 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 | 5 | <td> |
6 | 6 | <p> |
7 | 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 | 9 | </p> |
10 | 10 | </td> |
11 | 11 | </tr> | ... | ... |
app/views/person_notifier/mailer/_task.html.erb
... | ... | @@ -12,7 +12,7 @@ |
12 | 12 | <span style="font-size: 14px"> |
13 | 13 | <%= task_information(task) %> |
14 | 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 | 16 | </div> |
17 | 17 | </td> |
18 | 18 | </tr> | ... | ... |
app/views/person_notifier/mailer/_upload_image.html.erb
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | <td> |
6 | 6 | <p> |
7 | 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 | 9 | </p> |
10 | 10 | </td> |
11 | 11 | </tr> | ... | ... |
app/views/profile/_comment.html.erb
app/views/profile/_create_article.html.erb
... | ... | @@ -12,7 +12,7 @@ |
12 | 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 | 13 | </div> |
14 | 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 | 16 | <div class='profile-wall-actions'> |
17 | 17 | <%= link_to s_('profile|Comment'), '#', { :class => 'focus-on-comment'} %> |
18 | 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 | 3 | </div> |
4 | 4 | <div class='profile-activity-description'> |
5 | 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 | 7 | <div class='profile-wall-actions'> |
8 | 8 | <%= link_to s_('profile|Comment'), '#', { :class => 'focus-on-comment'} %> |
9 | 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 | 3 | </div> |
4 | 4 | <div class='profile-activity-description'> |
5 | 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 | 7 | <div class='profile-wall-actions'> |
8 | 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 | 9 | </div> | ... | ... |
app/views/profile/_profile_scrap.html.erb
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | <div class='profile-activity-description'> |
6 | 6 | <p class='profile-activity-sender'><%= link_to scrap.sender.name, scrap.sender.url %></p> |
7 | 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 | 9 | <div class='profile-wall-actions'> |
10 | 10 | <% if logged_in? && current_person.follows?(scrap.sender) %> |
11 | 11 | <span class='profile-activity-send-reply'> |
... | ... | @@ -22,5 +22,5 @@ |
22 | 22 | <% end %> |
23 | 23 | </ul> |
24 | 24 | <%= render :partial => 'profile_scrap_reply_form', :locals => { :scrap => scrap } %> |
25 | - <hr /> | |
25 | + <hr /> | |
26 | 26 | </li> | ... | ... |
app/views/profile/_profile_scraps.html.erb
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | <div class='profile-activity-description'> |
6 | 6 | <p class='profile-activity-sender'><%= link_to scrap.sender.name, scrap.sender.url %></p> |
7 | 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 | 9 | <div class='profile-wall-actions'> |
10 | 10 | <% if logged_in? && current_person.follows?(scrap.sender) %> |
11 | 11 | <span class='profile-activity-send-reply'> | ... | ... |
app/views/profile/_upload_image.html.erb
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | </div> |
5 | 5 | <div class='profile-activity-description'> |
6 | 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 | 8 | <div class='profile-wall-actions'> |
9 | 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 | 10 | </div> | ... | ... |
app/views/tasks/_abuse_complaint_accept_details.html.erb
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | <% task.abuse_reports.each do |abuse_report| %> |
3 | 3 | <div> |
4 | 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 | 6 | <% if !abuse_report.content.blank? %> |
7 | 7 | <button class="display-abuse-report-details" data-report="<%=abuse_report.id%>"><%=_('View details')%></button> |
8 | 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 | 13 | <ul> |
14 | 14 | <% @comment.comment_classification_plugin_comment_status_users.each do |relation| %> |
15 | 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 | 17 | <% unless relation.reason.blank? %> |
18 | 18 | <p><%= _("<i>Reason:</i> %s") % relation.reason %></p> |
19 | 19 | <% end %> | ... | ... |
test/functional/admin_panel_controller_test.rb
... | ... | @@ -140,8 +140,7 @@ class AdminPanelControllerTest < ActionController::TestCase |
140 | 140 | should 'dont save site article date format option when a invalid option is passed' do |
141 | 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 | 144 | end |
146 | 145 | |
147 | 146 | should 'set portal community' do | ... | ... |
test/unit/events_helper_test.rb
... | ... | @@ -8,27 +8,13 @@ class EventsHelperTest < ActiveSupport::TestCase |
8 | 8 | user = create_user('userwithevents').person |
9 | 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 | 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 | 7 | include ContentViewerHelper |
8 | 8 | include ActionView::Helpers::AssetTagHelper |
9 | 9 | include ApplicationHelper |
10 | + include ActionView::Helpers::DateHelper | |
10 | 11 | |
11 | 12 | def setup |
12 | 13 | @environment = Environment.default |
... | ... | @@ -41,7 +42,7 @@ class ForumHelperTest < ActiveSupport::TestCase |
41 | 42 | some_post = create(TextileArticle, :name => 'First post', :profile => profile, :parent => forum, :published => true, :author => author) |
42 | 43 | assert some_post.comments.empty? |
43 | 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 | 46 | assert_match /forum test author/, out |
46 | 47 | end |
47 | 48 | |
... | ... | @@ -53,10 +54,11 @@ class ForumHelperTest < ActiveSupport::TestCase |
53 | 54 | c = Comment.last |
54 | 55 | assert_equal 2, some_post.comments.count |
55 | 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 | 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 | 62 | end |
61 | 63 | |
62 | 64 | should "return last comment author's name from unauthenticated user" do |
... | ... | @@ -64,18 +66,15 @@ class ForumHelperTest < ActiveSupport::TestCase |
64 | 66 | some_post.comments << build(Comment, :name => 'John', :email => 'lenon@example.com', :title => 'test', :body => 'test') |
65 | 67 | c = Comment.last |
66 | 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 | 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 | 74 | end |
72 | 75 | |
73 | 76 | protected |
74 | 77 | |
75 | 78 | include NoosferoTestHelper |
76 | 79 | |
77 | - def time_ago_as_sentence(t = Time.now) | |
78 | - t.to_s | |
79 | - end | |
80 | - | |
81 | 80 | end | ... | ... |