Commit 407b928a5cde9451d7009e006309feaaa8730b15

Authored by Victor Costa
1 parent 03304903
Exists in master

Not fail when the target model is not an active record

lib/merit/point_rules.rb
@@ -178,7 +178,7 @@ module Merit @@ -178,7 +178,7 @@ module Merit
178 target_url = AVAILABLE_RULES[rule_name.to_sym][:target_url] 178 target_url = AVAILABLE_RULES[rule_name.to_sym][:target_url]
179 return nil if target_url.blank? || point.action.blank? 179 return nil if target_url.blank? || point.action.blank?
180 180
181 - model = BaseTargetFinder.new(Merit::Rule.new, point.action).get_target_from_database 181 + model = BaseTargetFinder.new(Merit::Rule.new, point.action).get_target_from_database rescue nil
182 model.present? ? target_url.call(model) : nil 182 model.present? ? target_url.call(model) : nil
183 end 183 end
184 184
test/unit/point_rules_test.rb
@@ -36,4 +36,13 @@ class PointRulesTest < ActiveSupport::TestCase @@ -36,4 +36,13 @@ class PointRulesTest < ActiveSupport::TestCase
36 assert_equal comment.url, url 36 assert_equal comment.url, url
37 end 37 end
38 38
  39 + should 'do not fail when return target url for a point without a related model' do
  40 + person = create_user('testuser').person
  41 + create_point_rule_definition('article_author')
  42 + article = create(TextArticle, :profile_id => person.id, :author => person)
  43 + point = person.score_points.last
  44 + point.action.stubs(:target_model).returns('Hash')
  45 + Merit::PointRules.target_url(point)
  46 + end
  47 +
39 end 48 end