Fixes #3514 - csv import example file download (organizations) is empty.

This commit is contained in:
Rolf Schmidt 2021-08-18 14:38:34 +02:00 committed by Thorsten Eckel
parent e5d9fb37dd
commit 2d6d15f9be
6 changed files with 32 additions and 17 deletions

View file

@ -176,7 +176,7 @@ returns
=end
def attributes_with_association_names
def attributes_with_association_names(empty_keys: false)
# get relations
attributes = attributes_with_association_ids
@ -185,6 +185,9 @@ returns
next if association_attributes_ignored.include?(assoc.name)
ref = send(assoc.name)
if empty_keys
attributes[assoc.name.to_s] = nil
end
next if !ref
if ref.respond_to?(:first)

View file

@ -246,7 +246,8 @@ returns
records.each do |record|
record_attributes_with_association_names = 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
new.attributes_with_association_names(empty_keys: true).each do |key, value|
next if value.instance_of?(ActiveSupport::HashWithIndifferentAccess)
next if value.instance_of?(Hash)
next if csv_attributes_ignored&.include?(key.to_sym)
@ -260,7 +261,6 @@ returns
header.push key
end
end
rows = []
records_attributes_with_association_names.each do |record|

View file

@ -27,7 +27,7 @@ class KnowledgeBase::Answer::Translation::Content < ApplicationModel
add_attachments_to_attributes(attrs)
end
def attributes_with_association_names
def attributes_with_association_names(empty_keys: false)
attrs = super
add_attachments_to_attributes(attrs)
end

View file

@ -44,7 +44,7 @@ class Taskbar < ApplicationModel
false
end
def attributes_with_association_names
def attributes_with_association_names(empty_keys: false)
add_attachments_to_attributes(super)
end

View file

@ -270,7 +270,7 @@ returns
=end
def attributes_with_association_names
def attributes_with_association_names(empty_keys: false)
attributes = super
add_attachments_to_attributes(attributes)
Ticket::Article.insert_urls(attributes)

View file

@ -1,6 +1,18 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
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
let!(:params) { { string: <<~CSV, parse_params: { col_sep: ',' } } }
#{described_class.attribute_names.join(',')}