From a42531ce4638fbfdd07d4880de2bfe75a403bf4b Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Wed, 20 Dec 2017 16:34:52 +0100 Subject: [PATCH] Removed obsolete import structures which were used for the LDAP import which was migrated to the Sequencer. --- lib/import/model_resource.rb | 30 --- lib/import/statistical_factory.rb | 38 --- spec/lib/import/model_resource_spec.rb | 48 ---- spec/lib/import/statistical_factory_spec.rb | 264 -------------------- 4 files changed, 380 deletions(-) delete mode 100644 lib/import/model_resource.rb delete mode 100644 lib/import/statistical_factory.rb delete mode 100644 spec/lib/import/model_resource_spec.rb delete mode 100644 spec/lib/import/statistical_factory_spec.rb diff --git a/lib/import/model_resource.rb b/lib/import/model_resource.rb deleted file mode 100644 index 0f35aad00..000000000 --- a/lib/import/model_resource.rb +++ /dev/null @@ -1,30 +0,0 @@ -module Import - class ModelResource < Import::BaseResource - - def import_class - self.class.import_class - end - - def model_name - self.class.model_name - end - - def self.import_class - model_name.constantize - end - - def self.model_name - @model_name ||= name.split('::').last - end - - private - - def create(resource, *_args) - result = super - if !@dry_run - reset_primary_key_sequence(model_name.underscore.pluralize) - end - result - end - end -end diff --git a/lib/import/statistical_factory.rb b/lib/import/statistical_factory.rb deleted file mode 100644 index 695c78d4e..000000000 --- a/lib/import/statistical_factory.rb +++ /dev/null @@ -1,38 +0,0 @@ -module Import - module StatisticalFactory - include Import::Factory - - # rubocop:disable Style/ModuleFunction - extend self - - attr_reader :statistics - - def import(records, *args) - super - end - - def reset_statistics - @statistics = { - skipped: 0, - created: 0, - updated: 0, - unchanged: 0, - failed: 0, - deactivated: 0, - } - end - - def pre_import_hook(_records, *_args) - reset_statistics if @statistics.blank? - end - - def post_import_hook(_record, backend_instance, *_args) - add_to_statistics(backend_instance) - end - - def add_to_statistics(backend_instance) - action = backend_instance.action - @statistics[action] += 1 - end - end -end diff --git a/spec/lib/import/model_resource_spec.rb b/spec/lib/import/model_resource_spec.rb deleted file mode 100644 index 58b6be07f..000000000 --- a/spec/lib/import/model_resource_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'rails_helper' - -RSpec.describe Import::ModelResource do - - before do - module Import - class Test < Import::Base - class Group < Import::ModelResource - def source - 'RSpec-Test' - end - end - end - end - end - - after do - Import::Test.send(:remove_const, :Group) - end - - let(:group_data) { attributes_for(:group).merge(id: 1337) } - - it 'creates model Objects by class name' do - expect do - Import::Test::Group.new(group_data) - end.to change { Group.count }.by(1) - end - - it 'updates model Objects by class name' do - - expect do - Import::Test::Group.new(group_data) - end - .to change { - Group.count - }.by(1) - - expect do - Import::Test::Group.new(group_data.merge(note: 'Updated')) - end - .to change { - Group.count - }.by(0) - .and change { - Group.last.note - } - end -end diff --git a/spec/lib/import/statistical_factory_spec.rb b/spec/lib/import/statistical_factory_spec.rb deleted file mode 100644 index da72a7a51..000000000 --- a/spec/lib/import/statistical_factory_spec.rb +++ /dev/null @@ -1,264 +0,0 @@ -require 'rails_helper' -require 'lib/import/factory_examples' - -RSpec.describe Import::StatisticalFactory do - it_behaves_like 'Import::Factory' - - before do - module Import - class Test < Import::Base - - module GroupFactory - extend Import::StatisticalFactory - end - - class Group < Import::ModelResource - def source - 'RSpec-Test' - end - end - end - end - end - - after do - Import::Test.send(:remove_const, :GroupFactory) - Import::Test.send(:remove_const, :Group) - end - - before(:each) do - Import::Test::GroupFactory.reset_statistics - end - - let(:attributes) do - attributes = attributes_for(:group) - attributes[:id] = 1337 - attributes - end - - context 'statistics' do - - context 'live run' do - - it 'tracks created instances' do - - Import::Test::GroupFactory.import([attributes]) - - statistics = { - created: 1, - updated: 0, - unchanged: 0, - skipped: 0, - failed: 0, - deactivated: 0, - } - expect(Import::Test::GroupFactory.statistics).to eq(statistics) - end - - context 'updated instances' do - it 'tracks by regular attributes' do - - Import::Test::GroupFactory.import([attributes]) - - # simulate next import run - travel 20.minutes - Import::Test::GroupFactory.reset_statistics - - attributes[:note] = 'TEST' - Import::Test::GroupFactory.import([attributes]) - - statistics = { - created: 0, - updated: 1, - unchanged: 0, - skipped: 0, - failed: 0, - deactivated: 0, - } - expect(Import::Test::GroupFactory.statistics).to eq(statistics) - end - - it 'tracks by has_many association attributes' do - - Import::Test::GroupFactory.import([attributes]) - - # simulate next import run - travel 20.minutes - Import::Test::GroupFactory.reset_statistics - - new_users = create_list(:user, 2) - attributes[:user_ids] = new_users.collect(&:id) - - Import::Test::GroupFactory.import([attributes]) - - statistics = { - created: 0, - updated: 1, - unchanged: 0, - skipped: 0, - failed: 0, - deactivated: 0, - } - expect(Import::Test::GroupFactory.statistics).to eq(statistics) - end - - it 'tracks by belongs_to association attributes' do - - Import::Test::GroupFactory.import([attributes]) - - # simulate next import run - travel 20.minutes - Import::Test::GroupFactory.reset_statistics - - new_signature = create(:signature) - attributes[:signature_id] = new_signature.id - - Import::Test::GroupFactory.import([attributes]) - - statistics = { - created: 0, - updated: 1, - unchanged: 0, - skipped: 0, - failed: 0, - deactivated: 0, - } - expect(Import::Test::GroupFactory.statistics).to eq(statistics) - end - end - - it 'tracks unchanged instances' do - - Import::Test::GroupFactory.import([attributes]) - - # simulate next import run - travel 20.minutes - Import::Test::GroupFactory.reset_statistics - - Import::Test::GroupFactory.import([attributes]) - - statistics = { - created: 0, - updated: 0, - unchanged: 1, - skipped: 0, - failed: 0, - deactivated: 0, - } - expect(Import::Test::GroupFactory.statistics).to eq(statistics) - end - end - - context 'dry run' do - - it 'tracks created instances' do - - Import::Test::GroupFactory.import([attributes], dry_run: true) - - statistics = { - created: 1, - updated: 0, - unchanged: 0, - skipped: 0, - failed: 0, - deactivated: 0, - } - expect(Import::Test::GroupFactory.statistics).to eq(statistics) - end - - context 'updated instances' do - - let(:local_group) { create(:group) } - - before(:each) do - ExternalSync.create( - source: 'RSpec-Test', - source_id: local_group.id, - object: 'Group', - o_id: local_group.id - ) - end - - it 'tracks by regular attributes' do - - update_attributes = local_group.attributes - update_attributes[:note] = 'TEST' - - Import::Test::GroupFactory.import([update_attributes], dry_run: true) - - statistics = { - created: 0, - updated: 1, - unchanged: 0, - skipped: 0, - failed: 0, - deactivated: 0, - } - expect(Import::Test::GroupFactory.statistics).to eq(statistics) - end - - it 'tracks by has_many association attributes' do - - update_attributes = local_group.attributes - new_users = create_list(:user, 2) - update_attributes[:user_ids] = new_users.collect(&:id) - - Import::Test::GroupFactory.import([update_attributes], dry_run: true) - - statistics = { - created: 0, - updated: 1, - unchanged: 0, - skipped: 0, - failed: 0, - deactivated: 0, - } - expect(Import::Test::GroupFactory.statistics).to eq(statistics) - end - - it 'tracks by belongs_to association attributes' do - - update_attributes = local_group.attributes - new_signature = create(:signature) - update_attributes[:signature_id] = new_signature.id - - Import::Test::GroupFactory.import([update_attributes], dry_run: true) - - statistics = { - created: 0, - updated: 1, - unchanged: 0, - skipped: 0, - failed: 0, - deactivated: 0, - } - expect(Import::Test::GroupFactory.statistics).to eq(statistics) - end - end - - it 'tracks unchanged instances' do - - local_group = create(:group) - - ExternalSync.create( - source: 'RSpec-Test', - source_id: local_group.id, - object: 'Group', - o_id: local_group.id - ) - - Import::Test::GroupFactory.import([local_group.attributes], dry_run: true) - - statistics = { - created: 0, - updated: 0, - unchanged: 1, - skipped: 0, - failed: 0, - deactivated: 0, - } - expect(Import::Test::GroupFactory.statistics).to eq(statistics) - end - end - end -end