gamification_plugin_points_controller_test.rb
2.41 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
63
64
65
66
67
68
69
require_relative "../test_helper"
class GamificationPluginPointsControllerTest < ActionController::TestCase
setup do
@environment = Environment.default
login_as(create_admin_user(@environment))
end
should "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:categories)
end
should "should create gamification_plugin_point_categorizations for existing community" do
community = fast_create(Community)
create_all_point_rules
count = GamificationPlugin::PointsType.count
assert_difference('GamificationPlugin::PointsCategorization.for_profile(community.identifier).count', count) do
post :create, identifier: community.identifier
end
end
should "should create gamification_plugin_point_categorizations for general rules" do
count = GamificationPlugin::PointsType.count
assert_difference('GamificationPlugin::PointsCategorization.count', count) do
post :create, identifier: ''
end
end
should "should not create gamification_plugin_point_categorizations for not existing community" do
create_all_point_rules
assert_no_difference('GamificationPlugin::PointsCategorization.count') do
post :create, identifier: 'any_not_existent_community_name'
end
end
should "should get edit" do
community = fast_create(Community)
create_point_rule_definition('article_author', community)
get :edit, id: community.id
assert_not_nil assigns(:profile)
assert_not_nil assigns(:categories)
end
should "should update gamification_plugin_points" do
community = fast_create(Community)
create_point_rule_definition('article_author', community)
weights = {}
GamificationPlugin::PointsCategorization.for_profile(community.identifier).each do |c|
weights[c.id] = {weight: c.weight+10}
end
put :edit, id: community.id, gamification_plugin_points_categorizations: weights
weights.each do |id, w|
c = GamificationPlugin::PointsCategorization.find id
assert_equal c.weight, w[:weight]
end
end
should "should destroy gamification_plugin_point" do
community = fast_create(Community)
create_point_rule_definition('article_author', community)
count = GamificationPlugin::PointsCategorization.for_profile(community.identifier).count
assert_difference('GamificationPlugin::PointsCategorization.count',-count) do
delete :destroy, id: community.id
end
end
end