From 999b106b6548dcfbf0d1e2a948a2582d2796f374 Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Thu, 27 Apr 2017 14:51:47 +1000 Subject: [PATCH] the award job adds the user to a group --- .../discourse_donations/charges_controller.rb | 1 - app/jobs/award_group.rb | 11 +++++++++++ lib/discourse_donations/engine.rb | 2 ++ spec/jobs/award_group_spec.rb | 9 +++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 spec/jobs/award_group_spec.rb diff --git a/app/controllers/discourse_donations/charges_controller.rb b/app/controllers/discourse_donations/charges_controller.rb index fc3e1cf..720e9d7 100644 --- a/app/controllers/discourse_donations/charges_controller.rb +++ b/app/controllers/discourse_donations/charges_controller.rb @@ -1,5 +1,4 @@ require_dependency 'discourse' -require_relative '../../jobs/award_group' module DiscourseDonations class ChargesController < ActionController::Base diff --git a/app/jobs/award_group.rb b/app/jobs/award_group.rb index 0996eff..1c69eb9 100644 --- a/app/jobs/award_group.rb +++ b/app/jobs/award_group.rb @@ -5,5 +5,16 @@ module Jobs def perform(args) puts '======================The Job was performed===========================' end + + def self.perform_in(arg, opts) + puts '======================The Job was enqueued===========================' + end + + def execute(args) + user = User.find_by_email(args[:email]) + if user.present? + DiscourseDonations::Rewards.new(user).add_to_group(args[:group_name]) + end + end end end diff --git a/lib/discourse_donations/engine.rb b/lib/discourse_donations/engine.rb index d92e065..b85aebb 100644 --- a/lib/discourse_donations/engine.rb +++ b/lib/discourse_donations/engine.rb @@ -1,3 +1,5 @@ +require_relative '../../app/jobs/award_group' + module ::DiscourseDonations class Engine < ::Rails::Engine engine_name 'discourse-donations' diff --git a/spec/jobs/award_group_spec.rb b/spec/jobs/award_group_spec.rb new file mode 100644 index 0000000..1a9b5c0 --- /dev/null +++ b/spec/jobs/award_group_spec.rb @@ -0,0 +1,9 @@ + +RSpec.describe Jobs::AwardGroup, type: :job do + it 'adds the user to a group' do + user = Fabricate(:user) + grp = Fabricate(:group) + Jobs::AwardGroup.new.execute(email: user.email, group_name: grp.name) + expect(user.groups).to include(grp) + end +end