gamification_plugin_points_categorizations_test.rb
2.01 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
require 'test_helper'
class GamificationPluginPointsCategorizationsTest < ActiveSupport::TestCase
should 'require value for weight' do
p = GamificationPlugin::PointsCategorization.new
p.valid?
assert p.errors[:weight].present?
p.weight = 12
p.valid?
refute p.errors[:weight].present?
end
should 'require value for point type' do
p = GamificationPlugin::PointsCategorization.new
p.valid?
assert p.errors[:point_type_id].present?
p.point_type = GamificationPlugin::PointsType.create!(:name => 'some')
p.valid?
refute p.errors[:point_type_id].present?
end
should 'the point type be unique in profile scope' do
point_type = GamificationPlugin::PointsType.create!(:name => 'some')
profile = fast_create(Community)
GamificationPlugin::PointsCategorization.new(:weight => 10, :point_type_id => point_type.id, :profile_id => profile.id).save!
p = GamificationPlugin::PointsCategorization.new(:weight => 10, :point_type_id => point_type.id, :profile_id => profile.id)
p.valid?
assert p.errors[:point_type_id].present?
end
should 'the point type be unique in profile scope when profile is nil' do
point_type = GamificationPlugin::PointsType.create!(:name => 'some')
GamificationPlugin::PointsCategorization.new(:weight => 10, :point_type_id => point_type.id).save!
p = GamificationPlugin::PointsCategorization.new(:weight => 10, :point_type_id => point_type.id)
p.valid?
assert p.errors[:point_type_id].present?
end
should 'the point type be used in differente profile scopes' do
point_type = GamificationPlugin::PointsType.create!(:name => 'some')
p1 = fast_create(Community)
GamificationPlugin::PointsCategorization.new(:weight => 10, :point_type_id => point_type.id, :profile_id => p1.id).save!
p2 = fast_create(Community)
p = GamificationPlugin::PointsCategorization.new(:weight => 10, :point_type_id => point_type.id, :profile_id => p2.id)
p.valid?
refute p.errors[:point_type_id].present?
end
end