Commit 9ef8392231f6896f53605504b36a0843e600a436
1 parent
1d415104
Exists in
master
and in
1 other branch
load the point rules correctly
Showing
5 changed files
with
18 additions
and
35 deletions
Show diff stats
lib/gamification_plugin.rb
@@ -24,6 +24,12 @@ class GamificationPlugin < Noosfero::Plugin | @@ -24,6 +24,12 @@ class GamificationPlugin < Noosfero::Plugin | ||
24 | Merit::AppBadgeRules.clear | 24 | Merit::AppBadgeRules.clear |
25 | Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules) | 25 | Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules) |
26 | Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules) | 26 | Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules) |
27 | + #FIXME We have to make a refactor of this code to avoid database data dependendy | ||
28 | + Merit::PointRules::AVAILABLE_RULES.map do |rule_name, rule| | ||
29 | + point_type = GamificationPlugin::PointsType.find_by_name rule_name | ||
30 | + point_type = GamificationPlugin::PointsType.create name: rule_name, description: rule['description'] if point_type.nil? | ||
31 | + GamificationPlugin::PointsCategorization.create point_type_id: point_type.id, weight: rule[:default_weight] | ||
32 | + end | ||
27 | end | 33 | end |
28 | 34 | ||
29 | def application_controller_filters | 35 | def application_controller_filters |
lib/merit/point_rules.rb
@@ -127,37 +127,7 @@ module Merit | @@ -127,37 +127,7 @@ module Merit | ||
127 | model: 'ArticleFollower', | 127 | model: 'ArticleFollower', |
128 | condition: lambda {|follow, profile| profile.nil? or follow.article.profile == profile }, | 128 | condition: lambda {|follow, profile| profile.nil? or follow.article.profile == profile }, |
129 | profile_action: true | 129 | profile_action: true |
130 | - }, | ||
131 | - #mobilizer: { | ||
132 | - #action: 'mobilize#create', | ||
133 | - #undo_action: 'mobilize#destroy', | ||
134 | - #to: lambda {|target| target.source.author }, | ||
135 | - #value: 1, | ||
136 | - #description: _('Mobilized Article Author'), | ||
137 | - #default_weight: 60, | ||
138 | - #condition: lambda {|target, profile| profile.nil? or target.source.profile == profile }, | ||
139 | - #profile_action: true | ||
140 | - #}, | ||
141 | - #mobilized_article_author: { | ||
142 | - #action: 'mobilize#create', | ||
143 | - #undo_action: 'mobilize#destroy', | ||
144 | - #to: lambda {|target| target.source.author }, | ||
145 | - #value: 1, | ||
146 | - #description: _('Mobilized Article Author'), | ||
147 | - #default_weight: 70, | ||
148 | - #condition: lambda {|follow, profile| profile.nil? or follow.source.profile == profile }, | ||
149 | - #profile_action: true | ||
150 | - #}, | ||
151 | - #mobilized_article: { | ||
152 | - #action: 'mobilize#create', | ||
153 | - #undo_action: 'mobilize#destroy', | ||
154 | - #to: lambda {|target| target.source }, | ||
155 | - #value: 1, | ||
156 | - #description: _('Mobilized Article Author'), | ||
157 | - #default_weight: 70, | ||
158 | - #condition: lambda {|follow, profile| profile.nil? or follow.source.profile == profile }, | ||
159 | - #profile_action: true | ||
160 | - #} | 130 | + } |
161 | } | 131 | } |
162 | 132 | ||
163 | def calculate_score(target, weight, value) | 133 | def calculate_score(target, weight, value) |
test/test_helper.rb
@@ -4,7 +4,7 @@ def create_point_rule_definition(rule_name, profile = nil, config = {}) | @@ -4,7 +4,7 @@ def create_point_rule_definition(rule_name, profile = nil, config = {}) | ||
4 | rule = load_point_rule(rule_name, config) | 4 | rule = load_point_rule(rule_name, config) |
5 | point_type = GamificationPlugin::PointsType.find_by_name rule_name | 5 | point_type = GamificationPlugin::PointsType.find_by_name rule_name |
6 | point_type = GamificationPlugin::PointsType.create name: rule_name, description: rule['description'] if point_type.nil? | 6 | point_type = GamificationPlugin::PointsType.create name: rule_name, description: rule['description'] if point_type.nil? |
7 | - GamificationPlugin::PointsCategorization.create! point_type_id: point_type.id, profile: profile, weight: rule[:default_weight] | 7 | + GamificationPlugin::PointsCategorization.create point_type_id: point_type.id, profile: profile, weight: rule[:default_weight] |
8 | GamificationPlugin.gamification_set_rules(@environment) | 8 | GamificationPlugin.gamification_set_rules(@environment) |
9 | end | 9 | end |
10 | 10 | ||
@@ -32,3 +32,4 @@ def person_points_debug(person) | @@ -32,3 +32,4 @@ def person_points_debug(person) | ||
32 | puts GamificationPlugin::PointsCategorization.find(sp.score.category).point_type.inspect | 32 | puts GamificationPlugin::PointsCategorization.find(sp.score.category).point_type.inspect |
33 | end | 33 | end |
34 | end | 34 | end |
35 | + |
test/unit/article_follower.rb
@@ -37,15 +37,20 @@ class ArticleTest < ActiveSupport::TestCase | @@ -37,15 +37,20 @@ class ArticleTest < ActiveSupport::TestCase | ||
37 | create_point_rule_definition('followed_article_author') | 37 | create_point_rule_definition('followed_article_author') |
38 | author = create_user('someuser').person | 38 | author = create_user('someuser').person |
39 | article = create(TextArticle, :profile_id => community.id, :author => author) | 39 | article = create(TextArticle, :profile_id => community.id, :author => author) |
40 | - amount = author.score_points.count | 40 | + |
41 | + author_amount = author.score_points.count | ||
42 | + person_amount = person.score_points.count | ||
41 | article.person_followers << person | 43 | article.person_followers << person |
42 | - assert_equal amount + 1, author.score_points.count | 44 | + |
45 | + assert_equal author_amount + 1, author.score_points.count | ||
43 | last_point = author.score_points.last | 46 | last_point = author.score_points.last |
44 | assert_equal article.article_followers.last.id, last_point.action.target_id | 47 | assert_equal article.article_followers.last.id, last_point.action.target_id |
45 | - assert_equal amount + 1, person.score_points.count | 48 | + |
49 | + assert_equal person_amount + 1, person.score_points.count | ||
46 | last_point = person.score_points.last | 50 | last_point = person.score_points.last |
47 | assert_equal article.article_followers.last.id, last_point.action.target_id | 51 | assert_equal article.article_followers.last.id, last_point.action.target_id |
48 | end | 52 | end |
53 | + | ||
49 | # should 'subtract merit points to author when destroy an article' do | 54 | # should 'subtract merit points to author when destroy an article' do |
50 | # article = create(TextArticle, :profile_id => @community.id, :author => person) | 55 | # article = create(TextArticle, :profile_id => @community.id, :author => person) |
51 | # assert_equal 1, person.score_points.count | 56 | # assert_equal 1, person.score_points.count |
test/unit/point_rules_test.rb
@@ -4,6 +4,7 @@ class PointRulesTest < ActiveSupport::TestCase | @@ -4,6 +4,7 @@ class PointRulesTest < ActiveSupport::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @environment = Environment.default | 6 | @environment = Environment.default |
7 | + GamificationPlugin.gamification_set_rules(@environment) | ||
7 | @point_rules = Merit::PointRules.new(@environment) | 8 | @point_rules = Merit::PointRules.new(@environment) |
8 | end | 9 | end |
9 | 10 |