diff --git a/db/migrate/20150812133432_add_action_to_points.rb b/db/migrate/20150812133432_add_action_to_points.rb new file mode 100644 index 0000000..d34737b --- /dev/null +++ b/db/migrate/20150812133432_add_action_to_points.rb @@ -0,0 +1,7 @@ +class AddActionToPoints < ActiveRecord::Migration + def change + change_table :merit_score_points do |t| + t.references :action + end + end +end diff --git a/lib/gamification_plugin.rb b/lib/gamification_plugin.rb index f52a4d5..c0361f4 100644 --- a/lib/gamification_plugin.rb +++ b/lib/gamification_plugin.rb @@ -58,6 +58,7 @@ class GamificationPlugin < Noosfero::Plugin config.checks_on_each_request = false config.user_model_name = 'Profile' config.current_user_method = 'current_person' + config.add_observer 'Merit::PointTrackObserver' config.add_observer 'Merit::RankObserver' end diff --git a/lib/merit/point_track_observer.rb b/lib/merit/point_track_observer.rb new file mode 100644 index 0000000..1acb8da --- /dev/null +++ b/lib/merit/point_track_observer.rb @@ -0,0 +1,12 @@ +module Merit + + class PointTrackObserver + def update(changed_data) + merit = changed_data[:merit_object] + if merit.kind_of?(Merit::Score::Point) + merit.update_attribute(:action_id, changed_data[:merit_action_id]) + end + end + end + +end diff --git a/lib/merit_ext.rb b/lib/merit_ext.rb index 76e499f..4aceeed 100644 --- a/lib/merit_ext.rb +++ b/lib/merit_ext.rb @@ -14,6 +14,12 @@ module Merit end + class Score + class Point + belongs_to :action + end + end + class TargetFinder # Accept proc in rule.to def other_target diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index a33c587..bb43614 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -13,6 +13,7 @@ class ArticleTest < ActiveSupport::TestCase should 'add merit points to author when create a new article' do create(TextArticle, :profile_id => person.id, :author => person) assert_equal 1, person.score_points.count + assert person.score_points.first.action.present? end should 'subtract merit points to author when destroy an article' do -- libgit2 0.21.2