From 770b3903766ead1e7ae708cc2f9b045e4613ad1f Mon Sep 17 00:00:00 2001 From: armandfardeau Date: Tue, 13 Jun 2023 09:36:55 +0200 Subject: [PATCH 1/2] 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 9a53d57..963cbb5 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 From 5c2b648e07c5fd51e2598256886895b9a83d698c Mon Sep 17 00:00:00 2001 From: armandfardeau Date: Thu, 31 Aug 2023 12:17:11 +0200 Subject: [PATCH 2/2] Fix offenses --- Gemfile.lock | 3 +++ spec/lib/decidim/term_customizer/i18n_backend_spec.rb | 8 ++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 896e1ff..fd26f53 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -513,6 +513,8 @@ GEM net-smtp (0.3.3) net-protocol nio4r (2.5.9) + nokogiri (1.14.5-arm64-darwin) + racc (~> 1.4) nokogiri (1.14.5-x86_64-linux) racc (~> 1.4) oauth (1.1.0) @@ -799,6 +801,7 @@ GEM zeitwerk (2.6.11) PLATFORMS + arm64-darwin-22 x86_64-linux DEPENDENCIES diff --git a/spec/lib/decidim/term_customizer/i18n_backend_spec.rb b/spec/lib/decidim/term_customizer/i18n_backend_spec.rb index 963cbb5..bae8152 100644 --- a/spec/lib/decidim/term_customizer/i18n_backend_spec.rb +++ b/spec/lib/decidim/term_customizer/i18n_backend_spec.rb @@ -80,9 +80,7 @@ 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) + allow(Decidim::TermCustomizer::Translation).to receive(:available_locales).and_raise(ActiveRecord::ConnectionNotEstablished) expect(subject.available_locales).to be_empty end @@ -90,9 +88,7 @@ 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) + allow(Decidim::TermCustomizer::Translation).to receive(:available_locales).and_raise(PG::ConnectionBad) expect(subject.available_locales).to be_empty end