I have written myself a model that looks something like this:
class PersonalDetailsForm < Reform::Form
include Reform::Form::ActiveModel::ModelReflections
include Reform::Form::Module
model :user
property :name
validates :name, presence: true
ProfilePrepopulator = lambda do |_options|
self.profile ||= Profile.new()
end
ProfilePopulator = lambda do |model:, **|
model || self.profile = Profile.new()
end
property :profile, populator: ProfilePopulator, prepopulator: ProfilePrepopulator do
property :date_of_birth
validates :date_of_birth, presence: true
AddressPopulator = lambda do |model:, **|
model || self.address = Address.new
end
AddressPrepopulator = lambda do |_options|
self.address ||= Address.new
end
property :address, populator: AddressPopulator,
prepopulator: AddressPrepopulator do
property :city
validates :line1, presence: true
end
end
end
In controller I go
form.validate(params[:user]] && form.save
And it works very well when i just run the browser and click around, but it doesnt do very well in request specs. for the mentioned above action to take place i send request with params for user, profile but not for address. it should fail, but it passes, somehow rspec doesnt see this last nested validation. If i remove validated params for profile it fails. Any idea how to fix this?
Aucun commentaire:
Enregistrer un commentaire