Last active
August 29, 2015 14:08
-
-
Save Fivell/2d0faace709de2d66887 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Jobs | |
class AutoRefill < ::BaseJob | |
def execute | |
logger.tagged('autorefill') do | |
scope_to_process.each do |prepaid| | |
begin | |
RefillService.new(prepaid).save! | |
rescue StandardError => e | |
logger.error{[e.message , e.backtrace.join("\n")].join("\n") } | |
end | |
end | |
end | |
end | |
def scope_to_process | |
VPDD::UserPrepaid.auto_refill | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe "Auto-Refill Job" do | |
include_context :queue | |
before do | |
@job = Jobs::AutoRefill.first | |
end | |
context "run job" do | |
let(:collection) { | |
[instance_double("VPDD::UserPrepaid"), instance_double("VPDD::UserPrepaid")] | |
} | |
before do | |
allow_any_instance_of(RefillService).to receive(:save!).and_return(true) | |
allow_any_instance_of(Jobs::AutoRefill).to receive(:scope_to_process).and_return(collection) | |
@job.run! | |
end | |
it "should make refill for each prepaid" do | |
expect_any_instance_of(RefillService).to receive(:save!).twice.and_return(true) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment