Commit 3820e979a998918a514bd4956c89b6a9b3035b20
1 parent
1c48df3a
Exists in
web_steps_improvements
and in
8 other branches
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.
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 | 115 | end |
116 | 116 | |
117 | 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 | 128 | include Noosfero::Plugin::HotSpot |
121 | 129 | ... | ... |