Skip to content

Instantly share code, notes, and snippets.

@Fivell
Last active August 29, 2015 14:08
Show Gist options
  • Save Fivell/2d0faace709de2d66887 to your computer and use it in GitHub Desktop.
Save Fivell/2d0faace709de2d66887 to your computer and use it in GitHub Desktop.
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
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