From df2b3f2ee78bfe43ab3eca0ed35d2ab699947eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 25 Mar 2022 19:42:06 +0100 Subject: [PATCH] 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. --- spec/models/skip_validation_spec.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spec/models/skip_validation_spec.rb b/spec/models/skip_validation_spec.rb index 553432757..d5da860b9 100644 --- a/spec/models/skip_validation_spec.rb +++ b/spec/models/skip_validation_spec.rb @@ -49,19 +49,21 @@ describe SkipValidation do describe ".skip_translation_validation" do before do - dummy_banner = Class.new(Banner) do - def self.translation_class - @translation_class ||= Class.new(Banner::Translation) { clear_validators! } + dummy_banner = Class.new(ApplicationRecord) do + def self.name + "DummyBanner" end - reflect_on_association(:translations).options[:class_name] = "DummyBanner::Translation" + self.table_name = "banners" + + translates :title, touch: true + translates :description, touch: true + include Globalizable - clear_validators! validates_translation :title, presence: true validates_translation :description, presence: true end stub_const("DummyBanner", dummy_banner) - stub_const("DummyBanner::Translation", dummy_banner.translation_class) end it "removes the validation from the translatable attribute" do