Sha256: ad44e4874f35fa1834599a3fbd98c2713fb614b79c9658f8fe0d7913dd883f19

Contents?: true

Size: 1.77 KB

Versions: 23

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe RubyRabbitmqJanus::Models::JanusInstance, type: :model,
                                                   name: :janus_instance do
  before { described_class.delete_all }

  after do
    described_class.delete_all
    create_janus_instances
  end

  let(:janus_id) do
    random_instance = [1, 2].sample

    if ENV['MONGO'].match?('true')
      { _id: random_instance.to_s }
    else
      { id: random_instance }
    end
  end
  let(:model) { described_class }

  context 'when Janus Instance simple transaction' do
    it { expect(model.count).to eq(0) }
  end

  context 'when many janus instances' do
    before do
      FactoryGirl.create_list(:janus_instance, 5, enable: false)
      FactoryGirl.create(:janus_instance, janus_id)
    end

    let(:one) { model.enabled.first }

    it { expect(model.count).to eq(6) }
    it { expect(model.enabled.count).to eq(1) }
    it { expect(model.find_by_session(one.session).thread).to eq(one.thread) }
    it { expect(model.find_by_instance(one.instance).session).to eq(one.session) }
  end

  context 'when Janus Instance enable' do
    let(:janus) { FactoryGirl.create(:janus_instance, janus_id) }

    it { expect(janus.valid?).to be_a(TrueClass) }
    it { expect(janus.session).to be_nil }
    it { expect(janus.enable).to be_a(TrueClass) }
    it { expect(janus.enable).to eq(true) }
    it { expect(janus.thread).to be_nil }
  end

  context 'when Janus Instance disable' do
    let(:janus) { FactoryGirl.create(:janus_instance, enable: false) }

    it { expect(janus.valid?).to be_a(TrueClass) }
    it { expect(janus.session).to be_nil }
    it { expect(janus.enable).to be_a(FalseClass) }
    it { expect(janus.enable).to eq(false) }
    it { expect(janus.thread).to be_nil }
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.7.1 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.7.1.pre.274 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.7.0.pre.272 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.7.0 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.7.0.pre.269 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.7.0.pre.267 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.6.0 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.6.0.pre.263 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.6.0.pre.261 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.6.0.pre.260 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.6.0.pre.259 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.6.0.pre.258 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.6.0.pre.247 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.6.0.pre.246 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.6.0.pre.244 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.6.0.pre.240 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.6.0.pre.239 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.6.0.pre.238 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.6.0.pre.233 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb
ruby_rabbitmq_janus-2.6.0.pre.229 spec/ruby_rabbitmq_janus/models/janus_instance_spec.rb