From 7ec9d586807fa013de82d58f6a6a46c186601a61 Mon Sep 17 00:00:00 2001 From: pedrodelyra Date: Thu, 6 Aug 2015 16:12:00 -0300 Subject: [PATCH] Testing average rating feature --- plugins/communities_ratings/test/unit/community_rating_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+), 0 deletions(-) diff --git a/plugins/communities_ratings/test/unit/community_rating_test.rb b/plugins/communities_ratings/test/unit/community_rating_test.rb index efebd78..c24b938 100644 --- a/plugins/communities_ratings/test/unit/community_rating_test.rb +++ b/plugins/communities_ratings/test/unit/community_rating_test.rb @@ -20,4 +20,22 @@ class CommunityRatingTest < ActiveSupport::TestCase assert_equal false, cr1.errors[:value].include?("must be between 1 and 5") assert_equal false, cr2.errors[:value].include?("must be between 1 and 5") end + + test "Should calculate community's rating average" do + community = fast_create Community + p1 = fast_create Person, :name=>"Person 1" + p2 = fast_create Person, :name=>"Person 2" + p3 = fast_create Person, :name=>"Person 3" + + CommunityRating.create! :value => 2, :community => community, :person => p1 + CommunityRating.create! :value => 3, :community => community, :person => p2 + CommunityRating.create! :value => 5, :community => community, :person => p3 + + assert_equal 3, CommunityRating.average_rating(community) + + p4 = fast_create Person, :name=>"Person 4" + CommunityRating.create! :value => 4, :community => community, :person => p4 + + assert_equal 4, CommunityRating.average_rating(community) + end end -- libgit2 0.21.2