lzap
September 30, 2019, 12:49pm
#1
Help.
I want smart proxy features to also have some capabilities by default. So I modified:
+++ b/test/factories/smart_proxy.rb
@@ -27,7 +27,7 @@ FactoryBot.define do
factory :dhcp_smart_proxy do
after(:build) do |smart_proxy, _evaluator|
- smart_proxy.smart_proxy_features << FactoryBot.build(:smart_proxy_feature, :dhcp, :smart_proxy => smart_proxy)
+ smart_proxy.smart_proxy_features << FactoryBot.build(:smart_proxy_feature, :dhcp, :smart_proxy => smart_proxy, :capabilities => ["dhcp_filename_ipv4"])
end
end
It looked like pretty straightforward change, however it does not work. I can’t find the culprit. In the dhcp_test.rb
it does not work:
FactoryBot.build(:subnet_ipv4, :dhcp).dhcp.capabilities("DHCP")
[]
I am not getting this, Subnet (subnet_ipv4
) factory should pick association :dhcp, :factory => :dhcp_smart_proxy
association and I have added the new attribute there, yet I don’t see it.
ekohl
September 30, 2019, 1:14pm
#2
I ran into this as well. I worked around it in an ugly way:
I think in Katello the following is used which might be cleaner:
trait :with_pulp3 do
after(:create) do |proxy, _evaluator|
plugins = Katello::RepositoryTypeManager.repository_types.values.map(&:pulp3_plugin).compact
v3_feature = Feature.find_or_create_by(:name => 'Pulp3')
proxy.features << v3_feature
smart_proxy_feature = proxy.smart_proxy_features.select { |spf| spf.feature_id == v3_feature.id }.first
smart_proxy_feature.capabilities = plugins
smart_proxy_feature.settings = { pulp_url: "https://#{Socket.gethostname}",
content_app_url: "http://localhost:24816" }
smart_proxy_feature.save!
end
end
lzap
September 30, 2019, 2:45pm
#3
I might be missing the point, is it the save!
call or create
instead of build
which makes it work? Saving does appear to do some HTTP calls I might need to stub.
lzap
October 1, 2019, 1:38pm
#4
Maybe @Justin_Sherrill can help?
lzap
October 2, 2019, 1:46pm
#5
Found the issue, it was caused by before(:create, :build, :build_stubbed)
which I did not expect. Well, I need to read the code more carefully next time!