Sha256: 912a39d53dec4d254d30ef8b1db6e0a9183569106230d6c353d5a292340335e9

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

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 'returns' do
      id = @job.create("test", key: 'value')
      @job.status(id).should == :wait
    end

    it 'sets' do
      id = @job.create("test", key: 'value')
      @job.status(id, :running)
      @job.status(id).should == :running
    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pgjob-0.1.0 spec/job_spec.rb