Commit 855e23ffb7becc3c47958eaf2124dfe25a0fd0b7
1 parent
33c30b1b
Exists in
master
and in
23 other branches
[tolerance-time] Making publication not crash if profile has no tolerance yet defined
Showing
2 changed files
with
14 additions
and
2 deletions
Show diff stats
plugins/tolerance_time/lib/tolerance_time_plugin/publication.rb
| @@ -13,10 +13,12 @@ class ToleranceTimePlugin::Publication < Noosfero::Plugin::ActiveRecord | @@ -13,10 +13,12 @@ class ToleranceTimePlugin::Publication < Noosfero::Plugin::ActiveRecord | ||
| 13 | def expired? | 13 | def expired? |
| 14 | profile = (target.kind_of?(Article) ? target.profile : target.article.profile) | 14 | profile = (target.kind_of?(Article) ? target.profile : target.article.profile) |
| 15 | profile_tolerance = ToleranceTimePlugin::Tolerance.find_by_profile_id(profile.id) | 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 | if target.kind_of?(Article) | 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 | elsif target.kind_of?(Comment) | 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 | else | 22 | else |
| 21 | tolerance_time = 1.0/0 | 23 | tolerance_time = 1.0/0 |
| 22 | end | 24 | end |
plugins/tolerance_time/test/unit/tolerance_time_plugin/publication_test.rb
| @@ -65,4 +65,14 @@ class ToleranceTimePlugin::PublicationTest < ActiveSupport::TestCase | @@ -65,4 +65,14 @@ class ToleranceTimePlugin::PublicationTest < ActiveSupport::TestCase | ||
| 65 | 65 | ||
| 66 | assert !article_publication.expired? | 66 | assert !article_publication.expired? |
| 67 | end | 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 | end | 78 | end |