Sha256: 9cdf689c17af0b1ae3755a3fa3910e20f1d8da8f40b1ecdaa249e714005b017d

Contents?: true

Size: 1.93 KB

Versions: 32

Compression:

Stored size: 1.93 KB

Contents

RSpec.describe Mdm::Ref, type: :model do
  it_should_behave_like 'Metasploit::Concern.run'

  context 'associations' do
    # shoulda matchers don't have support for :primary_key option, so need to
    # test this association manually
    context 'module_refs' do
      context 'with Mdm::Module::Refs' do
        context 'with same name' do
          let(:name) do
            FactoryBot.generate :mdm_ref_name
          end

          let!(:module_ref) do
            FactoryBot.create(:mdm_module_ref, :name => name)
          end

          let!(:ref) do
            FactoryBot.create(:mdm_ref, :name => name)
          end

          it 'should have module_refs in assocation' do
            expect(ref.module_refs).to match_array([module_ref])
          end
        end
      end
    end

    # @todo https://www.pivotaltracker.com/story/show/48915453
    it { is_expected.to have_many(:vulns_refs).class_name('Mdm::VulnRef') }
    it { is_expected.to have_many(:vulns).class_name('Mdm::Vuln').through(:vulns_refs) }
  end

  context 'database' do
    context 'columns' do
      it { is_expected.to have_db_column(:name).of_type(:string) }
      it { is_expected.to have_db_column(:ref_id).of_type(:integer) }

      context 'timestamps' do
        it { is_expected.to have_db_column(:created_at).of_type(:datetime) }
        it { is_expected.to have_db_column(:updated_at).of_type(:datetime) }
      end
    end

    context 'indices' do
      it { is_expected.to have_db_index(:name) }
    end
  end

  context 'factories' do
    context 'mdm_ref' do
      subject(:mdm_ref) do
        FactoryBot.build :mdm_ref
      end

      it { is_expected.to be_valid }
    end
  end

  context '#destroy' do
    it 'should successfully destroy the object' do
      mdm_ref = FactoryBot.create(:mdm_ref)
      expect {
        mdm_ref.destroy
      }.to_not raise_error
      expect {
        mdm_ref.reload
      }.to raise_error(ActiveRecord::RecordNotFound)
    end
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
wg-metasploit_data_models-4.1.4.02 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-6.0.5 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-6.0.4 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-6.0.3 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-6.0.2 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-6.0.1 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-6.0.0 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-5.0.6 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-5.0.5 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-5.0.4 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-5.0.3 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-5.0.2 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-5.0.1 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-5.0.0 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-4.1.4 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-4.1.3 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-4.1.2 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-4.1.1 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-4.1.0 spec/app/models/mdm/ref_spec.rb
metasploit_data_models-4.0.2 spec/app/models/mdm/ref_spec.rb