Commit b6df7d113113b5b30d585327fa4939df69c13e92
Exists in
master
and in
1 other branch
fixing merge conflit
Showing
5 changed files
with
85 additions
and
43 deletions
Show diff stats
controllers/admin/gamification_plugin_points_controller.rb
... | ... | @@ -5,18 +5,18 @@ class GamificationPluginPointsController < PluginAdminController |
5 | 5 | end |
6 | 6 | |
7 | 7 | def create |
8 | - if params[:identifier].blank? | |
9 | - profile_id = nil | |
10 | - else | |
11 | - profile = Profile.where identifier: params[:identifier] | |
12 | - profile = profile.first | |
13 | - if profile.nil? | |
14 | - flash[:notice] = _("Can't find a profile with the given identifier") | |
15 | - redirect_to action: :index | |
16 | - return | |
17 | - end | |
18 | - profile_id = profile.id | |
19 | - end | |
8 | + if params[:identifier].blank? | |
9 | + profile_id = nil | |
10 | + else | |
11 | + profile = Profile.where identifier: params[:identifier] | |
12 | + profile = profile.first | |
13 | + if profile.nil? | |
14 | + flash[:notice] = _("Can't find a profile with the given identifier") | |
15 | + redirect_to action: :index | |
16 | + return | |
17 | + end | |
18 | + profile_id = profile.id | |
19 | + end | |
20 | 20 | |
21 | 21 | GamificationPlugin::PointsType.all.each do |pType| |
22 | 22 | GamificationPlugin::PointsCategorization.create point_type_id: pType.id, profile_id: profile_id, weight: 0 | ... | ... |
lib/merit/point_rules.rb
... | ... | @@ -93,7 +93,6 @@ module Merit |
93 | 93 | value: 1, |
94 | 94 | description: _('Friends'), |
95 | 95 | default_weight: 5, |
96 | - profile_action: false | |
97 | 96 | }, |
98 | 97 | profile_completion: { |
99 | 98 | action: ['profile#create', 'profile#update'], |
... | ... | @@ -103,8 +102,7 @@ module Merit |
103 | 102 | description: _('Profile Completion'), |
104 | 103 | default_weight: 100, |
105 | 104 | model_name: "User", |
106 | - condition: lambda {|person| person.person? and person.profile_completion_score_condition }, | |
107 | - profile_action: false | |
105 | + condition: lambda {|person, profile| person.person? and person.profile_completion_score_condition }, | |
108 | 106 | }, |
109 | 107 | follower: { |
110 | 108 | action: 'articlefollower#create', |
... | ... | @@ -115,7 +113,6 @@ module Merit |
115 | 113 | default_weight: 10, |
116 | 114 | model: 'ArticleFollower', |
117 | 115 | condition: lambda {|follow, profile| profile.nil? or follow.article.profile == profile }, |
118 | - profile_action: true | |
119 | 116 | }, |
120 | 117 | followed_article_author: { |
121 | 118 | action: 'articlefollower#create', |
... | ... | @@ -126,7 +123,6 @@ module Merit |
126 | 123 | default_weight: 20, |
127 | 124 | model: 'ArticleFollower', |
128 | 125 | condition: lambda {|follow, profile| profile.nil? or follow.article.profile == profile }, |
129 | - profile_action: true | |
130 | 126 | } |
131 | 127 | } |
132 | 128 | |
... | ... | @@ -138,11 +134,7 @@ module Merit |
138 | 134 | def condition(setting, target, profile) |
139 | 135 | condition = setting[:condition] |
140 | 136 | if condition.present? |
141 | - if setting.fetch(:profile_action, true) | |
142 | - condition.call(target, profile) | |
143 | - else | |
144 | - condition.call(target) | |
145 | - end | |
137 | + condition.call(target, profile) | |
146 | 138 | else |
147 | 139 | true |
148 | 140 | end | ... | ... |
test/functional/application_controller_test.rb
... | ... | @@ -8,6 +8,7 @@ class ApplicationControllerTest < ActionController::TestCase |
8 | 8 | def setup |
9 | 9 | @environment = Environment.default |
10 | 10 | @environment.enable_plugin(GamificationPlugin) |
11 | + create_point_rule_definition('article_author') | |
11 | 12 | @controller = TestController.new |
12 | 13 | @controller.stubs(:environment).returns(@environment) |
13 | 14 | end | ... | ... |
test/functional/gamification_plugin_admin_controller_test.rb
... | ... | @@ -10,27 +10,6 @@ class GamificationPluginAdminControllerTest < ActionController::TestCase |
10 | 10 | |
11 | 11 | attr_accessor :person, :environment |
12 | 12 | |
13 | - should 'save point rules' do | |
14 | - post :points, :settings => {:point_rules => {'comment_author' => {'weight' => '10'}}} | |
15 | - @settings = Noosfero::Plugin::Settings.new(environment.reload, GamificationPlugin) | |
16 | - assert_equal({:point_rules => {'comment_author' => {'weight' => '10'}}}, @settings.settings) | |
17 | - end | |
18 | - | |
19 | - should 'load default weights for point rules' do | |
20 | - get :points | |
21 | - Merit::PointRules::AVAILABLE_RULES.each do |category, setting| | |
22 | - assert_select 'input[name=?][value=?]', "settings[point_rules][#{category}[weight]]", setting[:default_weight] | |
23 | - end | |
24 | - end | |
25 | - | |
26 | - should 'load saved weights for point rules' do | |
27 | - settings = Noosfero::Plugin::Settings.new(environment, GamificationPlugin, {}) | |
28 | - settings.set_setting(:point_rules, {'comment_author' => {'weight' => '500'}}) | |
29 | - settings.save! | |
30 | - get :points | |
31 | - assert_select 'input[name=?][value=?]', "settings[point_rules][comment_author[weight]]", 500 | |
32 | - end | |
33 | - | |
34 | 13 | should 'save rank rules' do |
35 | 14 | post :levels, :settings => {:rank_rules => [{:level => 1, :points => 10}]} |
36 | 15 | @settings = Noosfero::Plugin::Settings.new(environment.reload, GamificationPlugin) | ... | ... |
test/functional/gamification_plugin_points_controller_test.rb
0 → 100644
... | ... | @@ -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 | ... | ... |