4 Commits

Author SHA1 Message Date
Javi Martín
d18c627392 Add and apply Layout/EmptyLinesAfterModuleInclusion rule
This rule was added in rubocop 1.79. We were inconsistent about it, so
we're adding it to get more consistency.
2025-11-05 14:27:12 +01:00
Javi Martín
4d11d8a395 Specify translation class name in dummy test class
These tests were failing with Ruby 3.0 because we were getting an error
when loading the `translations` association of the dummy class:

```
NameError:
  uninitialized constant
  DummyBanner::#<Class:0x000055630e4dccd8>::Translation
```

Specifying the `class_name` of the `translations` association solves the
issue.
2023-04-13 16:31:28 +02:00
Javi Martín
df2b3f2ee7 Avoid model inheritance in skip validation test
One of these tests was failing sometimes on Github Actions. It looked
like the line `custom_banner.save!` was using the validations from the
Banner class sometimes, even if the callbacks had correctly been
removed in the DummyBanner class.

Se we're inheriting from ApplicationRecord instead of inheriting from
Banner. Since I couldn't reproduce the issue locally after running the
test hundreds of times and with the same seed and tests that were
running on Github Actions, there's a change this won't work. I've tested
a few times on Github Actions and it seems to be working, but we'll have
to keep an eye on it.
2022-03-25 20:25:34 +01:00
Javi Martín
b5a4609b56 Make it easier to customize validations
There are CONSUL installations where the validations CONSUL offers by
default don't make sense because they're using a different business
logic. Removing these validations in a custom model was hard, and that's
why in many cases modifying the original CONSUL models was an easier
solution.

Since modifying the original CONSUL models makes the code harder to
maintain, we're now providing a way to easily skip validations in a
custom model. For example, in order to skip the price presence
validation in the Budget::Heading model, we could write a model in
`app/models/custom/budget/heading.rb`:

```
require_dependency Rails.root.join("app", "models", "budget", "heading").to_s

class Budget::Heading
  skip_validation :price, :presence
end
```

In order to skip validation on translatable attributes (defined with
`validates_translation`), we have to use the
`skip_translation_validation` method; for example, to skip the proposal
title presence validation:

```
require_dependency Rails.root.join("app", "models", "proposal").to_s

class Proposal
  skip_translation_validation :title, :presence
end

```

Co-Authored-By: taitus <sebastia.roig@gmail.com>
2022-03-24 17:05:35 +01:00