On Wednesday, May 23, 2018 at 1:38:48 PM UTC-7, Elanor Riley wrote:
>
> So I just ran into an infuriating error while running my tests and I'm
> unsure if the error message can be improved to help someone in my position
> for the next time.
>
> Situation:
>
> I have a model. I'm writing a test to ensure the model is valid. My model
> has a validation like so:
>
> def validate
> super
> validates_presence [:package_name]
> validates_unique :package_name, :message => "That package name is already
> in use."
> end
>
>
> When running the test, I was receiving the error:
>
> NameError: undefined local variable or method `package_name' for
> #<CustomerServiceType @values={}>
>
> I couldn't figure out the root cause because I manually tested this in
> `padrino c` and everything worked.
>
> Turns out I hadn't run my table migrations in my test environment! I was
> pulling my hair out.
>
> Is there a way the error message could be modified to perhaps let people
> know that the database table Sequel is trying to reference doesn't exist?
> Just a thought.
>
What Sequel is trying to do is call the package_name method, so a NameError
makes sense if the method is not defined.
Note that in Sequel 5, if the model class's database type does not exist,
that raises an error when creating the model class (fail early). So I
assume you have either not yet upgraded to Sequel 5, or you have modified
the default configuration (require_valid_table = false) so that doesn't
raise an error.
In general I'm against overly defense error checking to produce slightly
nicer errors, especially in cases where it could negatively effect
performance.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.