diff --git a/.github/workflows/ci_term_customizer.yml b/.github/workflows/ci_term_customizer.yml index 501aff28..78cc75ab 100644 --- a/.github/workflows/ci_term_customizer.yml +++ b/.github/workflows/ci_term_customizer.yml @@ -19,5 +19,7 @@ jobs: main: needs: build_app name: Tests - uses: Platoniq/gha-decidim-module/.github/workflows/ci_rspec.yml@main + uses: ./.github/workflows/test_app.yml + with: + test_command: "bundle exec rspec --pattern './spec/**/*_spec.rb'" secrets: inherit diff --git a/.github/workflows/test_app.yml b/.github/workflows/test_app.yml new file mode 100644 index 00000000..bcf6c58c --- /dev/null +++ b/.github/workflows/test_app.yml @@ -0,0 +1,102 @@ +on: + workflow_call: + inputs: + ruby_version: + description: 'Ruby Version' + default: "3.2.2" + required: false + type: string + test_command: + description: 'The testing command to be ran' + required: true + type: string + chrome_version: + description: 'Chrome & Chromedriver version' + required: false + default: "136.0.7103.92" + type: string + +jobs: + build_app: + name: Test + runs-on: ubuntu-latest + if: "!startsWith(github.head_ref, 'chore/l10n')" + timeout-minutes: 60 + env: + DATABASE_USERNAME: postgres + DATABASE_PASSWORD: postgres + DATABASE_HOST: localhost + RUBYOPT: '-W:no-deprecated' + services: + validator: + image: ghcr.io/validator/validator:latest + ports: ["8888:8888"] + postgres: + image: postgres:14 + ports: ["5432:5432"] + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + env: + POSTGRES_PASSWORD: postgres + redis: + image: redis + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ inputs.ruby_version }} + - run: | + sudo apt update + sudo apt install libu2f-udev + wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${{inputs.chrome_version}}-1_amd64.deb + sudo dpkg -i /tmp/chrome.deb + rm /tmp/chrome.deb + - uses: nanasess/setup-chromedriver@v2 + with: + chromedriver-version: ${{inputs.chrome_version}} + name: Install Chrome version ${{inputs.chrome_version}} + - uses: actions/cache@v4 + id: decidim-app-cache + with: + path: ./spec/decidim_dummy_app/ + key: app-${{ github.sha }} + restore-keys: decidim-app-${{ github.sha }} + - run: | + bundle install + bundle exec rake db:create db:schema:load + name: Install gems and create db + shell: "bash" + working-directory: ./spec/decidim_dummy_app/ + - run: | + sudo Xvfb -ac $DISPLAY -screen 0 1920x1084x24 > /dev/null 2>&1 & # optional + ${{ inputs.test_command }} + name: RSpec + working-directory: ./ + env: + VALIDATOR_HTML_URI: http://localhost:8888/ + RUBY_VERSION: ${{ inputs.ruby_version }} + DECIDIM_MODULE: "decidim-module-additional_authorization_handler" + DISPLAY: ":99" + CI: "true" + SIMPLECOV: "true" + SHAKAPACKER_RUNTIME_COMPILE: "false" + NODE_ENV: "test" + - uses: codecov/codecov-action@v3 + name: Upload coverage + - uses: actions/upload-artifact@v4 + if: always() + with: + name: screenshots + path: ./spec/decidim_dummy_app/tmp/screenshots + if-no-files-found: ignore + overwrite: true diff --git a/app/packs/src/decidim/term_customizer/admin/translations_admin.js b/app/packs/src/decidim/term_customizer/admin/translations_admin.js index 27ceb156..aa634252 100644 --- a/app/packs/src/decidim/term_customizer/admin/translations_admin.js +++ b/app/packs/src/decidim/term_customizer/admin/translations_admin.js @@ -26,7 +26,6 @@ $(() => { // Just to avoid the "no-new" ESLint issue, wrap this in a function const initiate = () => { const config = JSON.parse(searchInput.dataset.autocomplete); - return new AutoComplete(searchInput, { name: searchInput.getAttribute("name"), placeholder: searchInput.getAttribute("placeholder"), @@ -41,6 +40,7 @@ $(() => { item.innerHTML = replacedText; item.dataset.value = valueItem.value; }, + maxResults: 200, dataSource }); }; diff --git a/lib/decidim/term_customizer/context/job_context.rb b/lib/decidim/term_customizer/context/job_context.rb index 5108778b..e325f98e 100644 --- a/lib/decidim/term_customizer/context/job_context.rb +++ b/lib/decidim/term_customizer/context/job_context.rb @@ -11,6 +11,7 @@ def resolve! # passed for the job. user = nil data[:job].arguments.each do |arg| + arg = arg[:args].first if arg.is_a?(Hash) && arg.has_key?(:args) @organization ||= organization_from_argument(arg) @space ||= space_from_argument(arg) @component ||= component_from_argument(arg) diff --git a/lib/decidim/term_customizer/i18n_backend.rb b/lib/decidim/term_customizer/i18n_backend.rb index 38dfd8ee..be4bde5a 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 dd8ac4c9..075e3c07 100644 --- a/spec/lib/decidim/term_customizer/i18n_backend_spec.rb +++ b/spec/lib/decidim/term_customizer/i18n_backend_spec.rb @@ -62,7 +62,7 @@ end end - it "returns an empty result" do + it "returns the available locales" do expect(subject.available_locales).to match_array(locales) end end @@ -76,6 +76,22 @@ expect(subject.available_locales).to be_empty end end + + context "when the translation query raises ActiveRecord::ConnectionNotEstablished" do + it "returns an empty result" do + allow(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 an empty result" do + allow(Decidim::TermCustomizer::Translation).to receive(:available_locales).and_raise(PG::ConnectionBad) + + expect(subject.available_locales).to be_empty + end + end end describe "#initialized?" do