grant the users the badge

This commit is contained in:
Rimian Perkins 2017-04-27 19:10:00 +10:00
parent 219444eab2
commit 14dd31b027
3 changed files with 32 additions and 4 deletions

View File

@ -4,10 +4,11 @@ module Jobs
every 1.minutes
def execute(_args)
puts '====================== The Award Group Job was executed ==========================='
user_queue.each do |email|
user = User.find_by_email(email)
DiscourseDonations::Rewards.new(user).add_to_group(group_name) if user.present?
next if user.nil?
puts "Added user #{user.email} to #{group_name}"
DiscourseDonations::Rewards.new(user).add_to_group(group_name)
end
user_queue_reset
end

View File

@ -4,7 +4,27 @@ module Jobs
every 5.minutes
def execute(_args)
puts '====================== The Grant Badge Job was executed ==========================='
user_queue.each do |email|
user = User.find_by_email(email)
next if user.nil?
puts "Granted user #{user.email} with badge: #{badge_name}"
DiscourseDonations::Rewards.new(user).grant_badge(badge_name)
end
user_queue_reset
end
private
def user_queue
PluginStore.get('discourse-donations', 'badge:grant') || []
end
def user_queue_reset
PluginStore.set('discourse-donations', 'badge:grant', [])
end
def badge_name
SiteSetting.discourse_donations_reward_badge_name
end
end
end

View File

@ -5,7 +5,14 @@ RSpec.describe Jobs::GrantBadge, type: :job do
before do
SiteSetting.stubs(:discourse_donations_reward_badge_name).returns(badge.name)
PluginStore.set('discourse-donations', 'badge:grant', [users.first.email, users.last.email])
end
it 'grants all the users the badge'
it 'grants all the users the badge' do
Jobs::GrantBadge.new.execute(nil)
aggregate_failures do
expect(users.first.badges).to include(badge)
expect(users.last.badges).to include(badge)
end
end
end