Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure report columns serialized as hashes have symbolized keys before importing #15273

Merged
merged 1 commit into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/miq_report/import_export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ 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) }

user = options[:user] || User.find_by_userid(options[:userid])
report.merge!("miq_group_id" => user.current_group_id, "user_id" => user.id)

Expand Down
20 changes: 15 additions & 5 deletions spec/models/miq_report/import_export_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
before do
@user = FactoryGirl.create(:user_admin)
@old_report = FactoryGirl.create(:miq_report,
:name => "Test Report",
:rpt_type => "Custom",
:tz => "Eastern Time (US & Canada)",
:col_order => ["name", "boot_time", "disks_aligned"],
:cols => ["name", "boot_time", "disks_aligned"]
:name => "Test Report",
:rpt_type => "Custom",
:tz => "Eastern Time (US & Canada)",
:col_order => ["name", "boot_time", "disks_aligned"],
:cols => ["name", "boot_time", "disks_aligned"],
:db_options => {:rpt_type => "ChargebackContainerProject"}
)
end

context ".import_from_hash" do
before do
report_string = MiqReport.export_to_yaml([@old_report.id], MiqReport)
@new_report = YAML.load(report_string).first
@from_json = JSON.parse(@new_report.to_json)
@options = {
:overwrite => true,
:user => @user
Expand All @@ -38,6 +40,14 @@
expect(result[:status]).to eq(:add)
expect(MiqReport.count).to eq(1)
end

it "imports from json and preserves symbolized keys in serialized columns" do
@options[:save] = true
MiqReport.import_from_hash(@from_json, @options)

report = MiqReport.last
expect(report.db_options[:rpt_type]).to_not be_nil
end
end

context "existing report" do
Expand Down