From c02811168b721704d64f26dcf5ffde40fe0c2212 Mon Sep 17 00:00:00 2001 From: Justin Sherrill Date: Mon, 29 Jun 2015 16:32:35 -0400 Subject: [PATCH] fixes #10922 - fix enabled product listing --- app/models/katello/product.rb | 7 ++++++- test/fixtures/models/katello_products.yml | 8 ++++++++ test/models/product_test.rb | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/models/katello/product.rb b/app/models/katello/product.rb index a98bc0c1529..f05f4005bad 100644 --- a/app/models/katello/product.rb +++ b/app/models/katello/product.rb @@ -56,7 +56,12 @@ def self.in_org(organization) scope :marketing, where(:type => "Katello::MarketingProduct") scope :syncable_content, uniq.where(Katello::Repository.arel_table[:url].not_eq(nil)) .joins(:repositories) - scope :enabled, joins(:repositories).uniq + scope :redhat, joins(:provider).where("#{Provider.table_name}.provider_type" => Provider::REDHAT) + scope :custom, joins(:provider).where("#{Provider.table_name}.provider_type" => [Provider::CUSTOM, Provider::ANONYMOUS]) + + def self.enabled + self.where("#{Product.table_name}.id in (?) or #{Product.table_name}.id in (?)", Product.redhat.joins(:repositories).uniq, Product.custom) + end before_create :assign_unique_label diff --git a/test/fixtures/models/katello_products.yml b/test/fixtures/models/katello_products.yml index f92ed4b81fb..2865ad1c04c 100644 --- a/test/fixtures/models/katello_products.yml +++ b/test/fixtures/models/katello_products.yml @@ -29,6 +29,14 @@ empty_product: provider_id: <%= ActiveRecord::Fixtures.identify(:anonymous) %> organization_id: <%= ActiveRecord::Fixtures.identify(:empty_organization) %> +empty_redhat: + name: Empty Red Hat Linux + description: A more Enterprisy but empty fedora + cp_id: redhat_empty + label: redhat_empty_label + provider_id: <%= ActiveRecord::Fixtures.identify(:redhat) %> + organization_id: <%= ActiveRecord::Fixtures.identify(:empty_organization) %> + empty_product_2: name: Empty Product_2 cp_id: empty_product_2 diff --git a/test/models/product_test.rb b/test/models/product_test.rb index bb9098a8c06..d653157d240 100644 --- a/test/models/product_test.rb +++ b/test/models/product_test.rb @@ -17,6 +17,23 @@ def teardown @product.destroy if @product end + def test_enabled + products = Product.enabled + refute_includes products, katello_products(:empty_redhat) + assert_includes products, @redhat_product + assert_includes products, katello_products(:empty_product) + end + + def test_redhat + assert_includes Product.redhat, @redhat_product + refute_includes Product.redhat, @promoted_product + end + + def test_custom + assert_includes Product.custom, @promoted_product + refute_includes Product.custom, @redhat_product + end + def test_redhat? assert @redhat_product.redhat? refute @product.redhat?