Commit 855e23ffb7becc3c47958eaf2124dfe25a0fd0b7

Authored by Rodrigo Souto
1 parent 33c30b1b

[tolerance-time] Making publication not crash if profile has no tolerance yet defined

plugins/tolerance_time/lib/tolerance_time_plugin/publication.rb
... ... @@ -13,10 +13,12 @@ class ToleranceTimePlugin::Publication < Noosfero::Plugin::ActiveRecord
13 13 def expired?
14 14 profile = (target.kind_of?(Article) ? target.profile : target.article.profile)
15 15 profile_tolerance = ToleranceTimePlugin::Tolerance.find_by_profile_id(profile.id)
  16 + content_tolerance = profile_tolerance ? profile_tolerance.content_tolerance : nil
  17 + comment_tolerance = profile_tolerance ? profile_tolerance.comment_tolerance : nil
16 18 if target.kind_of?(Article)
17   - tolerance_time = profile_tolerance.content_tolerance || 1.0/0
  19 + tolerance_time = content_tolerance || 1.0/0
18 20 elsif target.kind_of?(Comment)
19   - tolerance_time = profile_tolerance.comment_tolerance || 1.0/0
  21 + tolerance_time = comment_tolerance || 1.0/0
20 22 else
21 23 tolerance_time = 1.0/0
22 24 end
... ...
plugins/tolerance_time/test/unit/tolerance_time_plugin/publication_test.rb
... ... @@ -65,4 +65,14 @@ class ToleranceTimePlugin::PublicationTest < ActiveSupport::TestCase
65 65  
66 66 assert !article_publication.expired?
67 67 end
  68 +
  69 + should 'not crash if profile has no tolerance yet defined' do
  70 + profile = fast_create(Profile)
  71 + article = fast_create(Article, :profile_id => profile.id)
  72 + article_publication = ToleranceTimePlugin::Publication.create!(:target => article)
  73 + article_publication.created_at = 1000.years.ago
  74 + article_publication.save!
  75 +
  76 + assert !article_publication.expired?
  77 + end
68 78 end
... ...