I’m using a customer_registration
form object to handle the logic of creating a customer, with its credentials, personal information, and billing information. I’m curious how I would go about testing the register!
method? I’m handling form validation in this object, so should the persistence logic be deferred to the models that are actually taking care of that?
class CustomerRegistration
include ActiveModel::Model
...
def register!
if valid?
persist!
else
false
end
end
private
def persist!
# Persist the data from the form
end
end
I considered having a little test to make sure it returns true if valid?
is true, which just entails stubbing valid?
, but that seems a little too simple. Any suggestions?