From 228a49113279a53d45a1b5973d0284ee831263f0 Mon Sep 17 00:00:00 2001 From: armandfardeau Date: Tue, 13 Jun 2023 09:36:55 +0200 Subject: [PATCH] Fix precompile on docker --- lib/decidim/term_customizer/i18n_backend.rb | 2 +- .../term_customizer/i18n_backend_spec.rb | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/decidim/term_customizer/i18n_backend.rb b/lib/decidim/term_customizer/i18n_backend.rb index 38dfd8e..be4bde5 100644 --- a/lib/decidim/term_customizer/i18n_backend.rb +++ b/lib/decidim/term_customizer/i18n_backend.rb @@ -15,7 +15,7 @@ module Implementation # Get available locales from the translations hash def available_locales Translation.available_locales - rescue ::ActiveRecord::StatementInvalid + rescue ::ActiveRecord::StatementInvalid, ::ActiveRecord::ConnectionNotEstablished, ::PG::ConnectionBad [] end diff --git a/spec/lib/decidim/term_customizer/i18n_backend_spec.rb b/spec/lib/decidim/term_customizer/i18n_backend_spec.rb index d388238..280bb0e 100644 --- a/spec/lib/decidim/term_customizer/i18n_backend_spec.rb +++ b/spec/lib/decidim/term_customizer/i18n_backend_spec.rb @@ -78,6 +78,26 @@ end end + context "when the translation query raises ActiveRecord::StatementInvalid" do + it "returns and empty result" do + expect(Decidim::TermCustomizer::Translation).to receive( + :available_locales + ).and_raise(ActiveRecord::ConnectionNotEstablished) + + expect(subject.available_locales).to be_empty + end + end + + context "when there is no database connection" do + it "returns and empty result" do + expect(Decidim::TermCustomizer::Translation).to receive( + :available_locales + ).and_raise(PG::ConnectionBad) + + expect(subject.available_locales).to be_empty + end + end + describe "#initialized?" do context "when translations are not loaded" do it "returns false" do