Commit 13b6e3a3105c1283e653ff074daf935ec4a9ac7c
1 parent
e8dcaa70
Exists in
master
and in
1 other branch
Add points tests and adjust others
Showing
3 changed files
with
71 additions
and
23 deletions
Show diff stats
test/functional/application_controller_test.rb
@@ -7,8 +7,8 @@ class ApplicationControllerTest < ActionController::TestCase | @@ -7,8 +7,8 @@ class ApplicationControllerTest < ActionController::TestCase | ||
7 | 7 | ||
8 | def setup | 8 | def setup |
9 | @environment = Environment.default | 9 | @environment = Environment.default |
10 | - create_merit_categorization | ||
11 | @environment.enable_plugin(GamificationPlugin) | 10 | @environment.enable_plugin(GamificationPlugin) |
11 | + create_point_rule_definition('article_author') | ||
12 | @controller = TestController.new | 12 | @controller = TestController.new |
13 | @controller.stubs(:environment).returns(@environment) | 13 | @controller.stubs(:environment).returns(@environment) |
14 | end | 14 | end |
test/functional/gamification_plugin_admin_controller_test.rb
@@ -4,34 +4,12 @@ class GamificationPluginAdminControllerTest < ActionController::TestCase | @@ -4,34 +4,12 @@ class GamificationPluginAdminControllerTest < ActionController::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @environment = Environment.default | 6 | @environment = Environment.default |
7 | - create_merit_categorization | ||
8 | @person = create_user_with_permission('profile', 'edit_environment_features', Environment.default) | 7 | @person = create_user_with_permission('profile', 'edit_environment_features', Environment.default) |
9 | login_as(@person.identifier) | 8 | login_as(@person.identifier) |
10 | end | 9 | end |
11 | 10 | ||
12 | attr_accessor :person, :environment | 11 | attr_accessor :person, :environment |
13 | 12 | ||
14 | - should 'save point rules' do | ||
15 | - post :points, :settings => {:point_rules => {'comment_author' => {'weight' => '10'}}} | ||
16 | - @settings = Noosfero::Plugin::Settings.new(environment.reload, GamificationPlugin) | ||
17 | - assert_equal({:point_rules => {'comment_author' => {'weight' => '10'}}}, @settings.settings) | ||
18 | - end | ||
19 | - | ||
20 | - should 'load default weights for point rules' do | ||
21 | - get :points | ||
22 | - Merit::PointRules::AVAILABLE_RULES.each do |category, setting| | ||
23 | - assert_select 'input[name=?][value=?]', "settings[point_rules][#{category}[weight]]", setting[:default_weight] | ||
24 | - end | ||
25 | - end | ||
26 | - | ||
27 | - should 'load saved weights for point rules' do | ||
28 | - settings = Noosfero::Plugin::Settings.new(environment, GamificationPlugin, {}) | ||
29 | - settings.set_setting(:point_rules, {'comment_author' => {'weight' => '500'}}) | ||
30 | - settings.save! | ||
31 | - get :points | ||
32 | - assert_select 'input[name=?][value=?]', "settings[point_rules][comment_author[weight]]", 500 | ||
33 | - end | ||
34 | - | ||
35 | should 'save rank rules' do | 13 | should 'save rank rules' do |
36 | post :levels, :settings => {:rank_rules => [{:level => 1, :points => 10}]} | 14 | post :levels, :settings => {:rank_rules => [{:level => 1, :points => 10}]} |
37 | @settings = Noosfero::Plugin::Settings.new(environment.reload, GamificationPlugin) | 15 | @settings = Noosfero::Plugin::Settings.new(environment.reload, GamificationPlugin) |
test/functional/gamification_plugin_points_controller_test.rb
0 → 100644
@@ -0,0 +1,70 @@ | @@ -0,0 +1,70 @@ | ||
1 | +require 'test_helper' | ||
2 | + | ||
3 | +class GamificationPluginPointsControllerTest < ActionController::TestCase | ||
4 | + | ||
5 | + setup do | ||
6 | + @environment = Environment.default | ||
7 | + login_as(create_admin_user(@environment)) | ||
8 | + end | ||
9 | + | ||
10 | + should "should get index" do | ||
11 | + get :index | ||
12 | + assert_response :success | ||
13 | + assert_not_nil assigns(:categories) | ||
14 | + end | ||
15 | + | ||
16 | + should "should create gamification_plugin_point_categorizations for existing community" do | ||
17 | + community = fast_create(Community) | ||
18 | + create_all_point_rules | ||
19 | + count = GamificationPlugin::PointsType.count | ||
20 | + assert_difference('GamificationPlugin::PointsCategorization.for_profile(community.identifier).count', count) do | ||
21 | + post :create, identifier: community.identifier | ||
22 | + end | ||
23 | + end | ||
24 | + | ||
25 | + should "should create gamification_plugin_point_categorizations for general rules" do | ||
26 | + create_all_point_rules | ||
27 | + count = GamificationPlugin::PointsType.count | ||
28 | + assert_difference('GamificationPlugin::PointsCategorization.count', count) do | ||
29 | + post :create, identifier: '' | ||
30 | + end | ||
31 | + end | ||
32 | + | ||
33 | + should "should not create gamification_plugin_point_categorizations for not existing community" do | ||
34 | + create_all_point_rules | ||
35 | + assert_no_difference('GamificationPlugin::PointsCategorization.count') do | ||
36 | + post :create, identifier: 'any_not_existent_community_name' | ||
37 | + end | ||
38 | + end | ||
39 | + | ||
40 | + should "should get edit" do | ||
41 | + community = fast_create(Community) | ||
42 | + create_point_rule_definition('article_author', community) | ||
43 | + get :edit, id: community.id | ||
44 | + assert_not_nil assigns(:profile) | ||
45 | + assert_not_nil assigns(:categories) | ||
46 | + end | ||
47 | + | ||
48 | + should "should update gamification_plugin_points" do | ||
49 | + community = fast_create(Community) | ||
50 | + create_point_rule_definition('article_author', community) | ||
51 | + weights = {} | ||
52 | + GamificationPlugin::PointsCategorization.for_profile(community.identifier).each do |c| | ||
53 | + weights[c.id] = {weight: c.weight+10} | ||
54 | + end | ||
55 | + put :edit, id: community.id, gamification_plugin_points_categorizations: weights | ||
56 | + weights.each do |id, w| | ||
57 | + c = GamificationPlugin::PointsCategorization.find id | ||
58 | + assert_equal c.weight, w[:weight] | ||
59 | + end | ||
60 | + end | ||
61 | + | ||
62 | + should "should destroy gamification_plugin_point" do | ||
63 | + community = fast_create(Community) | ||
64 | + create_point_rule_definition('article_author', community) | ||
65 | + count = GamificationPlugin::PointsCategorization.for_profile(community.identifier).count | ||
66 | + assert_difference('GamificationPlugin::PointsCategorization.count',-count) do | ||
67 | + delete :destroy, id: community.id | ||
68 | + end | ||
69 | + end | ||
70 | +end |