Skip to content

Commit

Permalink
Fix ram_size_in_bytes for hardware#memory_mb = nil
Browse files Browse the repository at this point in the history
Fixes bug introduced in ManageIQ#12938
  • Loading branch information
kbrock committed Dec 12, 2016
1 parent fadf640 commit 5273a4e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/hardware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def mac_addresses
end

def ram_size_in_bytes
memory_mb * 1.megabyte
memory_mb.to_i * 1.megabyte
end

@@dh = {"type" => "device_name", "devicetype" => "device_type", "id" => "location", "present" => "present",
Expand Down
20 changes: 20 additions & 0 deletions spec/models/hardware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,24 @@
end
end
end

describe ".ram_size_in_bytes" do
it "handles nil" do
hardware = FactoryGirl.build(:hardware)

expect(hardware.ram_size_in_bytes).to eq(0)
end

it "works in ruby" do
hardware = FactoryGirl.build(:hardware, :memory_mb => 5)

expect(hardware.ram_size_in_bytes).to eq(5.megabytes)
end

it "works in sql" do
hardware = FactoryGirl.create(:hardware, :memory_mb => 5)

expect(virtual_column_sql_value(Hardware, "ram_size_in_bytes")).to eq(5.megabytes)
end
end
end

0 comments on commit 5273a4e

Please sign in to comment.