I have a (simplified) module: (/app/jobs/checkpulse.rb)
module CheckPulse
@queue = :heartbeat
def self.perform()
Machine.all.each do |machine|
machine.update_columns(active_alarm: true) #do not want to touch updated_at
end
end
end
I can use it in the rails console and it changes all machines as expected.
I am trying to write a spec to test it: (/spec/jobs/checkpulse_spec.rb)
require "spec_helper"
require_relative '../../app/jobs/checkpulse'
describe "CheckPulse" do
let(:user) { FactoryGirl.create(:user) }
let!(:machine) { FactoryGirl.create(:machine, user: user, heartbeat_timeout: 5) }
it "should change the machine to alarm mode" do
CheckPulse.perform
expect(machine.active_alarm).to be_true
end
end
This test fails every time. I have used puts inside the CheckPulse module to check on it and it has the expected behaviour inside the module, but when it returns from the module, the machine has not changed.
I have tried mixing the module into a dummy class, but that didn't work either. I also tried running rails console in the test environment to see if it was an environment problem, but the module worked fine there too.
I have spent the entire day on this, please help!