From d885de6f5d04b94898f884261b23f305da1098d5 Mon Sep 17 00:00:00 2001 From: LSchroeder Date: Mon, 15 Jul 2019 18:15:30 +0200 Subject: [PATCH] generate friendly_name "on the fly" and add tests Co-authored-by: Thomas Hutterer --- app/models/product.rb | 4 ++++ ...190717114051_remove_friendly_name_from_products.rb | 5 +++++ db/schema.rb | 3 +-- spec/factories/products.rb | 1 - spec/models/product_spec.rb | 11 +++++++++++ spec/serializers/v3/product_serializer_spec.rb | 9 +++++++++ 6 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20190717114051_remove_friendly_name_from_products.rb diff --git a/app/models/product.rb b/app/models/product.rb index b001e46ca..e01673dc7 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -95,6 +95,10 @@ def product_string [identifier, version, arch].join('/') end + def friendly_name + [name, friendly_version, release_type, (arch if arch != 'unknown')].compact.join(' ') + end + def change_repositories_mirroring!(conditions, mirroring_enabled) repos = repositories.where(conditions) repo_names = repos.pluck(:name) diff --git a/db/migrate/20190717114051_remove_friendly_name_from_products.rb b/db/migrate/20190717114051_remove_friendly_name_from_products.rb new file mode 100644 index 000000000..7292a63ab --- /dev/null +++ b/db/migrate/20190717114051_remove_friendly_name_from_products.rb @@ -0,0 +1,5 @@ +class RemoveFriendlyNameFromProducts < ActiveRecord::Migration[5.1] + def change + remove_column :products, :friendly_name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index a4c02d761..c4c2c9b35 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190320120959) do +ActiveRecord::Schema.define(version: 20190717114051) do create_table "activations", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.bigint "service_id", null: false @@ -56,7 +56,6 @@ create_table "products", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.string "name" t.text "description" - t.string "friendly_name" t.string "shortname" t.string "former_identifier" t.string "product_type" diff --git a/spec/factories/products.rb b/spec/factories/products.rb index 41f0edc55..8588c2d8b 100644 --- a/spec/factories/products.rb +++ b/spec/factories/products.rb @@ -4,7 +4,6 @@ sequence(:identifier) { |n| "product-#{n}" } sequence(:cpe) { |n| "cpe:/o:product:#{n}" } sequence(:shortname) { |n| "Product #{n}" } - sequence(:friendly_name) { |n| "Product #{n}" } sequence(:product_class) { |n| n.to_s.ljust(5, 'A') } free false product_type :base diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb index bbddc4667..2f4efd87d 100644 --- a/spec/models/product_spec.rb +++ b/spec/models/product_spec.rb @@ -128,6 +128,17 @@ end end + describe '#friendly_name' do + subject { create(:product, product_attrs).friendly_name } + + let(:product_attrs) { { name: 'Dummy Product', friendly_version: '99', release_type: 'Bar', arch: 'x86_64', release_stage: 'bazinga!' } } + + it { + is_expected.to eq 'Dummy Product 99 Bar x86_64' + is_expected.not_to include 'bazinga!' + } + end + describe '.modules_for_migration' do subject { described_class.modules_for_migration([root_product]) } diff --git a/spec/serializers/v3/product_serializer_spec.rb b/spec/serializers/v3/product_serializer_spec.rb index 09a7a602e..e72411711 100644 --- a/spec/serializers/v3/product_serializer_spec.rb +++ b/spec/serializers/v3/product_serializer_spec.rb @@ -35,6 +35,15 @@ end end + describe '#friendly_name' do + subject { described_class.new(product).as_json[:friendly_name] } + + let(:release_stage) { 'foo' } + let(:product) { create :product, release_stage: release_stage } + + it { is_expected.not_to include(release_stage) } + end + describe 'SLES extension tree' do subject(:serializer) { described_class.new(sles15, root_product: sles15, base_url: base_url) }