|
|
|
@ -55,25 +55,21 @@ module API |
|
|
|
|
validate :readonly_attributes_unchanged |
|
|
|
|
validate :run_attribute_validations |
|
|
|
|
|
|
|
|
|
# Performs validation of both, the contract and the underlying model and returns |
|
|
|
|
# the merged validation errors for both of them. |
|
|
|
|
def validate_contract_and_model |
|
|
|
|
self.validate |
|
|
|
|
def validate |
|
|
|
|
super.validate |
|
|
|
|
model.valid? |
|
|
|
|
|
|
|
|
|
merged_errors = self.errors.dup |
|
|
|
|
|
|
|
|
|
# We need to merge the contract errors with the model errors in |
|
|
|
|
# order to have them available at one place. |
|
|
|
|
# This is something we need as long as we have validations split |
|
|
|
|
# among the model and its contract. |
|
|
|
|
model.errors.keys.each do |key| |
|
|
|
|
model.errors[key].each do |message| |
|
|
|
|
merged_errors.add(key, message) |
|
|
|
|
errors.add(key, message) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
merged_errors |
|
|
|
|
errors.empty? |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
private |
|
|
|
|