Commit 7e8e2832a8f573c2d0fee4a70050bac982f6f4de
1 parent
6d48b429
Exists in
master
and in
1 other branch
adding article folloer test
Showing
1 changed file
with
117 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,117 @@ |
1 | +require_relative "../test_helper" | |
2 | + | |
3 | +class ArticleTest < ActiveSupport::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @person = create_user('testuser').person | |
7 | + @environment = Environment.default | |
8 | + @community = create_merit_categorization | |
9 | + GamificationPlugin.gamification_set_rules(@environment) | |
10 | + end | |
11 | + | |
12 | + attr_accessor :person, :environment, :community | |
13 | + | |
14 | + should 'add merit points to follower when it follows an article' do | |
15 | + article = create(TextArticle, :profile_id => community.id, :author => person) | |
16 | + amount = person.score_points.count | |
17 | + article.person_followers << person | |
18 | +puts person.score_points.first.action.inspect | |
19 | + assert_equal amount + 1, person.score_points.count | |
20 | + assert person.score_points.first.action.present? | |
21 | + end | |
22 | + | |
23 | +# should 'subtract merit points to author when destroy an article' do | |
24 | +# article = create(TextArticle, :profile_id => @community.id, :author => person) | |
25 | +# assert_equal 1, person.score_points.count | |
26 | +# article.destroy | |
27 | +# assert_equal 2, person.score_points.count | |
28 | +# assert_equal 0, person.points | |
29 | +# end | |
30 | +# | |
31 | +# should 'add merit badge to author when create 5 new articles' do | |
32 | +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 1) | |
33 | +# GamificationPlugin.gamification_set_rules(environment) | |
34 | +# | |
35 | +# 5.times { create(TextArticle, :profile_id => person.id, :author => person) } | |
36 | +# assert_equal 'article_author', person.badges.first.name | |
37 | +# assert_equal 1, person.badges.first.level | |
38 | +# end | |
39 | +# | |
40 | +# should 'add merit badge level 2 to author when create 10 new articles' do | |
41 | +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 1) | |
42 | +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 2, :custom_fields => {:threshold => 10}) | |
43 | +# GamificationPlugin.gamification_set_rules(environment) | |
44 | +# | |
45 | +# 10.times { create(TextArticle, :profile_id => person.id, :author => person) } | |
46 | +# assert_equal ['article_author'], person.badges.map(&:name).uniq | |
47 | +# assert_equal [1, 2], person.badges.map(&:level) | |
48 | +# end | |
49 | +# | |
50 | +# should 'add merit points to community article owner when an user like it' do | |
51 | +# article = create(TextArticle, :name => 'Test', :profile => @community, :author => person) | |
52 | +# | |
53 | +# c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: @community.id).first | |
54 | +# assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do | |
55 | +# Vote.create!(:voter => person, :voteable => article, :vote => 1) | |
56 | +# end | |
57 | +# end | |
58 | +# | |
59 | +# should 'add merit points to article when an user like it' do | |
60 | +# article = create(TextArticle, :name => 'Test', :profile => @community, :author => person) | |
61 | +# article = article.reload | |
62 | +# | |
63 | +# c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable).where(profile_id: @community.id).first | |
64 | +# assert_difference 'article.points(:category => c.id.to_s)', c.weight do | |
65 | +# Vote.create!(:voter => person, :voteable => article, :vote => 1) | |
66 | +# end | |
67 | +# end | |
68 | +# | |
69 | +# should 'add merit points to community when create a new article' do | |
70 | +# assert_difference 'community.score_points.count' do | |
71 | +# create(TextArticle, :profile_id => @community.id, :author => person) | |
72 | +# end | |
73 | +# end | |
74 | +# | |
75 | +# should 'add merit points to voter when he likes an article' do | |
76 | +# article = create(TextArticle, :name => 'Test', :profile => @community, :author => person) | |
77 | +# | |
78 | +# c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).where(profile_id: @community.id).first | |
79 | +# assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do | |
80 | +# Vote.create!(:voter => person, :voteable => article, :vote => 1) | |
81 | +# end | |
82 | +# end | |
83 | +# | |
84 | +# should 'add merit points to voter when he dislikes an article' do | |
85 | +# article = create(TextArticle, :name => 'Test', :profile => @community, :author => person) | |
86 | +# | |
87 | +# c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).where(profile_id: @community.id).first | |
88 | +# assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do | |
89 | +# Vote.create!(:voter => person, :voteable => article, :vote => -1) | |
90 | +# end | |
91 | +# end | |
92 | +# | |
93 | +# should 'add badge to author when users like his article' do | |
94 | +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'positive_votes_received') | |
95 | +# GamificationPlugin.gamification_set_rules(environment) | |
96 | +# | |
97 | +# article = create(TextArticle, :name => 'Test', :profile => person, :author => person) | |
98 | +# 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) } | |
99 | +# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) | |
100 | +# assert_equal [], person.badges | |
101 | +# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) | |
102 | +# assert_equal 'positive_votes_received', person.reload.badges.first.name | |
103 | +# end | |
104 | +# | |
105 | +# should 'add badge to author when users dislike his article' do | |
106 | +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'negative_votes_received') | |
107 | +# GamificationPlugin.gamification_set_rules(environment) | |
108 | +# | |
109 | +# article = create(TextArticle, :name => 'Test', :profile => person, :author => person) | |
110 | +# 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) } | |
111 | +# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) | |
112 | +# assert_equal [], person.badges | |
113 | +# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) | |
114 | +# assert_equal 'negative_votes_received', person.reload.badges.first.name | |
115 | +# end | |
116 | +# | |
117 | +end | ... | ... |