profile_test.rb
1.18 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
require_relative "../test_helper"
class ProfileTest < ActiveSupport::TestCase
def setup
@environment = Environment.default
@profile = fast_create(Profile)
@settings = GamificationPlugin.settings(environment)
@settings.set_setting(:rank_rules, [
{:level => 1, :points => 10},
{:level => 2, :points => 20},
{:level => 3, :points => 30}
])
@settings.save!
end
attr_accessor :profile, :environment
should 'calculate profile level' do
profile.stubs(:points).returns(25)
assert_equal 2, profile.gamification_plugin_calculate_level
end
should 'calculate profile last level' do
profile.stubs(:points).returns(35)
assert_equal 3, profile.gamification_plugin_calculate_level
end
should 'calculate profile first level' do
profile.stubs(:points).returns(10)
assert_equal 1, profile.gamification_plugin_calculate_level
end
should 'update profile level when the score changes' do
GamificationPlugin.gamification_set_rules(environment)
person = create_user('testuser').person
assert_equal 0, person.level
create(Article, :profile_id => profile.id, :author => person)
assert_equal 3, person.reload.level
end
end