Commit d9a171ceb019f053c13bd40650d8f526909ddc03
Exists in
master
and in
1 other branch
Merge commit '2f6dced'
Showing
6 changed files
with
35 additions
and
30 deletions
Show diff stats
lib/ext/article.rb
lib/gamification_plugin.rb
@@ -35,7 +35,7 @@ class GamificationPlugin < Noosfero::Plugin | @@ -35,7 +35,7 @@ class GamificationPlugin < Noosfero::Plugin | ||
35 | 35 | ||
36 | def body_ending | 36 | def body_ending |
37 | proc do | 37 | proc do |
38 | - if current_person.present? | 38 | + if current_person.present? && response.status == 200 |
39 | badges = current_person.badges.notification_pending.all | 39 | badges = current_person.badges.notification_pending.all |
40 | current_person.sash.notify_all_badges_from_user | 40 | current_person.sash.notify_all_badges_from_user |
41 | render :file => 'gamification/display_notifications', :locals => {:badges => badges} | 41 | render :file => 'gamification/display_notifications', :locals => {:badges => badges} |
script/process_merit_rules.rb
@@ -10,14 +10,14 @@ def create_action(obj, index, count) | @@ -10,14 +10,14 @@ def create_action(obj, index, count) | ||
10 | end | 10 | end |
11 | end | 11 | end |
12 | 12 | ||
13 | -puts "Destroy all merit actions" | ||
14 | -Merit::Action.destroy_all | 13 | +#puts "Destroy all merit actions" |
14 | +#Merit::Action.destroy_all | ||
15 | 15 | ||
16 | -count = Person.count | ||
17 | -Person.all.each.with_index(1) do |person, i| | ||
18 | - puts "#{i}/#{count} Remove sash from #{person.identifier}" | ||
19 | - person.sash.destroy unless person.sash.nil? | ||
20 | -end | 16 | +#count = Person.count |
17 | +#Person.all.each.with_index(1) do |person, i| | ||
18 | +# puts "#{i}/#{count} Remove sash from #{person.identifier}" | ||
19 | +# person.sash.destroy unless person.sash.nil? | ||
20 | +#end | ||
21 | 21 | ||
22 | Environment.all.each do |environment| | 22 | Environment.all.each do |environment| |
23 | 23 | ||
@@ -26,9 +26,9 @@ Environment.all.each do |environment| | @@ -26,9 +26,9 @@ Environment.all.each do |environment| | ||
26 | Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules) | 26 | Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules) |
27 | Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules) | 27 | Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules) |
28 | 28 | ||
29 | - article_count = environment.articles.count | 29 | + article_count = environment.articles.text_articles.count |
30 | article_index = 0 | 30 | article_index = 0 |
31 | - environment.articles.find_each do |article| | 31 | + environment.articles.text_articles.find_each do |article| |
32 | article_index += 1 | 32 | article_index += 1 |
33 | create_action(article, article_index, article_count) | 33 | create_action(article, article_index, article_count) |
34 | 34 | ||
@@ -45,4 +45,9 @@ Environment.all.each do |environment| | @@ -45,4 +45,9 @@ Environment.all.each do |environment| | ||
45 | end | 45 | end |
46 | end | 46 | end |
47 | 47 | ||
48 | + environment.people.each.with_index(1) do |person, person_index| | ||
49 | + puts "Updating #{person.identifier} level" | ||
50 | + person.update_attribute(:level, person.gamification_plugin_calculate_level) | ||
51 | + end | ||
52 | + | ||
48 | end | 53 | end |
test/unit/article_test.rb
@@ -11,12 +11,12 @@ class ArticleTest < ActiveSupport::TestCase | @@ -11,12 +11,12 @@ class ArticleTest < ActiveSupport::TestCase | ||
11 | attr_accessor :person, :environment | 11 | attr_accessor :person, :environment |
12 | 12 | ||
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(Article, :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 | end | 16 | end |
17 | 17 | ||
18 | should 'subtract merit points to author when destroy an article' do | 18 | should 'subtract merit points to author when destroy an article' do |
19 | - article = create(Article, :profile_id => person.id, :author => person) | 19 | + article = create(TextArticle, :profile_id => person.id, :author => person) |
20 | assert_equal 1, person.score_points.count | 20 | assert_equal 1, person.score_points.count |
21 | article.destroy | 21 | article.destroy |
22 | assert_equal 2, person.score_points.count | 22 | assert_equal 2, person.score_points.count |
@@ -27,7 +27,7 @@ class ArticleTest < ActiveSupport::TestCase | @@ -27,7 +27,7 @@ class ArticleTest < ActiveSupport::TestCase | ||
27 | GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 1) | 27 | GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 1) |
28 | GamificationPlugin.gamification_set_rules(environment) | 28 | GamificationPlugin.gamification_set_rules(environment) |
29 | 29 | ||
30 | - 5.times { create(Article, :profile_id => person.id, :author => person) } | 30 | + 5.times { create(TextArticle, :profile_id => person.id, :author => person) } |
31 | assert_equal 'article_author', person.badges.first.name | 31 | assert_equal 'article_author', person.badges.first.name |
32 | assert_equal 1, person.badges.first.level | 32 | assert_equal 1, person.badges.first.level |
33 | end | 33 | end |
@@ -37,13 +37,13 @@ class ArticleTest < ActiveSupport::TestCase | @@ -37,13 +37,13 @@ class ArticleTest < ActiveSupport::TestCase | ||
37 | GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 2, :custom_fields => {:threshold => 10}) | 37 | GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 2, :custom_fields => {:threshold => 10}) |
38 | GamificationPlugin.gamification_set_rules(environment) | 38 | GamificationPlugin.gamification_set_rules(environment) |
39 | 39 | ||
40 | - 10.times { create(Article, :profile_id => person.id, :author => person) } | 40 | + 10.times { create(TextArticle, :profile_id => person.id, :author => person) } |
41 | assert_equal ['article_author'], person.badges.map(&:name).uniq | 41 | assert_equal ['article_author'], person.badges.map(&:name).uniq |
42 | assert_equal [1, 2], person.badges.map(&:level) | 42 | assert_equal [1, 2], person.badges.map(&:level) |
43 | end | 43 | end |
44 | 44 | ||
45 | should 'add merit points to article owner when an user like it' do | 45 | should 'add merit points to article owner when an user like it' do |
46 | - article = create(Article, :name => 'Test', :profile => person, :author => person) | 46 | + article = create(TextArticle, :name => 'Test', :profile => person, :author => person) |
47 | 47 | ||
48 | assert_difference 'article.author.points(:category => :vote_voteable_author)', 50 do | 48 | assert_difference 'article.author.points(:category => :vote_voteable_author)', 50 do |
49 | Vote.create!(:voter => person, :voteable => article, :vote => 1) | 49 | Vote.create!(:voter => person, :voteable => article, :vote => 1) |
@@ -51,7 +51,7 @@ class ArticleTest < ActiveSupport::TestCase | @@ -51,7 +51,7 @@ class ArticleTest < ActiveSupport::TestCase | ||
51 | end | 51 | end |
52 | 52 | ||
53 | should 'add merit points to article when an user like it' do | 53 | should 'add merit points to article when an user like it' do |
54 | - article = create(Article, :name => 'Test', :profile => person, :author => person) | 54 | + article = create(TextArticle, :name => 'Test', :profile => person, :author => person) |
55 | article = article.reload | 55 | article = article.reload |
56 | 56 | ||
57 | assert_difference 'article.points(:category => :vote_voteable)', 50 do | 57 | assert_difference 'article.points(:category => :vote_voteable)', 50 do |
@@ -62,12 +62,12 @@ class ArticleTest < ActiveSupport::TestCase | @@ -62,12 +62,12 @@ class ArticleTest < ActiveSupport::TestCase | ||
62 | should 'add merit points to community when create a new article' do | 62 | should 'add merit points to community when create a new article' do |
63 | community = fast_create(Community) | 63 | community = fast_create(Community) |
64 | assert_difference 'community.score_points.count' do | 64 | assert_difference 'community.score_points.count' do |
65 | - create(Article, :profile_id => community.id, :author => person) | 65 | + create(TextArticle, :profile_id => community.id, :author => person) |
66 | end | 66 | end |
67 | end | 67 | end |
68 | 68 | ||
69 | should 'add merit points to voter when he likes an article' do | 69 | should 'add merit points to voter when he likes an article' do |
70 | - article = create(Article, :name => 'Test', :profile => person, :author => person) | 70 | + article = create(TextArticle, :name => 'Test', :profile => person, :author => person) |
71 | 71 | ||
72 | assert_difference 'article.author.points(:category => :vote_voter)', 10 do | 72 | assert_difference 'article.author.points(:category => :vote_voter)', 10 do |
73 | Vote.create!(:voter => person, :voteable => article, :vote => 1) | 73 | Vote.create!(:voter => person, :voteable => article, :vote => 1) |
@@ -75,7 +75,7 @@ class ArticleTest < ActiveSupport::TestCase | @@ -75,7 +75,7 @@ class ArticleTest < ActiveSupport::TestCase | ||
75 | end | 75 | end |
76 | 76 | ||
77 | should 'add merit points to voter when he dislikes an article' do | 77 | should 'add merit points to voter when he dislikes an article' do |
78 | - article = create(Article, :name => 'Test', :profile => person, :author => person) | 78 | + article = create(TextArticle, :name => 'Test', :profile => person, :author => person) |
79 | 79 | ||
80 | assert_difference 'article.author.points(:category => :vote_voter)', 10 do | 80 | assert_difference 'article.author.points(:category => :vote_voter)', 10 do |
81 | Vote.create!(:voter => person, :voteable => article, :vote => -1) | 81 | Vote.create!(:voter => person, :voteable => article, :vote => -1) |
@@ -86,7 +86,7 @@ class ArticleTest < ActiveSupport::TestCase | @@ -86,7 +86,7 @@ class ArticleTest < ActiveSupport::TestCase | ||
86 | GamificationPlugin::Badge.create!(:owner => environment, :name => 'positive_votes_received') | 86 | GamificationPlugin::Badge.create!(:owner => environment, :name => 'positive_votes_received') |
87 | GamificationPlugin.gamification_set_rules(environment) | 87 | GamificationPlugin.gamification_set_rules(environment) |
88 | 88 | ||
89 | - article = create(Article, :name => 'Test', :profile => person, :author => person) | 89 | + article = create(TextArticle, :name => 'Test', :profile => person, :author => person) |
90 | 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) } | 90 | 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) } |
91 | Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) | 91 | Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) |
92 | assert_equal [], person.badges | 92 | assert_equal [], person.badges |
@@ -98,7 +98,7 @@ class ArticleTest < ActiveSupport::TestCase | @@ -98,7 +98,7 @@ class ArticleTest < ActiveSupport::TestCase | ||
98 | GamificationPlugin::Badge.create!(:owner => environment, :name => 'negative_votes_received') | 98 | GamificationPlugin::Badge.create!(:owner => environment, :name => 'negative_votes_received') |
99 | GamificationPlugin.gamification_set_rules(environment) | 99 | GamificationPlugin.gamification_set_rules(environment) |
100 | 100 | ||
101 | - article = create(Article, :name => 'Test', :profile => person, :author => person) | 101 | + article = create(TextArticle, :name => 'Test', :profile => person, :author => person) |
102 | 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) } | 102 | 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) } |
103 | Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) | 103 | Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) |
104 | assert_equal [], person.badges | 104 | assert_equal [], person.badges |
test/unit/profile_test.rb
@@ -35,7 +35,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -35,7 +35,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
35 | GamificationPlugin.gamification_set_rules(environment) | 35 | GamificationPlugin.gamification_set_rules(environment) |
36 | person = create_user('testuser').person | 36 | person = create_user('testuser').person |
37 | assert_equal 0, person.level | 37 | assert_equal 0, person.level |
38 | - create(Article, :profile_id => profile.id, :author => person) | 38 | + create(TextArticle, :profile_id => profile.id, :author => person) |
39 | assert_equal 3, person.reload.level | 39 | assert_equal 3, person.reload.level |
40 | end | 40 | end |
41 | 41 |