FactoryBot advice - subnet-smart proxy-feature

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.

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:

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.

Maybe @Justin_Sherrill can help?

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!