Skip to content

Commit

Permalink
Merge pull request #1067 from BigG1947/fix-bags-with-apply-uniques-co…
Browse files Browse the repository at this point in the history
…lumns

Fix bugs with apply uniques columns
  • Loading branch information
Fivell authored Nov 24, 2021
2 parents e5fc6ed + 3b6d01e commit a43e56f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/assets/javascripts/import_apply_unique_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ $(document).ready(function () {
// fix inputs
form.find('select')
.attr('name', 'changes[unique_columns][]')
.attr('id', 'changes_unique_columns')
.attr('multiple', 'multiple')
.chosen({ width: '100%' });

// add select all button
let select_all_column = $('<a></a>').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');
});
});
});
2 changes: 1 addition & 1 deletion app/models/importing/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions spec/features/routing/dialpeers/create_import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a43e56f

Please sign in to comment.