Sha256: 8318c1c1dace8c0223254d2be9d8c05df4bc0db5f98a1c71a015f9e18ba52078

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'
require 'qu-mongoid'

describe Qu::Backend::Mongoid do
  it_should_behave_like 'a backend'

  describe 'connection' do
    it 'should default the qu database' do
      subject.connection.should be_instance_of(Moped::Session)
      subject.connection.options[:database].should == 'qu'
    end
    
    it 'should use MONGOHQ_URL from heroku' do
      # Clean up from other tests
      ::Mongoid.sessions[:default]  = nil
      subject.instance_eval {@connection=nil}
      ::Mongoid::Sessions.clear
      
      ENV['MONGOHQ_URL'] = 'mongodb://127.0.0.1:27017/quspec'
      subject.connection.options[:database].should == 'quspec'
      subject.connection.cluster.nodes.first.resolved_address.should == "127.0.0.1:27017"
      ::Mongoid.sessions[:default][:hosts].should include("127.0.0.1:27017")
      
      # Clean up MONGOHQ stuff
      ENV.delete('MONGOHQ_URL')
      subject.instance_eval {@connection=nil}
      ::Mongoid.connect_to('qu')
    end
  end

  describe 'reserve' do
    let(:worker) { Qu::Worker.new }

    describe "on mongo >=2" do
      it 'should return nil when no jobs exist' do
        subject.clear
        Moped::Session.any_instance.should_receive(:command).and_return(nil)
        lambda { subject.reserve(worker, :block => false).should be_nil }.should_not raise_error
      end
    end

    describe 'on mongo <2' do
      it 'should return nil when no jobs exist' do
        subject.clear
        subject.connection.should_receive(:command).and_raise(Moped::Errors::OperationFailure.new(nil, 'test'))
        lambda { subject.reserve(worker, :block => false).should be_nil }.should_not raise_error
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qu-mongoid-0.2.0 spec/qu/backend/mongoid_spec.rb