Skip to content

Commit

Permalink
Fixes #36667 - Hammer should fail non-existent LCE in host update
Browse files Browse the repository at this point in the history
(cherry picked from commit 05b73f7)
  • Loading branch information
lfu authored and wbclark committed Sep 6, 2023
1 parent 47fac47 commit 9740780
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ def set_up_content_view_environment
return unless @host&.content_facet.present? && params[:host]&.[](:content_facet_attributes)&.present?
cv_id = params[:host][:content_facet_attributes].delete(:content_view_id)
env_id = params[:host][:content_facet_attributes].delete(:lifecycle_environment_id)
Rails.logger.info "set_up_content_view_environment: cv_id=#{cv_id}, env_id=#{env_id}"
if (cv_id.present? && env_id.present?)
@host.content_facet.assign_single_environment(
lifecycle_environment_id: env_id,
content_view_id: cv_id
)
Rails.logger.info "set_up_content_view_environment: done"
end
Rails.logger.info "#{__method__}: cv_id=#{cv_id}, env_id=#{env_id}"
@host.content_facet.assign_single_environment(
lifecycle_environment_id: env_id,
content_view_id: cv_id
)
Rails.logger.info "#{__method__}: done"
end
end
end
Expand Down
38 changes: 38 additions & 0 deletions test/controllers/api/v2/hosts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,44 @@ def test_content_facet_attributes_assigned_as_cve
assert_equal target_cve, host.content_facet.content_view_environments.first
end

def test_host_update_with_env_only
host = FactoryBot.create(:host, :with_content, :with_subscription,
:content_view => @content_view, :lifecycle_environment => @environment)
put :update, params: {
:id => host.id,
:content_facet_attributes => {
:lifecycle_environment_id => @dev.id
}
}, session: set_session_user
assert_response :error
end

def test_host_update_with_cv_only
host = FactoryBot.create(:host, :with_content, :with_subscription,
:content_view => @content_view, :lifecycle_environment => @environment)
put :update, params: {
:id => host.id,
:content_facet_attributes => {
:content_view_id => @cv2.id
}
}, session: set_session_user
assert_response :error
end

def test_host_update_with_invalid_env
host = FactoryBot.create(:host, :with_content, :with_subscription,
:content_view => @content_view, :lifecycle_environment => @environment)
@dev.destroy
put :update, params: {
:id => host.id,
:content_facet_attributes => {
:content_view_id => @cv2.id,
:lifecycle_environment_id => @dev.id
}
}, session: set_session_user
assert_response :error
end

def test_with_subscriptions
host = FactoryBot.create(:host, :with_subscription)
host_index_and_show(host)
Expand Down

0 comments on commit 9740780

Please sign in to comment.