Sha256: 6d771730e5587244c775ced5ca7d76309d69c3e00ba56d0a183ef1c210fcf20a

Contents?: true

Size: 726 Bytes

Versions: 14

Compression:

Stored size: 726 Bytes

Contents

require 'spec_helper'

describe 'OperationFailure code' do
  let(:collection_name) { 'operation_error_code_spec' }
  let(:collection) { authorized_client[collection_name] }

  before do
    collection.delete_many
  end

  context 'duplicate key error' do
    it 'is set' do
      begin
        collection.insert_one(_id: 1)
        collection.insert_one(_id: 1)
        fail('Should have raised')
      rescue Mongo::Error::OperationFailure => e
        expect(e.code).to eq(11000)
        # 4.0 and 4.1 sharded clusters set code name.
        # 4.0 and 4.1 replica sets and standalones do not,
        # and neither do older versions.
        expect([nil, 'DuplicateKey']).to include(e.code_name)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongo-2.8.0/spec/integration/operation_failure_code_spec.rb
mongo-2.9.2 spec/integration/operation_failure_code_spec.rb
mongo-2.9.1 spec/integration/operation_failure_code_spec.rb
mongo-2.9.1.rc0 spec/integration/operation_failure_code_spec.rb
mongo-2.9.0 spec/integration/operation_failure_code_spec.rb
mongo-2.9.0.rc1 spec/integration/operation_failure_code_spec.rb
mongo-2.9.0.rc0 spec/integration/operation_failure_code_spec.rb
mongo-2.8.0 spec/integration/operation_failure_code_spec.rb
mongo-2.7.2 spec/integration/operation_failure_code_spec.rb
mongo-2.8.0.rc0 spec/integration/operation_failure_code_spec.rb
mongo-2.7.1 spec/integration/operation_failure_code_spec.rb
mongo-2.7.0 spec/integration/operation_failure_code_spec.rb
mongo-2.7.0.rc0 spec/integration/operation_failure_code_spec.rb
mongo-2.6.4 spec/integration/operation_failure_code_spec.rb