Commit 2e1af6c93a27dbfd5c7f40e5f5d1acbe8ad5439a
1 parent
c12f8abd
Exists in
master
and in
1 other branch
Add action reference to point
Showing
5 changed files
with
27 additions
and
0 deletions
Show diff stats
lib/gamification_plugin.rb
@@ -58,6 +58,7 @@ class GamificationPlugin < Noosfero::Plugin | @@ -58,6 +58,7 @@ class GamificationPlugin < Noosfero::Plugin | ||
58 | config.checks_on_each_request = false | 58 | config.checks_on_each_request = false |
59 | config.user_model_name = 'Profile' | 59 | config.user_model_name = 'Profile' |
60 | config.current_user_method = 'current_person' | 60 | config.current_user_method = 'current_person' |
61 | + config.add_observer 'Merit::PointTrackObserver' | ||
61 | config.add_observer 'Merit::RankObserver' | 62 | config.add_observer 'Merit::RankObserver' |
62 | end | 63 | end |
63 | 64 |
@@ -0,0 +1,12 @@ | @@ -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,6 +14,12 @@ module Merit | ||
14 | 14 | ||
15 | end | 15 | end |
16 | 16 | ||
17 | + class Score | ||
18 | + class Point | ||
19 | + belongs_to :action | ||
20 | + end | ||
21 | + end | ||
22 | + | ||
17 | class TargetFinder | 23 | class TargetFinder |
18 | # Accept proc in rule.to | 24 | # Accept proc in rule.to |
19 | def other_target | 25 | def other_target |
test/unit/article_test.rb
@@ -13,6 +13,7 @@ class ArticleTest < ActiveSupport::TestCase | @@ -13,6 +13,7 @@ class ArticleTest < ActiveSupport::TestCase | ||
13 | should 'add merit points to author when create a new article' do | 13 | should 'add merit points to author when create a new article' do |
14 | create(TextArticle, :profile_id => person.id, :author => person) | 14 | create(TextArticle, :profile_id => person.id, :author => person) |
15 | assert_equal 1, person.score_points.count | 15 | assert_equal 1, person.score_points.count |
16 | + assert person.score_points.first.action.present? | ||
16 | end | 17 | end |
17 | 18 | ||
18 | should 'subtract merit points to author when destroy an article' do | 19 | should 'subtract merit points to author when destroy an article' do |