Skip to content

Commit

Permalink
define PersistentVolumeClaim#persistent_volume as a relation
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Jun 21, 2023
1 parent 06e1c93 commit df5e3a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 2 additions & 4 deletions app/models/persistent_volume_claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ class PersistentVolumeClaim < ApplicationRecord
belongs_to :ext_management_system, :foreign_key => "ems_id"
belongs_to :container_project
has_many :container_volumes
has_one :persistent_volume, -> { where(:type => 'PersistentVolume')}, :class_name => "ContainerVolume"

serialize :capacity, Hash
serialize :requests, Hash
serialize :limits, Hash

virtual_column :storage_capacity, :type => :integer

def persistent_volume
container_volumes.find_by_type('PersistentVolume')
end

def storage_capacity
capacity[:storage]
end
Expand Down
15 changes: 15 additions & 0 deletions spec/models/persistent_volume_claim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,19 @@
expect(persistent_volume.storage_capacity).to be nil
end
end

describe "#persistent_volume" do
it "finds none" do
pvc = FactoryBot.create(:persistent_volume_claim)
FactoryBot.create(:container_volume, :persistent_volume_claim => pvc)
expect(pvc.persistent_volume).to be_nil
end

it "finds one" do
pvc = FactoryBot.create(:persistent_volume_claim)
FactoryBot.create(:container_volume, :persistent_volume_claim => pvc)
pv = FactoryBot.create(:persistent_volume, :persistent_volume_claim => pvc)
expect(pvc.persistent_volume).to eq(pv)
end
end
end

0 comments on commit df5e3a2

Please sign in to comment.