Removed obsolete import structures which were used for the LDAP import which was migrated to the Sequencer.
This commit is contained in:
parent
1821c97506
commit
a42531ce46
4 changed files with 0 additions and 380 deletions
|
@ -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
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -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
|
|
Loading…
Reference in a new issue