Commit 2e1af6c93a27dbfd5c7f40e5f5d1acbe8ad5439a

Authored by Victor Costa
1 parent c12f8abd

Add action reference to point

db/migrate/20150812133432_add_action_to_points.rb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +class AddActionToPoints < ActiveRecord::Migration
  2 + def change
  3 + change_table :merit_score_points do |t|
  4 + t.references :action
  5 + end
  6 + end
  7 +end
... ...
lib/gamification_plugin.rb
... ... @@ -58,6 +58,7 @@ class GamificationPlugin &lt; Noosfero::Plugin
58 58 config.checks_on_each_request = false
59 59 config.user_model_name = 'Profile'
60 60 config.current_user_method = 'current_person'
  61 + config.add_observer 'Merit::PointTrackObserver'
61 62 config.add_observer 'Merit::RankObserver'
62 63 end
63 64  
... ...
lib/merit/point_track_observer.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +module Merit
  2 +
  3 + class PointTrackObserver
  4 + def update(changed_data)
  5 + merit = changed_data[:merit_object]
  6 + if merit.kind_of?(Merit::Score::Point)
  7 + merit.update_attribute(:action_id, changed_data[:merit_action_id])
  8 + end
  9 + end
  10 + end
  11 +
  12 +end
... ...
lib/merit_ext.rb
... ... @@ -14,6 +14,12 @@ module Merit
14 14  
15 15 end
16 16  
  17 + class Score
  18 + class Point
  19 + belongs_to :action
  20 + end
  21 + end
  22 +
17 23 class TargetFinder
18 24 # Accept proc in rule.to
19 25 def other_target
... ...
test/unit/article_test.rb
... ... @@ -13,6 +13,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
13 13 should 'add merit points to author when create a new article' do
14 14 create(TextArticle, :profile_id => person.id, :author => person)
15 15 assert_equal 1, person.score_points.count
  16 + assert person.score_points.first.action.present?
16 17 end
17 18  
18 19 should 'subtract merit points to author when destroy an article' do
... ...