require 'spec_helper' describe PGJob::Job do before do @job = PGJob::Job.new(dbname: 'pgjob_test') end after do @job.finish! end describe '#create' do it 'success' do id = @job.create("test", key: 'value') id.should > 0 id.should be_kind_of(Fixnum) end it 'accepts only symbol keys' do -> { @job.create("test", 'key' => 'value') }.should raise_error -> { @job.create("test", :hash => {'key' => 'value'}) }.should raise_error end end describe '#status' do it 'running' do id = @job.create("test", key: 'value') @job.status(id, :running, 'info') @job.running?(id).should be_true @job.finished?(id).should be_false @job.success?(id).should be_false @job.failed?(id).should be_false @job.status(id).should == 'info' end it 'success' do id = @job.create("test", key: 'value') @job.status(id, :success, 'info') @job.running?(id).should be_false @job.finished?(id).should be_true @job.success?(id).should be_true @job.failed?(id).should be_false @job.status(id).should == 'info' end it 'failed' do id = @job.create("test", key: 'value') @job.status(id, :failed, 'info') @job.running?(id).should be_false @job.finished?(id).should be_true @job.success?(id).should be_false @job.failed?(id).should be_true @job.status(id).should == 'info' end end it '#name' do id = @job.create("test", key: 'value') @job.name(id).should == 'test' end describe '#params' do it 'returns' do id = @job.create("test", key: 'value') @job.params(id).should == {key: 'value'} end it 'returns integer values' do id = @job.create("test", key: 1054) @job.params(id).should == {key: 1054} end it 'symbolizes all keys' do id = @job.create("test", hash: {key: 1054}) @job.params(id).should == {hash: {key: 1054}} end end describe '#log' do it "success" do id = @job.create("test") @job.add_log(id, 'msg1') @job.add_log(id, 'msg2') @job.log(id).should == "msg1\nmsg2" end it 'escape' do id = @job.create("test") hard = ['"', "'", '#', '@', '!', "\n"].join @job.add_log(id, hard) @job.log(id).should == hard end it "log + status" do id = @job.create("test") @job.add_log(id, 'msg1') @job.status(id, :success, 'done') @job.add_log(id, 'msg2') @job.log(id).should == "msg1\n[mode] success - done\nmsg2" end end end