mirror of
https://github.com/plashchynski/crono.git
synced 2026-04-25 02:08:43 +02:00
Lint the whole project
This commit is contained in:
@@ -1,66 +1,67 @@
|
||||
require "spec_helper"
|
||||
require 'spec_helper'
|
||||
|
||||
class TestJob
|
||||
def perform;end
|
||||
def perform
|
||||
end
|
||||
end
|
||||
|
||||
class TestFailingJob
|
||||
def perform
|
||||
raise "Some error"
|
||||
fail 'Some error'
|
||||
end
|
||||
end
|
||||
|
||||
describe Crono::Job do
|
||||
let(:period) { Crono::Period.new(2.day) }
|
||||
let(:job) { Crono::Job.new(TestJob, period) }
|
||||
let(:job) { Crono::Job.new(TestJob, period) }
|
||||
let(:failing_job) { Crono::Job.new(TestFailingJob, period) }
|
||||
|
||||
it "should contain performer and period" do
|
||||
it 'should contain performer and period' do
|
||||
expect(job.performer).to be TestJob
|
||||
expect(job.period).to be period
|
||||
end
|
||||
|
||||
describe "#perform" do
|
||||
describe '#perform' do
|
||||
after { job.send(:model).destroy }
|
||||
|
||||
it "should run performer in separate thread" do
|
||||
it 'should run performer in separate thread' do
|
||||
expect(job).to receive(:save)
|
||||
thread = job.perform.join
|
||||
expect(thread).to be_stop
|
||||
end
|
||||
|
||||
it "should save performin errors to log" do
|
||||
it 'should save performin errors to log' do
|
||||
thread = failing_job.perform.join
|
||||
expect(thread).to be_stop
|
||||
saved_log = Crono::CronoJob.find_by(job_id: failing_job.job_id).log
|
||||
expect(saved_log).to include "Some error"
|
||||
expect(saved_log).to include 'Some error'
|
||||
end
|
||||
|
||||
it "should set Job#healthy to true if perform ok" do
|
||||
thread = job.perform.join
|
||||
it 'should set Job#healthy to true if perform ok' do
|
||||
job.perform.join
|
||||
expect(job.healthy).to be true
|
||||
end
|
||||
|
||||
it "should set Job#healthy to false if perform with error" do
|
||||
thread = failing_job.perform.join
|
||||
it 'should set Job#healthy to false if perform with error' do
|
||||
failing_job.perform.join
|
||||
expect(failing_job.healthy).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#description" do
|
||||
it "should return job identificator" do
|
||||
expect(job.description).to be_eql("Perform TestJob every 2 days")
|
||||
describe '#description' do
|
||||
it 'should return job identificator' do
|
||||
expect(job.description).to be_eql('Perform TestJob every 2 days')
|
||||
end
|
||||
end
|
||||
|
||||
describe "#save" do
|
||||
it "should save new job to DB" do
|
||||
describe '#save' do
|
||||
it 'should save new job to DB' do
|
||||
expect(Crono::CronoJob.where(job_id: job.job_id)).to_not exist
|
||||
job.save
|
||||
expect(Crono::CronoJob.where(job_id: job.job_id)).to exist
|
||||
end
|
||||
|
||||
it "should update saved job" do
|
||||
it 'should update saved job' do
|
||||
job.last_performed_at = Time.now
|
||||
job.healthy = true
|
||||
job.save
|
||||
@@ -69,8 +70,8 @@ describe Crono::Job do
|
||||
expect(@crono_job.healthy).to be true
|
||||
end
|
||||
|
||||
it "should save and truncate job log" do
|
||||
message = "test message"
|
||||
it 'should save and truncate job log' do
|
||||
message = 'test message'
|
||||
job.send(:log, message)
|
||||
job.save
|
||||
expect(job.send(:model).reload.log).to include message
|
||||
@@ -78,37 +79,37 @@ describe Crono::Job do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#load" do
|
||||
describe '#load' do
|
||||
before do
|
||||
@saved_last_performed_at = job.last_performed_at = Time.now
|
||||
job.save
|
||||
end
|
||||
|
||||
it "should load last_performed_at from DB" do
|
||||
it 'should load last_performed_at from DB' do
|
||||
@job = Crono::Job.new(TestJob, period)
|
||||
@job.load
|
||||
expect(@job.last_performed_at.utc.to_s).to be_eql @saved_last_performed_at.utc.to_s
|
||||
end
|
||||
end
|
||||
|
||||
describe "#log" do
|
||||
it "should write log messages to both common and job log" do
|
||||
message = "Test message"
|
||||
describe '#log' do
|
||||
it 'should write log messages to both common and job log' do
|
||||
message = 'Test message'
|
||||
expect(job.logger).to receive(:log).with(Logger::INFO, message)
|
||||
expect(job.job_logger).to receive(:log).with(Logger::INFO, message)
|
||||
job.send(:log, message)
|
||||
end
|
||||
|
||||
it "should write job log to Job#job_log" do
|
||||
message = "Test message"
|
||||
it 'should write job log to Job#job_log' do
|
||||
message = 'Test message'
|
||||
job.send(:log, message)
|
||||
expect(job.job_log.string).to include(message)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#log_error" do
|
||||
it "should call log with ERROR severity" do
|
||||
message = "Test message"
|
||||
describe '#log_error' do
|
||||
it 'should call log with ERROR severity' do
|
||||
message = 'Test message'
|
||||
expect(job).to receive(:log).with(message, Logger::ERROR)
|
||||
job.send(:log_error, message)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user