diff --git a/lib/gamification_plugin.rb b/lib/gamification_plugin.rb index b354729..16b19a4 100644 --- a/lib/gamification_plugin.rb +++ b/lib/gamification_plugin.rb @@ -35,7 +35,7 @@ class GamificationPlugin < Noosfero::Plugin def body_ending proc do - if current_person.present? && response.status == 200 + if current_person.present? && !current_person.gamification_plugin_disabled && response.status == 200 badges = current_person.badges.notification_pending.all current_person.sash.notify_all_badges_from_user render :file => 'gamification/display_notifications', :locals => {:badges => badges} diff --git a/test/unit/gamification_plugin_test.rb b/test/unit/gamification_plugin_test.rb index 32da134..972467a 100644 --- a/test/unit/gamification_plugin_test.rb +++ b/test/unit/gamification_plugin_test.rb @@ -5,9 +5,10 @@ class GamificationPluginTest < ActiveSupport::TestCase def setup @plugin = GamificationPlugin.new @current_person = create_user('person').person + @response = mock end - attr_accessor :plugin, :current_person + attr_accessor :plugin, :current_person, :response should 'return user points and badges in user_data_extras' do assert_equal({:gamification_plugin => {:points => 0, :badges => [], :level => 0}}, instance_eval(&plugin.user_data_extras)) @@ -18,4 +19,20 @@ class GamificationPluginTest < ActiveSupport::TestCase assert_equal({}, instance_eval(&plugin.user_data_extras)) end + should 'render notifications for a profile' do + response.expects(:status).returns(200) + expects(:render).returns('render notifications') + assert_equal 'render notifications', instance_eval(&plugin.body_ending) + end + + should 'render nothing when there is no current person' do + @current_person = nil + assert_equal '', instance_eval(&plugin.body_ending) + end + + should 'not render notifications when gamification is disabled for a profile' do + current_person.update_attribute(:gamification_plugin_disabled, true) + assert_equal '', instance_eval(&plugin.body_ending) + end + end -- libgit2 0.21.2