Commit 73d011600d8f59b6f53292f114619642acae1448
Exists in
staging
and in
32 other branches
Merge branch 'comment-profile-and-environment-relation' into 'master'
comment: make explicit fail-safe relation with profile and environment This tests are necessary because comment estabilishes a polymorphic relation with the source, which creates harsh conditions to determine how to relate it with the environment. See merge request !819
Showing
1 changed file
with
9 additions
and
1 deletions
Show diff stats
app/models/comment.rb
@@ -115,7 +115,15 @@ class Comment < ActiveRecord::Base | @@ -115,7 +115,15 @@ class Comment < ActiveRecord::Base | ||
115 | end | 115 | end |
116 | 116 | ||
117 | delegate :environment, :to => :profile | 117 | delegate :environment, :to => :profile |
118 | - delegate :profile, :to => :source, :allow_nil => true | 118 | + |
119 | + def environment | ||
120 | + profile && profile.respond_to?(:environment) ? profile.environment : nil | ||
121 | + end | ||
122 | + | ||
123 | + def profile | ||
124 | + return unless source | ||
125 | + source.kind_of?(Profile) ? source : source.profile | ||
126 | + end | ||
119 | 127 | ||
120 | include Noosfero::Plugin::HotSpot | 128 | include Noosfero::Plugin::HotSpot |
121 | 129 |