Fixes #3514 - csv import example file download (organizations) is empty.
This commit is contained in:
parent
e5d9fb37dd
commit
2d6d15f9be
6 changed files with 32 additions and 17 deletions
|
@ -176,7 +176,7 @@ returns
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def attributes_with_association_names
|
def attributes_with_association_names(empty_keys: false)
|
||||||
|
|
||||||
# get relations
|
# get relations
|
||||||
attributes = attributes_with_association_ids
|
attributes = attributes_with_association_ids
|
||||||
|
@ -185,6 +185,9 @@ returns
|
||||||
next if association_attributes_ignored.include?(assoc.name)
|
next if association_attributes_ignored.include?(assoc.name)
|
||||||
|
|
||||||
ref = send(assoc.name)
|
ref = send(assoc.name)
|
||||||
|
if empty_keys
|
||||||
|
attributes[assoc.name.to_s] = nil
|
||||||
|
end
|
||||||
next if !ref
|
next if !ref
|
||||||
|
|
||||||
if ref.respond_to?(:first)
|
if ref.respond_to?(:first)
|
||||||
|
|
|
@ -246,20 +246,20 @@ returns
|
||||||
records.each do |record|
|
records.each do |record|
|
||||||
record_attributes_with_association_names = record.attributes_with_association_names
|
record_attributes_with_association_names = record.attributes_with_association_names
|
||||||
records_attributes_with_association_names.push record_attributes_with_association_names
|
records_attributes_with_association_names.push record_attributes_with_association_names
|
||||||
record_attributes_with_association_names.each do |key, value|
|
end
|
||||||
next if value.instance_of?(ActiveSupport::HashWithIndifferentAccess)
|
new.attributes_with_association_names(empty_keys: true).each do |key, value|
|
||||||
next if value.instance_of?(Hash)
|
next if value.instance_of?(ActiveSupport::HashWithIndifferentAccess)
|
||||||
next if csv_attributes_ignored&.include?(key.to_sym)
|
next if value.instance_of?(Hash)
|
||||||
next if key.end_with?('_id')
|
next if csv_attributes_ignored&.include?(key.to_sym)
|
||||||
next if key.end_with?('_ids')
|
next if key.end_with?('_id')
|
||||||
next if key == 'created_by'
|
next if key.end_with?('_ids')
|
||||||
next if key == 'updated_by'
|
next if key == 'created_by'
|
||||||
next if key == 'created_at'
|
next if key == 'updated_by'
|
||||||
next if key == 'updated_at'
|
next if key == 'created_at'
|
||||||
next if header.include?(key)
|
next if key == 'updated_at'
|
||||||
|
next if header.include?(key)
|
||||||
|
|
||||||
header.push key
|
header.push key
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
rows = []
|
rows = []
|
||||||
|
|
|
@ -27,7 +27,7 @@ class KnowledgeBase::Answer::Translation::Content < ApplicationModel
|
||||||
add_attachments_to_attributes(attrs)
|
add_attachments_to_attributes(attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
def attributes_with_association_names
|
def attributes_with_association_names(empty_keys: false)
|
||||||
attrs = super
|
attrs = super
|
||||||
add_attachments_to_attributes(attrs)
|
add_attachments_to_attributes(attrs)
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Taskbar < ApplicationModel
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def attributes_with_association_names
|
def attributes_with_association_names(empty_keys: false)
|
||||||
add_attachments_to_attributes(super)
|
add_attachments_to_attributes(super)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -270,7 +270,7 @@ returns
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def attributes_with_association_names
|
def attributes_with_association_names(empty_keys: false)
|
||||||
attributes = super
|
attributes = super
|
||||||
add_attachments_to_attributes(attributes)
|
add_attachments_to_attributes(attributes)
|
||||||
Ticket::Article.insert_urls(attributes)
|
Ticket::Article.insert_urls(attributes)
|
||||||
|
|
|
@ -1,6 +1,18 @@
|
||||||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
RSpec.shared_examples 'CanCsvImport' do |unique_attributes: []|
|
RSpec.shared_examples 'CanCsvImport' do |unique_attributes: []|
|
||||||
|
describe '.csv_example' do
|
||||||
|
before do
|
||||||
|
described_class.destroy_all
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when no data avaiable' do
|
||||||
|
it 'still returns the header for the csv example' do
|
||||||
|
expect(described_class.csv_example).to include('id')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '.csv_import' do
|
describe '.csv_import' do
|
||||||
let!(:params) { { string: <<~CSV, parse_params: { col_sep: ',' } } }
|
let!(:params) { { string: <<~CSV, parse_params: { col_sep: ',' } } }
|
||||||
#{described_class.attribute_names.join(',')}
|
#{described_class.attribute_names.join(',')}
|
||||||
|
|
Loading…
Reference in a new issue