Commit 7ec9d586807fa013de82d58f6a6a46c186601a61
Committed by
Fabio Teixeira
1 parent
75bd9845
Exists in
communities_ratings
Testing average rating feature
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com>
Showing
1 changed file
with
18 additions
and
0 deletions
Show diff stats
plugins/communities_ratings/test/unit/community_rating_test.rb
... | ... | @@ -20,4 +20,22 @@ class CommunityRatingTest < ActiveSupport::TestCase |
20 | 20 | assert_equal false, cr1.errors[:value].include?("must be between 1 and 5") |
21 | 21 | assert_equal false, cr2.errors[:value].include?("must be between 1 and 5") |
22 | 22 | end |
23 | + | |
24 | + test "Should calculate community's rating average" do | |
25 | + community = fast_create Community | |
26 | + p1 = fast_create Person, :name=>"Person 1" | |
27 | + p2 = fast_create Person, :name=>"Person 2" | |
28 | + p3 = fast_create Person, :name=>"Person 3" | |
29 | + | |
30 | + CommunityRating.create! :value => 2, :community => community, :person => p1 | |
31 | + CommunityRating.create! :value => 3, :community => community, :person => p2 | |
32 | + CommunityRating.create! :value => 5, :community => community, :person => p3 | |
33 | + | |
34 | + assert_equal 3, CommunityRating.average_rating(community) | |
35 | + | |
36 | + p4 = fast_create Person, :name=>"Person 4" | |
37 | + CommunityRating.create! :value => 4, :community => community, :person => p4 | |
38 | + | |
39 | + assert_equal 4, CommunityRating.average_rating(community) | |
40 | + end | |
23 | 41 | end | ... | ... |