From 1b9595e06fb7e43898f587049c2dfd07f6a1a4ca Mon Sep 17 00:00:00 2001 From: Artem Lutsenko Date: Tue, 23 Nov 2021 17:49:29 +0200 Subject: [PATCH 1/2] fix bug with null value comparison in unique column --- .../javascripts/import_apply_unique_fields.js | 1 + app/models/importing/base.rb | 2 +- .../routing/dialpeers/create_import_spec.rb | 57 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/import_apply_unique_fields.js b/app/assets/javascripts/import_apply_unique_fields.js index 49e7b4461..e45b68618 100644 --- a/app/assets/javascripts/import_apply_unique_fields.js +++ b/app/assets/javascripts/import_apply_unique_fields.js @@ -8,6 +8,7 @@ $(document).ready(function () { // fix inputs form.find('select') .attr('name', 'changes[unique_columns][]') + .attr('id', 'changes_unique_columns') .attr('multiple', 'multiple') .chosen({ width: '100%' }); }); diff --git a/app/models/importing/base.rb b/app/models/importing/base.rb index c6870809b..3f10e5612 100644 --- a/app/models/importing/base.rb +++ b/app/models/importing/base.rb @@ -139,7 +139,7 @@ def self.update_relations_for_each!(relation_table_name, field, unique_columns = if unique_columns.any? condition_array = [] unique_columns.each do |column_name| - condition_array << "ta.#{column_name} = tb.#{column_name}" + condition_array << "ta.#{column_name} IS NOT DISTINCT FROM tb.#{column_name}" end condition = condition_array.join(' AND ') else diff --git a/spec/features/routing/dialpeers/create_import_spec.rb b/spec/features/routing/dialpeers/create_import_spec.rb index 4df8c0267..7f41cf270 100644 --- a/spec/features/routing/dialpeers/create_import_spec.rb +++ b/spec/features/routing/dialpeers/create_import_spec.rb @@ -45,4 +45,61 @@ expect(page).to have_table_row(count: 1) end end + + context 'apply unique columns', js: true do + let!(:gateway_group) { create(:gateway_group, vendor: contractor) } + let!(:dialpeer_1) { create(:dialpeer, dialpeer_1_attrs) } + let(:dialpeer_1_attrs) do + { + prefix: '1', + gateway: gateway, + gateway_group: nil, + + src_rewrite_rule: '4587', + dst_rewrite_rule: '789', + routing_group: routing_group, + src_rewrite_result: '1145', + dst_rewrite_result: '86554', + vendor: contractor + } + end + let!(:dialpeer_2) { create(:dialpeer, dialpeer_2_attrs) } + let(:dialpeer_2_attrs) do + { + prefix: '123', + gateway: nil, + gateway_group: gateway_group, + + src_rewrite_rule: '4587', + dst_rewrite_rule: '789', + routing_group: routing_group, + src_rewrite_result: '1145', + dst_rewrite_result: '86554', + vendor: contractor + } + end + let!(:import_1) { create(:importing_dialpeer, o_id: nil, prefix: 1, gateway_id: gateway.id, gateway_group: nil) } + let!(:import_2) { create(:importing_dialpeer, o_id: nil, prefix: 123, gateway_id: nil, gateway_group_id: gateway_group.id) } + let!(:import_3) { create(:importing_dialpeer, o_id: nil, prefix: 123, gateway_id: 2, gateway_group: nil) } + let!(:import_4) { create(:importing_dialpeer, o_id: nil, prefix: 123, gateway_id: 3, gateway_group: nil) } + + subject do + super() + page.find('#collection_selection_toggle_all').set(true) + click_on 'Apply unique columns' + fill_in_chosen 'changes[unique_columns][]', with: :prefix, multiple: true, ajax: false + fill_in_chosen 'changes[unique_columns][]', with: :gateway_id, multiple: true, ajax: false + fill_in_chosen 'changes[unique_columns][]', with: :gateway_group_id, multiple: true, ajax: false + click_on 'OK' + end + + it 'should fill correct o_id for imported data' do + expect { subject }.to change { + import_1.reload.o_id + }.to(dialpeer_1.id) + .and change { + import_2.reload.o_id + }.to(dialpeer_2.id) + end + end end From 3b6d01e0b11f4c8c04fbcd6bd1a1593baec95a07 Mon Sep 17 00:00:00 2001 From: Artem Lutsenko Date: Tue, 23 Nov 2021 17:50:13 +0200 Subject: [PATCH 2/2] add 'select all' link to apply unique columns form --- app/assets/javascripts/import_apply_unique_fields.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/assets/javascripts/import_apply_unique_fields.js b/app/assets/javascripts/import_apply_unique_fields.js index e45b68618..bfc4ff337 100644 --- a/app/assets/javascripts/import_apply_unique_fields.js +++ b/app/assets/javascripts/import_apply_unique_fields.js @@ -11,5 +11,12 @@ $(document).ready(function () { .attr('id', 'changes_unique_columns') .attr('multiple', 'multiple') .chosen({ width: '100%' }); + + // add select all button + let select_all_column = $('').text('Select All').attr('id', 'select-all-unique-columns').attr('href', '#'); + form.append(select_all_column); + select_all_column.click(function () { + form.find('select option').prop('selected', true).trigger('chosen:updated'); + }); }); });