From b2e7c8c489c7006b1312c3181e6f0f9f90f7fd89 Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Wed, 19 Mar 2025 17:46:37 +0100 Subject: [PATCH 01/10] fix: add new rescue cases in available_locales method --- lib/decidim/term_customizer/i18n_backend.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From b50db441cfe7de46386f327172050f00900e99cf Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Wed, 19 Mar 2025 17:47:08 +0100 Subject: [PATCH 02/10] test: update spec --- .../term_customizer/i18n_backend_spec.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 From 1e53e25fcaef4fcad7c0026adb2dc1913e42c716 Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Thu, 20 Mar 2025 09:11:33 +0100 Subject: [PATCH 03/10] ci: change the ref for tests part --- .github/workflows/ci_term_customizer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_term_customizer.yml b/.github/workflows/ci_term_customizer.yml index 501aff28..fce1924c 100644 --- a/.github/workflows/ci_term_customizer.yml +++ b/.github/workflows/ci_term_customizer.yml @@ -19,5 +19,5 @@ jobs: main: needs: build_app name: Tests - uses: Platoniq/gha-decidim-module/.github/workflows/ci_rspec.yml@main + uses: OpenSourcePolitics/decidim-module-additional_authorization_handler/.github/workflows/test_app.yml@master secrets: inherit From 1c8234b59f8309f705592d668f18da2f7787fd35 Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Thu, 20 Mar 2025 09:19:37 +0100 Subject: [PATCH 04/10] ci: ads specific file for tests part of ci --- .github/workflows/ci_term_customizer.yml | 4 +- .github/workflows/test_app.yml | 102 +++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test_app.yml diff --git a/.github/workflows/ci_term_customizer.yml b/.github/workflows/ci_term_customizer.yml index fce1924c..34836045 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: OpenSourcePolitics/decidim-module-additional_authorization_handler/.github/workflows/test_app.yml@master + 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..0727185a --- /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: "126.0.6478.182" + 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: app-cache + with: + path: ./spec/decidim_dummy_app/ + key: app-${{ github.sha }} + restore-keys: 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 From bb52282145f60e35cfcb3dccfecee0963fa99a10 Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Thu, 20 Mar 2025 09:47:00 +0100 Subject: [PATCH 05/10] ci: updating tests ci --- .github/workflows/ci_term_customizer.yml | 2 +- .github/workflows/test_app.yml | 126 +++++++++-------------- 2 files changed, 51 insertions(+), 77 deletions(-) diff --git a/.github/workflows/ci_term_customizer.yml b/.github/workflows/ci_term_customizer.yml index 34836045..78cc75ab 100644 --- a/.github/workflows/ci_term_customizer.yml +++ b/.github/workflows/ci_term_customizer.yml @@ -21,5 +21,5 @@ jobs: name: Tests uses: ./.github/workflows/test_app.yml with: - test_command: "bundle exec rspec --pattern './spec/**/*_spec.rb'" + 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 index 0727185a..943c5670 100644 --- a/.github/workflows/test_app.yml +++ b/.github/workflows/test_app.yml @@ -1,36 +1,29 @@ on: workflow_call: inputs: - ruby_version: - description: 'Ruby Version' - default: "3.2.2" + use-cached-app: + description: Loads the generated test application from the cache also loads the DB schema for the cached app. required: false - type: string - test_command: - description: 'The testing command to be ran' - required: true - type: string - chrome_version: - description: 'Chrome & Chromedriver version' + default: true + load-schema: + description: Loads the DB schema in case the database has not been initialized. required: false - default: "126.0.6478.182" - type: string - + default: false jobs: - build_app: - name: Test + test_rspec: + name: Test app (RSpec) runs-on: ubuntu-latest if: "!startsWith(github.head_ref, 'chore/l10n')" timeout-minutes: 60 env: + CI: "true" + CODECOV: "true" # legacy + SIMPLECOV: "true" 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"] @@ -41,62 +34,43 @@ jobs: --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: app-cache - with: - path: ./spec/decidim_dummy_app/ - key: app-${{ github.sha }} - restore-keys: 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 + - run: sudo apt-get install imagemagick + name: Install ImageMagick + shell: "bash" + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + # Note that the cache action needs to come after the checkout because it + # deletes the whole folder. + - uses: actions/cache@v4 + id: decidim-app-cache + with: + path: ./spec/decidim_dummy_app/ + key: decidim-app-${{ github.sha }} + restore-keys: decidim-app-${{ github.sha }} + if: ${{ fromJSON(inputs.use-cached-app) }} + - uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - uses: nanasess/setup-chromedriver@v2 + - run: bundle exec rails db:purge db:schema:load + name: Load DB schema + shell: "bash" + working-directory: ./spec/decidim_dummy_app/ + env: + RAILS_ENV: test + DISABLE_SPRING: 1 + if: ${{ fromJSON(inputs.use-cached-app) || fromJSON(inputs.load-schema)}} + - run: bundle exec rspec + name: RSpec + shell: "bash" + env: + DISABLE_SPRING: 1 + - uses: codecov/codecov-action@v3 + - uses: actions/upload-artifact@v4 + if: always() + with: + name: screenshots + path: ./spec/decidim_dummy_app/tmp/screenshots + if-no-files-found: ignore From fd575d1809407fb24316dffbfb02609c536b61fd Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Thu, 20 Mar 2025 09:49:59 +0100 Subject: [PATCH 06/10] ci: change test_app file --- .github/workflows/test_app.yml | 126 ++++++++++++++++++++------------- 1 file changed, 76 insertions(+), 50 deletions(-) diff --git a/.github/workflows/test_app.yml b/.github/workflows/test_app.yml index 943c5670..0727185a 100644 --- a/.github/workflows/test_app.yml +++ b/.github/workflows/test_app.yml @@ -1,29 +1,36 @@ on: workflow_call: inputs: - use-cached-app: - description: Loads the generated test application from the cache also loads the DB schema for the cached app. + ruby_version: + description: 'Ruby Version' + default: "3.2.2" required: false - default: true - load-schema: - description: Loads the DB schema in case the database has not been initialized. + type: string + test_command: + description: 'The testing command to be ran' + required: true + type: string + chrome_version: + description: 'Chrome & Chromedriver version' required: false - default: false + default: "126.0.6478.182" + type: string + jobs: - test_rspec: - name: Test app (RSpec) + build_app: + name: Test runs-on: ubuntu-latest if: "!startsWith(github.head_ref, 'chore/l10n')" timeout-minutes: 60 env: - CI: "true" - CODECOV: "true" # legacy - SIMPLECOV: "true" 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"] @@ -34,43 +41,62 @@ jobs: --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: - - run: sudo apt-get install imagemagick - name: Install ImageMagick - shell: "bash" - - uses: actions/checkout@v4 - with: - fetch-depth: 1 - # Note that the cache action needs to come after the checkout because it - # deletes the whole folder. - - uses: actions/cache@v4 - id: decidim-app-cache - with: - path: ./spec/decidim_dummy_app/ - key: decidim-app-${{ github.sha }} - restore-keys: decidim-app-${{ github.sha }} - if: ${{ fromJSON(inputs.use-cached-app) }} - - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true - - uses: nanasess/setup-chromedriver@v2 - - run: bundle exec rails db:purge db:schema:load - name: Load DB schema - shell: "bash" - working-directory: ./spec/decidim_dummy_app/ - env: - RAILS_ENV: test - DISABLE_SPRING: 1 - if: ${{ fromJSON(inputs.use-cached-app) || fromJSON(inputs.load-schema)}} - - run: bundle exec rspec - name: RSpec - shell: "bash" - env: - DISABLE_SPRING: 1 - - uses: codecov/codecov-action@v3 - - uses: actions/upload-artifact@v4 - if: always() - with: - name: screenshots - path: ./spec/decidim_dummy_app/tmp/screenshots - if-no-files-found: ignore + - 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: app-cache + with: + path: ./spec/decidim_dummy_app/ + key: app-${{ github.sha }} + restore-keys: 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 From f3b55cae4e22713d7c842f0de4c421e9765ad7b0 Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Thu, 20 Mar 2025 10:08:49 +0100 Subject: [PATCH 07/10] ci: update cache action in test_app file --- .github/workflows/test_app.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_app.yml b/.github/workflows/test_app.yml index 0727185a..5cab3fcf 100644 --- a/.github/workflows/test_app.yml +++ b/.github/workflows/test_app.yml @@ -66,11 +66,11 @@ jobs: chromedriver-version: ${{inputs.chrome_version}} name: Install Chrome version ${{inputs.chrome_version}} - uses: actions/cache@v4 - id: app-cache + id: decidim-app-cache with: path: ./spec/decidim_dummy_app/ key: app-${{ github.sha }} - restore-keys: app-${{ github.sha }} + restore-keys: decidim-app-${{ github.sha }} - run: | bundle install bundle exec rake db:create db:schema:load From 15d1032a1ffa918f8b826c7672d44227455b364b Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Wed, 19 Nov 2025 14:01:51 +0100 Subject: [PATCH 08/10] fix: add maxResults --- .../src/decidim/term_customizer/admin/translations_admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 }); }; From 8c4d3585c3209b3fc823cdaf100d49a1d56ba57c Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Wed, 19 Nov 2025 14:33:01 +0100 Subject: [PATCH 09/10] ci: update chrome version --- .github/workflows/test_app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_app.yml b/.github/workflows/test_app.yml index 5cab3fcf..bcf6c58c 100644 --- a/.github/workflows/test_app.yml +++ b/.github/workflows/test_app.yml @@ -13,7 +13,7 @@ on: chrome_version: description: 'Chrome & Chromedriver version' required: false - default: "126.0.6478.182" + default: "136.0.7103.92" type: string jobs: From 08a7a55ac5336a5d3e2d549441423ca961714dce Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Thu, 20 Nov 2025 11:05:03 +0100 Subject: [PATCH 10/10] fix: update job context to work with emails --- lib/decidim/term_customizer/context/job_context.rb | 1 + 1 file changed, 1 insertion(+) 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)