Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci_term_customizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
102 changes: 102 additions & 0 deletions .github/workflows/test_app.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -41,6 +40,7 @@ $(() => {
item.innerHTML = replacedText;
item.dataset.value = valueItem.value;
},
maxResults: 200,
dataSource
});
};
Expand Down
1 change: 1 addition & 0 deletions lib/decidim/term_customizer/context/job_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/decidim/term_customizer/i18n_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 17 additions & 1 deletion spec/lib/decidim/term_customizer/i18n_backend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down