diff --git a/app/models/miq_report/import_export.rb b/app/models/miq_report/import_export.rb index 69774ae6b45..35c1218cd27 100644 --- a/app/models/miq_report/import_export.rb +++ b/app/models/miq_report/import_export.rb @@ -11,8 +11,8 @@ def import_from_hash(report, options = nil) raise _("Incorrect format, only policy records can be imported.") end - # Ensure that all columns serialized as hashes in the report have keys that are symbols - self.column_names.each { |k| report[k].deep_symbolize_keys! if report[k].kind_of?(Hash) } + report[:db_options] ||= report["db_options"] + report[:db_options].deep_symbolize_keys! if report[:db_options] user = options[:user] || User.find_by_userid(options[:userid]) report.merge!("miq_group_id" => user.current_group_id, "user_id" => user.id) diff --git a/spec/models/miq_report/import_export_spec.rb b/spec/models/miq_report/import_export_spec.rb index 41656d8d4f8..320807039ba 100644 --- a/spec/models/miq_report/import_export_spec.rb +++ b/spec/models/miq_report/import_export_spec.rb @@ -7,7 +7,8 @@ :tz => "Eastern Time (US & Canada)", :col_order => ["name", "boot_time", "disks_aligned"], :cols => ["name", "boot_time", "disks_aligned"], - :db_options => {:rpt_type => "ChargebackContainerProject"} + :db_options => {:rpt_type => "ChargebackContainerProject"}, + "include" => {"columns" => %w(col1 col2)} ) end @@ -40,14 +41,22 @@ expect(result[:status]).to eq(:add) expect(MiqReport.count).to eq(1) end + end - it "imports from json and preserves symbolized keys in serialized columns" do + context "keys symbolizing" do + let(:report) do @options[:save] = true MiqReport.import_from_hash(@from_json, @options) + MiqReport.last + end - report = MiqReport.last + it "imports from json and preserves symbolized keys in `db_options` section " do expect(report.db_options[:rpt_type]).to_not be_nil end + + it "keeps string keys in 'include:' section" do + expect(report["include"]["columns"]).to_not be_nil + end end context "existing report" do