Sha256: 46a521cbb5b4c2e6de970f1bed379b124fcecc16e12ccac9786ccfc8219753b5

Contents?: true

Size: 1.49 KB

Versions: 23

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

each_db_config(Deimos::Backends::Db) do
  include_context 'with publish_backend'

  it 'should save to the database' do
    expect(Deimos.config.metrics).to receive(:increment).with(
      'db_producer.insert',
      tags: %w(topic:my-topic),
      by: 3
    )
    described_class.publish(producer_class: MyProducer, messages: messages)
    records = Deimos::KafkaMessage.all
    expect(records.size).to eq(3)
    expect(records[0].attributes.to_h).to include(
      'message' => '{"foo"=>1}',
      'topic' => 'my-topic',
      'key' => 'foo1'
    )
    expect(records[1].attributes.to_h).to include(
      'message' => '{"foo"=>2}',
      'topic' => 'my-topic',
      'key' => 'foo2'
    )
    expect(records[2].attributes.to_h).to include(
      'message' => '{"foo"=>3}',
      'topic' => 'my-topic',
      'key' => 'foo3'
    )
  end

  it 'should add nil messages' do
    described_class.publish(producer_class: MyProducer,
                            messages: [build_message(nil, 'my-topic', 'foo1')])
    expect(Deimos::KafkaMessage.count).to eq(1)
    expect(Deimos::KafkaMessage.last.message).to eq(nil)
  end

  it 'should add to non-keyed messages' do
    described_class.publish(producer_class: MyNoKeyProducer,
                            messages: messages)
    expect(Deimos::KafkaMessage.count).to eq(3)
    described_class.publish(producer_class: MyNoKeyProducer,
                            messages: [messages.first])
    expect(Deimos::KafkaMessage.count).to eq(4)

  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
deimos-ruby-1.8.2 spec/backends/db_spec.rb
deimos-ruby-1.8.2.pre.beta2 spec/backends/db_spec.rb
deimos-ruby-1.8.2.pre.beta1 spec/backends/db_spec.rb
deimos-ruby-1.8.1.pre.beta9 spec/backends/db_spec.rb
deimos-ruby-1.8.1.pre.beta8 spec/backends/db_spec.rb
deimos-ruby-1.8.1.pre.beta7 spec/backends/db_spec.rb
deimos-ruby-1.8.1.pre.beta6 spec/backends/db_spec.rb
deimos-ruby-1.8.1.pre.beta5 spec/backends/db_spec.rb
deimos-ruby-1.8.1.pre.beta4 spec/backends/db_spec.rb
deimos-ruby-1.8.1.pre.beta3 spec/backends/db_spec.rb
deimos-ruby-1.8.1.pre.beta2 spec/backends/db_spec.rb
deimos-ruby-1.8.1.pre.beta1 spec/backends/db_spec.rb
deimos-ruby-1.8.0.pre.beta2 spec/backends/db_spec.rb
deimos-ruby-1.8.0.pre.beta1 spec/backends/db_spec.rb
deimos-ruby-1.7.0.pre.beta1 spec/backends/db_spec.rb
deimos-ruby-1.6.4 spec/backends/db_spec.rb
deimos-ruby-1.6.3 spec/backends/db_spec.rb
deimos-ruby-1.6.2 spec/backends/db_spec.rb
deimos-ruby-1.6.1 spec/backends/db_spec.rb
deimos-ruby-1.6.0 spec/backends/db_spec.rb