I am new to rails rspec testing, I currently need to created nested data structure and using factorybot for data. And while it works for controller testing. Its not letting me do simple Factorybot.create(:model). I have searched a lot. But didn't seem to find or understand a solution. So, data structure i need to create is something like:
"email":"",
"name":"",
"personalDetail":{
"height":"",
"weight":"",
"color":""
}
"address":{
"street":"",
"postal_code":""
},
"experience":""
}
(**note. this not association related, data in controller is received in such a way. There is no relationship involved) while i am currently achieving this structure using
initialize_with{{
"email":"",
"name":"",
"personalDetail":{
"height":"",
"weight":"",
"color":""
}
"address":{
"street":"",
"postal_code":""
},
"experience":""
}}
its works for controller testing but it i'm not able to change key value while testing like:
FactoryBot.create(:model, name:"xyz")
, and also is not working for FactoryBot.create(:model), which is giving me error of
** Api::V1::someController get #index Failure/Error: FactoryBot.create(:model)
NoMethodError:
undefined method `save!' for #<Hash:0x0000563db7324060>
# ./spec/controllers/api/v1/somecontroller_spec.rb:11:in `block (2 levels) in <main>'
# -e:1:in `<main>' **
So, my question is how can i generate this structure using FactoryBot usual method. i.e
factory :job_application do
field1 { "" }
field2 { "" }
end
so that i can use it usual way.