6 Commits

Author SHA1 Message Date
Ivan Kuchin d16cc85f58 test handling available custom fields in BaseContract 2026-02-25 20:07:06 +01:00
Jan Sandbrink c753ce6e30 Replace with_merged_former_errors by validate_and_merge_errors
The main problem with the previous method was that it only worked
if the contract being validated inside the block was sharing the same
errors object as the contract calling it. The old implementation
was incapable of incorporating errors from a contract that had its
own errors object.

In my opinion it's a code smell that our contracts use the #errors
of the model they are validating as the place to store their validation
result, however I didn't dare touching this yet, because changing that
would certainly be a huge change. I can also imagine that some places rely
on it for historic reasons (because using "classic" validations also
puts the errors on the model). However, I think that no two contracts
should RELY on using the SAME errors object, just because the way we implemented
them happens to cause them to share the same object.
2025-02-11 10:51:49 +01:00
Ivan Kuchin 4911b8a149 remove years from copyrights (except for COPYRIGHT file) 2024-07-31 15:02:49 +02:00
Christophe Bliard 87f98e9da1 Remove unused contexts 2024-07-19 09:18:52 +02:00
Christophe Bliard d6f560bb93 Update spec/contracts/base_contract_spec.rb
Co-authored-by: Aaron Contreras <61627014+aaron-contreras@users.noreply.github.com>
2024-07-19 09:17:47 +02:00
Christophe Bliard 71f0728898 Fix writable_attributes when redefining attributes in child classes
There were cases were the writable parameter of a parent contract would
take precedence of the child contract writable parameter when the parent
condition is a lambda: a child could say `writable: true` and it would
still be the parent `writable: -> { false }` that would "win" because
when reducing and evaluating `writable_conditions`, only lambda are
considered.

This commit fixes the issue by adding extensive tests and putting both
lambdas AND true/false values in the `writable_conditions` hash.
2024-07-18 17:13:19 +02:00