From 556b48d812a8c4bd119c1e121e4d795badf55193 Mon Sep 17 00:00:00 2001 From: Ranjan Kumar Date: Mon, 30 Apr 2018 12:02:56 +0530 Subject: [PATCH] Fixes #23084 - activation-key copy fix --- app/controllers/katello/api/v2/activation_keys_controller.rb | 2 +- app/lib/katello/resources/candlepin/activation_key.rb | 2 +- test/controllers/api/v2/activation_keys_controller_test.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/katello/api/v2/activation_keys_controller.rb b/app/controllers/katello/api/v2/activation_keys_controller.rb index 3f1e25a9582..070a7913ecf 100644 --- a/app/controllers/katello/api/v2/activation_keys_controller.rb +++ b/app/controllers/katello/api/v2/activation_keys_controller.rb @@ -97,7 +97,7 @@ def copy @activation_key.pools.each do |pool| @new_activation_key.subscribe(pool[:id]) end - @new_activation_key.set_content_overrides(@activation_key.content_overrides) + @new_activation_key.set_content_overrides(@activation_key.content_overrides) unless @activation_key.content_overrides.blank? respond_for_show(:resource => @new_activation_key) end diff --git a/app/lib/katello/resources/candlepin/activation_key.rb b/app/lib/katello/resources/candlepin/activation_key.rb index a00d85e43ec..763a01d254d 100644 --- a/app/lib/katello/resources/candlepin/activation_key.rb +++ b/app/lib/katello/resources/candlepin/activation_key.rb @@ -88,7 +88,7 @@ def update_content_overrides(id, content_overrides) client.options[:payload] = attrs_to_delete.to_json result = client.delete({:accept => :json, :content_type => :json}.merge(User.cp_oauth_header)) end - ::Katello::Util::Data.array_with_indifferent_access(JSON.parse(result)) + ::Katello::Util::Data.array_with_indifferent_access(JSON.parse(result || '{}')) end def path(id = nil) diff --git a/test/controllers/api/v2/activation_keys_controller_test.rb b/test/controllers/api/v2/activation_keys_controller_test.rb index 87f42652bc8..1bc08ad3e5a 100644 --- a/test/controllers/api/v2/activation_keys_controller_test.rb +++ b/test/controllers/api/v2/activation_keys_controller_test.rb @@ -173,7 +173,7 @@ def test_copy assert_equal activation_key_params[:auto_attach], @activation_key.auto_attach end content_overrides = [::Katello::ContentOverride.new("foo", :enabled => 1), ::Katello::ContentOverride.new("bar", :enabled => nil)] - @activation_key.expects(:content_overrides).returns(content_overrides) + @activation_key.expects(:content_overrides).at_least_once.returns(content_overrides) ::Katello::Resources::Candlepin::ActivationKey.expects(:update_content_overrides).with do |id, hash| id.wont_equal(@activation_key.cp_id)