From 6878a3a9dfbb00e5929cad2f946c09fff1221749 Mon Sep 17 00:00:00 2001 From: Gregg Tanzillo Date: Wed, 30 May 2018 15:05:47 -0400 Subject: [PATCH] Merge pull request #17465 from lgalis/add_option_to_clear_classifications Add option to clear classifications for tag_details (cherry picked from commit e5adfd2804f8e387e302e172c439fb4e610afeb3) https://bugzilla.redhat.com/show_bug.cgi?id=1591495 --- lib/miq_expression.rb | 3 +++ spec/lib/miq_expression_spec.rb | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/miq_expression.rb b/lib/miq_expression.rb index f35d5149bec..526393ac2fd 100644 --- a/lib/miq_expression.rb +++ b/lib/miq_expression.rb @@ -899,6 +899,9 @@ def self._model_details(relats, opts) def self.tag_details(path, opts) result = [] + if opts[:no_cache] + @classifications = nil + end @classifications ||= categories @classifications.each do |name, cat| prefix = path.nil? ? "managed" : [path, "managed"].join(".") diff --git a/spec/lib/miq_expression_spec.rb b/spec/lib/miq_expression_spec.rb index b1b07fff7d3..85f3ce6cb46 100644 --- a/spec/lib/miq_expression_spec.rb +++ b/spec/lib/miq_expression_spec.rb @@ -3356,6 +3356,23 @@ actual = described_class.tag_details(nil, {}) expect(actual).to eq([["My Company Tags : Environment", "managed-env"]]) end + + it "returns the added classification when no_cache option is used" do + Tenant.seed + FactoryGirl.create(:classification, + :name => "first_classification", + :description => "First Classification", + :children => [FactoryGirl.create(:classification)]) + actual = described_class.tag_details(nil, {}) + expect(actual).to eq([["My Company Tags : First Classification", "managed-first_classification"]]) + + FactoryGirl.create(:classification, + :name => "second_classification", + :description => "Second Classification", + :children => [FactoryGirl.create(:classification)]) + actual = described_class.tag_details(nil, :no_cache => true) + expect(actual).to eq([["My Company Tags : First Classification", "managed-first_classification"], ["My Company Tags : Second Classification", "managed-second_classification"]]) + end end describe "miq_adv_search_lists" do