Skip to content

Commit

Permalink
Merge pull request #16143 from yrudman/simbolize-only-db-options-sect…
Browse files Browse the repository at this point in the history
…ion-when-importing-report

When importing report symbolize keys only in 'db_options:' section
  • Loading branch information
gtanzillo authored Oct 11, 2017
2 parents 7e4db98 + 64250ff commit ce2d0a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/models/miq_report/import_export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,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)
Expand Down
15 changes: 12 additions & 3 deletions spec/models/miq_report/import_export_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ce2d0a4

Please sign in to comment.