diff --git a/lib/activejob-status/status.rb b/lib/activejob-status/status.rb index 3509687..6e25784 100644 --- a/lib/activejob-status/status.rb +++ b/lib/activejob-status/status.rb @@ -44,7 +44,9 @@ def status end def progress - read[:progress].to_f / read[:total].to_f + read.then do |hash| + hash[:progress].to_f / hash[:total].to_f + end end def present? diff --git a/spec/specs/active_job/status_spec.rb b/spec/specs/active_job/status_spec.rb index 1004c33..1c9f512 100644 --- a/spec/specs/active_job/status_spec.rb +++ b/spec/specs/active_job/status_spec.rb @@ -101,6 +101,14 @@ def jobs_with(*args, **kwargs) expect(job.status.progress).to eq(0.4) end end + + it "reads cache once" do + job = BaseJob.new + + allow(described_class.store).to receive(:read) + job.status.progress + expect(described_class.store).to have_received(:read).once + end end describe "job status" do