Summary:
The information in "Saving with Forms" for Custom Validations does not seem to be correct. If I create a pristine Lucky project and add the custom validation in the guide, I get a compiler error.
Steps to reproduce:
lucky init
name it 'whatever', select full, say y to generating authentication
cd whatever
Add in the example used in the guide (validate_is_old_enough) to SignUpForm, resulting in this:
class SignUpForm < User::BaseForm
# Change password validations in src/forms/mixins/password_validations.cr
include PasswordValidations
fillable email
virtual password : String
virtual password_confirmation : String
def prepare
validate_uniqueness_of email
run_password_validations
Authentic.copy_and_encrypt password, to: encrypted_password
validate_is_old_enough
end
private def user_is_old_enough
# The value might be `nil` so we need to use `try`.
## There's no 'age' but we'll leave the same method name
email.value.try do |value|
if email == "batman@notbatman.com"
field.add_error "Dude you're totally batman"
end
end
end
end
Run script/setup then lucky dev
Compiler barfs out:
web | in src/actions/sign_ups/create.cr:5: instantiating 'SignUpForm.class#create(Lucky::Params)'
web |
web | SignUpForm.create(params) do |form, user|
web | ^~~~~~
web |
web | in macro 'generate_save_methods' /private/tmp/what/whatever/lib/avram/src/avram/needy_initializer_and_save_methods.cr:159, line 1:
web |
web | > 1. generate_create(with_params: true, with_bang: false)
web | 2. generate_create(with_params: true, with_bang: true)
web | 3. generate_create(with_params: false, with_bang: true)
web | 4. generate_create(with_params: false, with_bang: false)
web | 5.
web | 6. generate_update(with_params: true, with_bang: false)
web | 7. generate_update(with_params: true, with_bang: true)
web | 8. generate_update(with_params: false, with_bang: true)
web | 9. generate_update(with_params: false, with_bang: false)
web | 10.
web |
web | expanding macro
web | in macro 'generate_create' /private/tmp/what/whatever/lib/avram/src/avram/needy_initializer_and_save_methods.cr:65, line 20:
web |
web | 1. def self.create(
web | 2. params,
web | 3.
web | 4.
web | 5.
web | 6. password : String | Nothing = Nothing.new,
web | 7.
web | 8. password_confirmation : String | Nothing = Nothing.new,
web | 9.
web | 10. )
web | 11. form = new(
web | 12. params,
web | 13.
web | 14. )
web | 15.
web | 16.
web | 17.
web | 18.
web | 19.
web | > 20. if form.save
web | 21. yield form, form.record
web | 22. else
web | 23. form.log_failed_save
web | 24. yield form, nil
web | 25. end
web | 26.
web | 27. end
web | 28.
web |
web | instantiating 'SignUpForm#save()'
web | in lib/avram/src/avram/form.cr:261: instantiating 'perform_save()'
web |
web | if perform_save
web | ^~~~~~~~~~~~
web |
web | in lib/avram/src/avram/form.cr:271: instantiating 'valid?()'
web |
web | if valid? && changes.any?
web | ^~~~~~
web |
web | in lib/avram/src/avram/form.cr:180: instantiating 'prepare()'
web |
web | prepare
web | ^~~~~~~
web |
web | in src/forms/sign_up_form.cr:13: undefined local variable or method 'validate_is_old_enough'
web |
web | validate_is_old_enough
web | ^~~~~~~~~~~~~~~~~~~~~~
web |
web | There was a problem compiling. Watching for fixes...
Summary: The information in "Saving with Forms" for Custom Validations does not seem to be correct. If I create a pristine Lucky project and add the custom validation in the guide, I get a compiler error.
Steps to reproduce:
full
, sayy
to generating authenticationvalidate_is_old_enough
) to SignUpForm, resulting in this:script/setup
thenlucky dev