diff --git a/lib/gamification_plugin.rb b/lib/gamification_plugin.rb index 874b13c..088a3c2 100644 --- a/lib/gamification_plugin.rb +++ b/lib/gamification_plugin.rb @@ -24,6 +24,12 @@ class GamificationPlugin < Noosfero::Plugin Merit::AppBadgeRules.clear Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules) Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules) + #FIXME We have to make a refactor of this code to avoid database data dependendy + Merit::PointRules::AVAILABLE_RULES.map do |rule_name, rule| + point_type = GamificationPlugin::PointsType.find_by_name rule_name + point_type = GamificationPlugin::PointsType.create name: rule_name, description: rule['description'] if point_type.nil? + GamificationPlugin::PointsCategorization.create point_type_id: point_type.id, weight: rule[:default_weight] + end end def application_controller_filters diff --git a/lib/merit/point_rules.rb b/lib/merit/point_rules.rb index 39359ec..9280d59 100644 --- a/lib/merit/point_rules.rb +++ b/lib/merit/point_rules.rb @@ -127,37 +127,7 @@ module Merit model: 'ArticleFollower', condition: lambda {|follow, profile| profile.nil? or follow.article.profile == profile }, profile_action: true - }, - #mobilizer: { - #action: 'mobilize#create', - #undo_action: 'mobilize#destroy', - #to: lambda {|target| target.source.author }, - #value: 1, - #description: _('Mobilized Article Author'), - #default_weight: 60, - #condition: lambda {|target, profile| profile.nil? or target.source.profile == profile }, - #profile_action: true - #}, - #mobilized_article_author: { - #action: 'mobilize#create', - #undo_action: 'mobilize#destroy', - #to: lambda {|target| target.source.author }, - #value: 1, - #description: _('Mobilized Article Author'), - #default_weight: 70, - #condition: lambda {|follow, profile| profile.nil? or follow.source.profile == profile }, - #profile_action: true - #}, - #mobilized_article: { - #action: 'mobilize#create', - #undo_action: 'mobilize#destroy', - #to: lambda {|target| target.source }, - #value: 1, - #description: _('Mobilized Article Author'), - #default_weight: 70, - #condition: lambda {|follow, profile| profile.nil? or follow.source.profile == profile }, - #profile_action: true - #} + } } def calculate_score(target, weight, value) diff --git a/test/test_helper.rb b/test/test_helper.rb index bee7a12..a1d68f8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,7 +4,7 @@ def create_point_rule_definition(rule_name, profile = nil, config = {}) rule = load_point_rule(rule_name, config) point_type = GamificationPlugin::PointsType.find_by_name rule_name point_type = GamificationPlugin::PointsType.create name: rule_name, description: rule['description'] if point_type.nil? - GamificationPlugin::PointsCategorization.create! point_type_id: point_type.id, profile: profile, weight: rule[:default_weight] + GamificationPlugin::PointsCategorization.create point_type_id: point_type.id, profile: profile, weight: rule[:default_weight] GamificationPlugin.gamification_set_rules(@environment) end @@ -32,3 +32,4 @@ def person_points_debug(person) puts GamificationPlugin::PointsCategorization.find(sp.score.category).point_type.inspect end end + diff --git a/test/unit/article_follower.rb b/test/unit/article_follower.rb index bfeecdb..e9518e9 100644 --- a/test/unit/article_follower.rb +++ b/test/unit/article_follower.rb @@ -37,15 +37,20 @@ class ArticleTest < ActiveSupport::TestCase create_point_rule_definition('followed_article_author') author = create_user('someuser').person article = create(TextArticle, :profile_id => community.id, :author => author) - amount = author.score_points.count + + author_amount = author.score_points.count + person_amount = person.score_points.count article.person_followers << person - assert_equal amount + 1, author.score_points.count + + assert_equal author_amount + 1, author.score_points.count last_point = author.score_points.last assert_equal article.article_followers.last.id, last_point.action.target_id - assert_equal amount + 1, person.score_points.count + + assert_equal person_amount + 1, person.score_points.count last_point = person.score_points.last assert_equal article.article_followers.last.id, last_point.action.target_id end + # should 'subtract merit points to author when destroy an article' do # article = create(TextArticle, :profile_id => @community.id, :author => person) # assert_equal 1, person.score_points.count diff --git a/test/unit/point_rules_test.rb b/test/unit/point_rules_test.rb index c2597e6..ed302db 100644 --- a/test/unit/point_rules_test.rb +++ b/test/unit/point_rules_test.rb @@ -4,6 +4,7 @@ class PointRulesTest < ActiveSupport::TestCase def setup @environment = Environment.default + GamificationPlugin.gamification_set_rules(@environment) @point_rules = Merit::PointRules.new(@environment) end -- libgit2 0.21.2