Commit ce90725256940bea881c0bce823694d2d5570d85
1 parent
9e756466
Exists in
master
Do not display notifications when gamification is disabled for a profile
Showing
2 changed files
with
19 additions
and
2 deletions
Show diff stats
lib/gamification_plugin.rb
| ... | ... | @@ -35,7 +35,7 @@ class GamificationPlugin < Noosfero::Plugin |
| 35 | 35 | |
| 36 | 36 | def body_ending |
| 37 | 37 | proc do |
| 38 | - if current_person.present? && response.status == 200 | |
| 38 | + if current_person.present? && !current_person.gamification_plugin_disabled && response.status == 200 | |
| 39 | 39 | badges = current_person.badges.notification_pending.all |
| 40 | 40 | current_person.sash.notify_all_badges_from_user |
| 41 | 41 | render :file => 'gamification/display_notifications', :locals => {:badges => badges} | ... | ... |
test/unit/gamification_plugin_test.rb
| ... | ... | @@ -5,9 +5,10 @@ class GamificationPluginTest < ActiveSupport::TestCase |
| 5 | 5 | def setup |
| 6 | 6 | @plugin = GamificationPlugin.new |
| 7 | 7 | @current_person = create_user('person').person |
| 8 | + @response = mock | |
| 8 | 9 | end |
| 9 | 10 | |
| 10 | - attr_accessor :plugin, :current_person | |
| 11 | + attr_accessor :plugin, :current_person, :response | |
| 11 | 12 | |
| 12 | 13 | should 'return user points and badges in user_data_extras' do |
| 13 | 14 | assert_equal({:gamification_plugin => {:points => 0, :badges => [], :level => 0}}, instance_eval(&plugin.user_data_extras)) |
| ... | ... | @@ -18,4 +19,20 @@ class GamificationPluginTest < ActiveSupport::TestCase |
| 18 | 19 | assert_equal({}, instance_eval(&plugin.user_data_extras)) |
| 19 | 20 | end |
| 20 | 21 | |
| 22 | + should 'render notifications for a profile' do | |
| 23 | + response.expects(:status).returns(200) | |
| 24 | + expects(:render).returns('render notifications') | |
| 25 | + assert_equal 'render notifications', instance_eval(&plugin.body_ending) | |
| 26 | + end | |
| 27 | + | |
| 28 | + should 'render nothing when there is no current person' do | |
| 29 | + @current_person = nil | |
| 30 | + assert_equal '', instance_eval(&plugin.body_ending) | |
| 31 | + end | |
| 32 | + | |
| 33 | + should 'not render notifications when gamification is disabled for a profile' do | |
| 34 | + current_person.update_attribute(:gamification_plugin_disabled, true) | |
| 35 | + assert_equal '', instance_eval(&plugin.body_ending) | |
| 36 | + end | |
| 37 | + | |
| 21 | 38 | end | ... | ... |