Commit 51c916624b7dd6151d090db564919f6f23de4097

Authored by Hugo Melo
1 parent 84c24a16

Fix article follower test file name

test/unit/article_follower.rb
... ... @@ -1,126 +0,0 @@
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 = fast_create(Community)
9   - end
10   -
11   - attr_accessor :person, :environment, :community
12   -
13   - should 'add merit points to an article follower by user' do
14   - create_point_rule_definition('followed_article')
15   - article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
16   -
17   - c = GamificationPlugin::PointsCategorization.for_type(:followed_article).first
18   - assert_difference 'article.points(:category => c.id.to_s)', c.weight do
19   - article.person_followers << person
20   - end
21   - end
22   -
23   - should 'add merit points to follower when it follows an article' do
24   - create_point_rule_definition('follower')
25   -
26   - article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
27   -
28   - c = GamificationPlugin::PointsCategorization.for_type(:follower).first
29   - assert_difference 'person.points(:category => c.id.to_s)', c.weight do
30   - article.person_followers << person
31   - end
32   - end
33   -
34   - should "add merit points for article's author followed by an user" do
35   - create_point_rule_definition('followed_article_author')
36   -
37   - article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
38   -
39   - c = GamificationPlugin::PointsCategorization.for_type(:followed_article_author).first
40   - assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
41   - article.person_followers << person
42   - end
43   - end
44   -
45   - should 'subtract merit points to follower when it unfollow an article' do
46   - create_point_rule_definition('follower')
47   - follower = create_user('someuser').person
48   - article = create(TextArticle, :profile_id => community.id, :author => person)
49   - score_points = follower.score_points.count
50   - points = follower.points
51   - article.person_followers << follower
52   - assert_equal score_points + 1, follower.score_points.count
53   - ArticleFollower.last.destroy
54   - assert_equal score_points + 2, follower.score_points.count
55   - assert_equal points, follower.points
56   - end
57   -
58   - should 'subtract merit points to article author when a user unfollow an article' do
59   - create_point_rule_definition('follower')
60   - article = create(TextArticle, :profile_id => community.id, :author => person)
61   - score_points = person.score_points.count
62   - points = person.points
63   - article.person_followers << person
64   - assert_equal score_points + 1, person.score_points.count
65   - ArticleFollower.last.destroy
66   - assert_equal score_points + 2, person.score_points.count
67   - assert_equal points, person.points
68   - end
69   -
70   - should 'subtract merit points to article when a user unfollow an article' do
71   - create_point_rule_definition('followed_article')
72   - article = create(TextArticle, :profile_id => community.id, :author => person)
73   - score_points = article.score_points.count
74   - points = article.points
75   - article.person_followers << person
76   - assert_equal score_points + 1, article.score_points.count
77   - ArticleFollower.last.destroy
78   - assert_equal score_points + 2, article.score_points.count
79   - assert_equal points, article.points
80   - end
81   -
82   -#FIXME make tests for badges generete with article follower actions
83   -#
84   -# should 'add badge to author when users like his article' do
85   -# GamificationPlugin::Badge.create!(:owner => environment, :name => 'positive_votes_received')
86   -# GamificationPlugin.gamification_set_rules(environment)
87   -#
88   -# article = create(TextArticle, :name => 'Test', :profile => person, :author => person)
89   -# 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) }
90   -# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1)
91   -# assert_equal [], person.badges
92   -# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1)
93   -# assert_equal 'positive_votes_received', person.reload.badges.first.name
94   -# end
95   -#
96   -# should 'add badge to author when users dislike his article' do
97   -# GamificationPlugin::Badge.create!(:owner => environment, :name => 'negative_votes_received')
98   -# GamificationPlugin.gamification_set_rules(environment)
99   -#
100   -# article = create(TextArticle, :name => 'Test', :profile => person, :author => person)
101   -# 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) }
102   -# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1)
103   -# assert_equal [], person.badges
104   -# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1)
105   -# assert_equal 'negative_votes_received', person.reload.badges.first.name
106   -# end
107   -#
108   -# should 'add merit badge to author when create 5 new articles' do
109   -# GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 1)
110   -# GamificationPlugin.gamification_set_rules(environment)
111   -#
112   -# 5.times { create(TextArticle, :profile_id => person.id, :author => person) }
113   -# assert_equal 'article_author', person.badges.first.name
114   -# assert_equal 1, person.badges.first.level
115   -# end
116   -#
117   -# should 'add merit badge level 2 to author when create 10 new articles' do
118   -# GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 1)
119   -# GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 2, :custom_fields => {:threshold => 10})
120   -# GamificationPlugin.gamification_set_rules(environment)
121   -#
122   -# 10.times { create(TextArticle, :profile_id => person.id, :author => person) }
123   -# assert_equal ['article_author'], person.badges.map(&:name).uniq
124   -# assert_equal [1, 2], person.badges.map(&:level)
125   -# end
126   -end
test/unit/article_follower_test.rb 0 → 100644
... ... @@ -0,0 +1,126 @@
  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 = fast_create(Community)
  9 + end
  10 +
  11 + attr_accessor :person, :environment, :community
  12 +
  13 + should 'add merit points to an article follower by user' do
  14 + create_point_rule_definition('followed_article')
  15 + article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
  16 +
  17 + c = GamificationPlugin::PointsCategorization.for_type(:followed_article).first
  18 + assert_difference 'article.points(:category => c.id.to_s)', c.weight do
  19 + article.person_followers << person
  20 + end
  21 + end
  22 +
  23 + should 'add merit points to follower when it follows an article' do
  24 + create_point_rule_definition('follower')
  25 +
  26 + article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
  27 +
  28 + c = GamificationPlugin::PointsCategorization.for_type(:follower).first
  29 + assert_difference 'person.points(:category => c.id.to_s)', c.weight do
  30 + article.person_followers << person
  31 + end
  32 + end
  33 +
  34 + should "add merit points for article's author followed by an user" do
  35 + create_point_rule_definition('followed_article_author')
  36 +
  37 + article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
  38 +
  39 + c = GamificationPlugin::PointsCategorization.for_type(:followed_article_author).first
  40 + assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
  41 + article.person_followers << person
  42 + end
  43 + end
  44 +
  45 + should 'subtract merit points to follower when it unfollow an article' do
  46 + create_point_rule_definition('follower')
  47 + follower = create_user('someuser').person
  48 + article = create(TextArticle, :profile_id => community.id, :author => person)
  49 + score_points = follower.score_points.count
  50 + points = follower.points
  51 + article.person_followers << follower
  52 + assert_equal score_points + 1, follower.score_points.count
  53 + ArticleFollower.last.destroy
  54 + assert_equal score_points + 2, follower.score_points.count
  55 + assert_equal points, follower.points
  56 + end
  57 +
  58 + should 'subtract merit points to article author when a user unfollow an article' do
  59 + create_point_rule_definition('follower')
  60 + article = create(TextArticle, :profile_id => community.id, :author => person)
  61 + score_points = person.score_points.count
  62 + points = person.points
  63 + article.person_followers << person
  64 + assert_equal score_points + 1, person.score_points.count
  65 + ArticleFollower.last.destroy
  66 + assert_equal score_points + 2, person.score_points.count
  67 + assert_equal points, person.points
  68 + end
  69 +
  70 + should 'subtract merit points to article when a user unfollow an article' do
  71 + create_point_rule_definition('followed_article')
  72 + article = create(TextArticle, :profile_id => community.id, :author => person)
  73 + score_points = article.score_points.count
  74 + points = article.points
  75 + article.person_followers << person
  76 + assert_equal score_points + 1, article.score_points.count
  77 + ArticleFollower.last.destroy
  78 + assert_equal score_points + 2, article.score_points.count
  79 + assert_equal points, article.points
  80 + end
  81 +
  82 +#FIXME make tests for badges generete with article follower actions
  83 +#
  84 +# should 'add badge to author when users like his article' do
  85 +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'positive_votes_received')
  86 +# GamificationPlugin.gamification_set_rules(environment)
  87 +#
  88 +# article = create(TextArticle, :name => 'Test', :profile => person, :author => person)
  89 +# 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) }
  90 +# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1)
  91 +# assert_equal [], person.badges
  92 +# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1)
  93 +# assert_equal 'positive_votes_received', person.reload.badges.first.name
  94 +# end
  95 +#
  96 +# should 'add badge to author when users dislike his article' do
  97 +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'negative_votes_received')
  98 +# GamificationPlugin.gamification_set_rules(environment)
  99 +#
  100 +# article = create(TextArticle, :name => 'Test', :profile => person, :author => person)
  101 +# 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) }
  102 +# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1)
  103 +# assert_equal [], person.badges
  104 +# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1)
  105 +# assert_equal 'negative_votes_received', person.reload.badges.first.name
  106 +# end
  107 +#
  108 +# should 'add merit badge to author when create 5 new articles' do
  109 +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 1)
  110 +# GamificationPlugin.gamification_set_rules(environment)
  111 +#
  112 +# 5.times { create(TextArticle, :profile_id => person.id, :author => person) }
  113 +# assert_equal 'article_author', person.badges.first.name
  114 +# assert_equal 1, person.badges.first.level
  115 +# end
  116 +#
  117 +# should 'add merit badge level 2 to author when create 10 new articles' do
  118 +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 1)
  119 +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 2, :custom_fields => {:threshold => 10})
  120 +# GamificationPlugin.gamification_set_rules(environment)
  121 +#
  122 +# 10.times { create(TextArticle, :profile_id => person.id, :author => person) }
  123 +# assert_equal ['article_author'], person.badges.map(&:name).uniq
  124 +# assert_equal [1, 2], person.badges.map(&:level)
  125 +# end
  126 +end
... ...