<commit_before>require "spec_helper"
require_migration

describe SetCorrectStiTypeOnOpenstackInfraMiqTemplate do
  let(:ext_management_system_stub) { migration_stub(:ExtManagementSystem) }
  let(:miq_template_stub) { migration_stub(:Vm) }

  EMS_ROW_ENTRIES = [
    {:id => 1, :type => "ManageIQ::Providers::Openstack::InfraManager"},
    {:id => 2, :type => "ManageIQ::Providers::Openstack::CloudManager"},
    {:id => 3, :type => "ManageIQ::Providers::AnotherManager"}
  ]

  ROW_ENTRIES = [{
                   :ems_id   => 1,
                   :name     => "template_1",
                   :type_in  => 'ManageIQ::Providers::Openstack::CloudManager::Template',
                   :type_out => 'ManageIQ::Providers::Openstack::InfraManager::Template'
                 },
                 {
                   :ems_id   => 1,
                   :name     => "template_2",
                   :type_in  => 'ManageIQ::Providers::Openstack::CloudManager::Template',
                   :type_out => 'ManageIQ::Providers::Openstack::InfraManager::Template'
                 },
                 {
                   :ems_id   => 2,
                   :name     => "template_3",
                   :type_in  => 'ManageIQ::Providers::Openstack::CloudManager::Template',
                   :type_out => 'ManageIQ::Providers::Openstack::CloudManager::Template'
                 },
                 {
                   :ems_id   => 3,
                   :name     => "template_4",
                   :type_in  => 'ManageIQ::Providers::AnyManager::Template',
                   :type_out => 'ManageIQ::Providers::AnyManager::Template'
                 },
  ]

  migration_context :up do
    it "migrates a series of representative row" do
      EMS_ROW_ENTRIES.each do |x|
        ext_management_system_stub.create!(:type => x[:type], :id => x[:id])
      end

      ROW_ENTRIES.each do |x|
        x[:miq_template] = miq_template_stub.create!(:type => x[:type_in], :ems_id => x[:ems_id], :name => x[:name])
      end

      migrate

      ROW_ENTRIES.each do |x|
        expect(x[:miq_template].reload).to have_attributes(
                                      :type   => x[:type_out],
                                      :name   => x[:name],
                                      :ems_id => x[:ems_id]
                                    )
      end
    end
  end

  migration_context :down do
    it "migrates a series of representative row" do
      EMS_ROW_ENTRIES.each do |x|
        ext_management_system_stub.create!(:type => x[:type], :id => x[:id])
      end

      ROW_ENTRIES.each do |x|
        x[:miq_template] = miq_template_stub.create!(:type => x[:type_out], :ems_id => x[:ems_id], :name => x[:name])
      end

      migrate

      ROW_ENTRIES.each do |x|
        expect(x[:miq_template].reload).to have_attributes(
                                             :type   => x[:type_in],
                                             :name   => x[:name],
                                             :ems_id => x[:ems_id]
        )
      end
    end
  end
end
<commit_msg>Refactoring of migrations tests for miq_template STI class<commit_after>require "spec_helper"
require_migration

describe SetCorrectStiTypeOnOpenstackInfraMiqTemplate do
  let(:ext_management_system_stub) { migration_stub(:ExtManagementSystem) }
  let(:miq_template_stub) { migration_stub(:Vm) }

  EMS_ROW_ENTRIES = [
    {:type => "ManageIQ::Providers::Openstack::InfraManager"},
    {:type => "ManageIQ::Providers::Openstack::CloudManager"},
    {:type => "ManageIQ::Providers::AnotherManager"}
  ]

  ROW_ENTRIES = [{
                   :ems      => EMS_ROW_ENTRIES[0],
                   :name     => "template_1",
                   :type_in  => 'ManageIQ::Providers::Openstack::CloudManager::Template',
                   :type_out => 'ManageIQ::Providers::Openstack::InfraManager::Template'
                 },
                 {
                   :ems      => EMS_ROW_ENTRIES[0],
                   :name     => "template_2",
                   :type_in  => 'ManageIQ::Providers::Openstack::CloudManager::Template',
                   :type_out => 'ManageIQ::Providers::Openstack::InfraManager::Template'
                 },
                 {
                   :ems      => EMS_ROW_ENTRIES[1],
                   :name     => "template_3",
                   :type_in  => 'ManageIQ::Providers::Openstack::CloudManager::Template',
                   :type_out => 'ManageIQ::Providers::Openstack::CloudManager::Template'
                 },
                 {
                   :ems      => EMS_ROW_ENTRIES[2],
                   :name     => "template_4",
                   :type_in  => 'ManageIQ::Providers::AnyManager::Template',
                   :type_out => 'ManageIQ::Providers::AnyManager::Template'
                 },
  ]

  migration_context :up do
    it "migrates a series of representative row" do
      EMS_ROW_ENTRIES.each do |x|
        x[:ems] = ext_management_system_stub.create!(:type => x[:type])
      end

      ROW_ENTRIES.each do |x|
        x[:miq_template] = miq_template_stub.create!(:type => x[:type_in], :ems_id => x[:ems][:ems].id, :name => x[:name])
      end

      migrate

      ROW_ENTRIES.each do |x|
        expect(x[:miq_template].reload).to have_attributes(
                                      :type   => x[:type_out],
                                      :name   => x[:name],
                                      :ems_id => x[:ems][:ems].id
                                    )
      end
    end
  end

  migration_context :down do
    it "migrates a series of representative row" do
      EMS_ROW_ENTRIES.each do |x|
        x[:ems] = ext_management_system_stub.create!(:type => x[:type])
      end

      ROW_ENTRIES.each do |x|
        x[:miq_template] = miq_template_stub.create!(:type => x[:type_out], :ems_id => x[:ems][:ems].id, :name => x[:name])
      end

      migrate

      ROW_ENTRIES.each do |x|
        expect(x[:miq_template].reload).to have_attributes(
                                             :type   => x[:type_in],
                                             :name   => x[:name],
                                             :ems_id => x[:ems][:ems].id
        )
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.130775379696243, 'fraction_numerical': 0.003037569944044764, 'mean_word_length': 1.6746472851646002, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4945054', 'n_tokens_mistral': 1920, 'n_tokens_neox': 1839, 'n_words': 293}