2016-12-21 09:59:54 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe UseKeyWorker do
|
|
|
|
describe "#perform" do
|
|
|
|
it "updates the key's last_used_at attribute to the current time when it exists" do
|
|
|
|
worker = described_class.new
|
|
|
|
key = create(:key)
|
|
|
|
current_time = Time.zone.now
|
|
|
|
|
|
|
|
Timecop.freeze(current_time) do
|
2017-02-22 11:55:08 -05:00
|
|
|
expect { worker.perform(key.id) }
|
|
|
|
.to change { key.reload.last_used_at }.from(nil).to be_like_time(current_time)
|
2016-12-21 09:59:54 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false and skips the job when the key doesn't exist" do
|
|
|
|
worker = described_class.new
|
|
|
|
key = create(:key)
|
|
|
|
|
|
|
|
expect(worker.perform(key.id + 1)).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|