ratings_helper_test.rb
1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper'
require 'ratings_helper'
class RatingsHelperTest < ActiveSupport::TestCase
include RatingsHelper
def setup
@environment = Environment.default
@environment.enabled_plugins = ['CommunitiesRatingsPlugin']
@environment.save
@person = create_user('testuser').person
@community = Community.create(:name => "TestCommunity")
end
should "get the ratings of a community ordered by most recent ratings" do
ratings_array = []
first_rating = CommunityRating.new
first_rating.community = @community
first_rating.person = @person
first_rating.value = 3
first_rating.save
most_recent_rating = CommunityRating.new
most_recent_rating.community = @community
most_recent_rating.person = @person
most_recent_rating.value = 5
sleep 2
most_recent_rating.save
ratings_array << most_recent_rating
ratings_array << first_rating
assert_equal @environment.communities_ratings_order, "most recent"
assert_equal ratings_array, get_ratings(@community.id)
end
should "get the ratings of a community ordered by best ratings" do
ratings_array = []
@environment.communities_ratings_order = "best ratings"
@environment.save
first_rating = CommunityRating.new
first_rating.community = @community
first_rating.person = @person
first_rating.value = 3
first_rating.save
second_rating = CommunityRating.new
second_rating.community = @community
second_rating.person = @person
second_rating.value = 5
sleep 2
second_rating.save
ratings_array << second_rating
ratings_array << first_rating
assert_equal ratings_array, get_ratings(@community.id)
end
end