Commit 6b84f0107c7dac0e821970d55930ce5e4a7a22f9

Authored by Victor Costa
1 parent a3529df7

Restrict merit rules to text article

lib/ext/article.rb
@@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
1 -require_dependency 'article'  
2 -  
3 -class Article  
4 -  
5 - has_merit  
6 - has_merit_actions  
7 -  
8 -end  
lib/ext/text_article.rb 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +require_dependency 'text_article'
  2 +
  3 +class TextArticle
  4 +
  5 + has_merit
  6 + has_merit_actions
  7 +
  8 +end
script/process_merit_rules.rb
@@ -7,14 +7,14 @@ def create_action(obj, index, count) @@ -7,14 +7,14 @@ def create_action(obj, index, count)
7 end 7 end
8 end 8 end
9 9
10 -puts "Destroy all merit actions"  
11 -Merit::Action.destroy_all 10 +#puts "Destroy all merit actions"
  11 +#Merit::Action.destroy_all
12 12
13 -count = Person.count  
14 -Person.all.each.with_index(1) do |person, i|  
15 - puts "#{i}/#{count} Remove sash from #{person.identifier}"  
16 - person.sash.destroy unless person.sash.nil?  
17 -end 13 +#count = Person.count
  14 +#Person.all.each.with_index(1) do |person, i|
  15 +# puts "#{i}/#{count} Remove sash from #{person.identifier}"
  16 +# person.sash.destroy unless person.sash.nil?
  17 +#end
18 18
19 Environment.all.each do |environment| 19 Environment.all.each do |environment|
20 20
@@ -23,9 +23,9 @@ Environment.all.each do |environment| @@ -23,9 +23,9 @@ Environment.all.each do |environment|
23 Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules) 23 Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules)
24 Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules) 24 Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules)
25 25
26 - article_count = environment.articles.count 26 + article_count = environment.articles.text_articles.count
27 article_index = 0 27 article_index = 0
28 - environment.articles.find_each do |article| 28 + environment.articles.text_articles.find_each do |article|
29 article_index += 1 29 article_index += 1
30 create_action(article, article_index, article_count) 30 create_action(article, article_index, article_count)
31 31
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