Skip to content

Commit

Permalink
fixes #10922 - fix enabled product listing
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsherrill committed Jul 3, 2015
1 parent e39df4a commit c028111
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/katello/product.rb
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/models/katello_products.yml
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions test/models/product_test.rb
Expand Up @@ -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?
Expand Down

0 comments on commit c028111

Please sign in to comment.