Skip to content

Commit

Permalink
Refs #37137 - fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Feb 28, 2024
1 parent 8982ebc commit 1f8225e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/models/katello/concerns/host_managed_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,20 +342,20 @@ def import_module_streams(module_streams)
context: module_stream["context"]
}
end
AvailableModuleStream.insert_all(
streams,
unique_by: %w[name stream context],
returning: %w[id name stream context]
)

if streams.any?
AvailableModuleStream.insert_all(
streams,
unique_by: %w[name stream context],
returning: %w[id name stream context]
)
end
indexed_module_streams = module_streams.index_by do |module_stream|
available_module_stream_id_from(
name: module_stream["name"],
stream: module_stream["stream"],
context: module_stream["context"]
)
end

sync_available_module_stream_associations(indexed_module_streams)
end

Expand Down
5 changes: 5 additions & 0 deletions test/models/concerns/host_managed_extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ def test_import_modules_with_active_field
assert_equal 2, @foreman_host.host_available_module_streams.unknown.count
end

def clear_cached_available_module_streams
@foreman_host.instance_variable_set(:@indexed_available_module_streams, nil)
end

def test_import_modules_with_update
modules_json = [make_module_json("enabled21111", "enabled")]
prior_count = HostAvailableModuleStream.count
Expand All @@ -384,6 +388,7 @@ def test_import_modules_with_update
assert_empty @foreman_host.reload.host_available_module_streams
assert_equal prior_count, HostAvailableModuleStream.count

clear_cached_available_module_streams
@foreman_host.import_module_streams([make_module_json("xxxx", "enabled", 'blah', ["default"])])
assert_equal "enabled", @foreman_host.reload.host_available_module_streams.first.status
assert_equal ["default"], @foreman_host.reload.host_available_module_streams.first.installed_profiles
Expand Down

0 comments on commit 1f8225e

Please sign in to comment.