From 140d1aa1848f41496804749f18bf2f67ee6b339e Mon Sep 17 00:00:00 2001 From: nimrodshn Date: Sun, 6 Aug 2017 16:57:56 +0300 Subject: [PATCH] add number of container using image some refactoring refactored containers count minor refactoring minor refactoring refactored tests refactored tests refactored tests added file by mistake removed random file --- app/models/container_image.rb | 1 + spec/factories/containers.rb | 1 + spec/models/container_image/container_image_spec.rb | 13 +++++++++++++ 3 files changed, 15 insertions(+) create mode 100644 spec/models/container_image/container_image_spec.rb diff --git a/app/models/container_image.rb b/app/models/container_image.rb index c288927b158..8632d44eadf 100644 --- a/app/models/container_image.rb +++ b/app/models/container_image.rb @@ -31,6 +31,7 @@ class ContainerImage < ApplicationRecord acts_as_miq_taggable virtual_column :display_registry, :type => :string + virtual_total :total_containers, :containers after_create :raise_creation_event diff --git a/spec/factories/containers.rb b/spec/factories/containers.rb index f51d65bf2fb..1efcc99a419 100644 --- a/spec/factories/containers.rb +++ b/spec/factories/containers.rb @@ -1,5 +1,6 @@ FactoryGirl.define do factory :container do + sequence(:name) { |n| "container_#{seq_padded_for_sorting(n)}" } end factory :kubernetes_container, diff --git a/spec/models/container_image/container_image_spec.rb b/spec/models/container_image/container_image_spec.rb new file mode 100644 index 00000000000..6fc7a45a3b1 --- /dev/null +++ b/spec/models/container_image/container_image_spec.rb @@ -0,0 +1,13 @@ +describe ContainerImage do + it "counts containers" do + group = FactoryGirl.create( + :container_group, + :name => "group", + :container_node => FactoryGirl.create(:container_node, :name => "node") + ) + expect(FactoryGirl.create( + :container_image, + :containers => FactoryGirl.create_list(:container, 2, :container_group => group) + ).total_containers).to eq(2) + end +end