Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: User Answers not exporting from surveys #151

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
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
105 changes: 98 additions & 7 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ env:
SIMPLECOV: "true"
RSPEC_FORMAT: "documentation"
RUBY_VERSION: 3.0.6
CHROME_VERSION: 126.0.6478.182
RAILS_ENV: test
NODE_VERSION: 16.9.1
RUBYOPT: '-W:no-deprecated'
Expand Down Expand Up @@ -54,6 +55,10 @@ jobs:
run: |
bundle exec rails zeitwerk:check
tests:
strategy:
fail-fast: false
matrix:
slice: [ "0-2", "1-2" ]
name: Tests
runs-on: ubuntu-latest
services:
Expand All @@ -76,17 +81,60 @@ jobs:
if: "github.ref != 'refs/heads/master' || github.ref != 'refs/heads/develop'"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- uses: OpenSourcePolitics/rspec-action@fix/chromedriver_lock_119
- uses: actions/checkout@v3
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- run: |
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_${{env.CHROME_VERSION}}-1_amd64.deb
sudo dpkg -i /tmp/chrome.deb
rm /tmp/chrome.deb
name: Install Chrome version ${{ env.CHROME_VERSION }}
- uses: actions/setup-node@v3
with:
command: 'bundle exec rspec --exclude-pattern "spec/system/**/*_spec.rb"'
prepare_command: "bundle exec rails db:create db:migrate"
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: yarn install --prefer-offline --frozen-lockfile
- name: Create db
run: |
bundle exec rails parallel:create parallel:migrate
- name: Register cache hash
id: cache-hash
run: |
echo "::set-output name=hash::$(bundle exec rake test:assets_hash)"
- uses: OpenSourcePolitics/cache-precompile-action@master
with:
key: asset-cache-${{ runner.os }}-${{ steps.cache-hash.outputs.hash }}
- run: mkdir -p ./spec/tmp/screenshots
name: Create the screenshots folder
- uses: nanasess/setup-chromedriver@v2
with:
chromedriver-version: ${{ env.CHROME_VERSION }}
- run: bundle exec rspec --exclude-pattern "spec/system/**/*_spec.rb"
name: RSpec
# - run: ./.github/upload_coverage.sh decidim-app $GITHUB_EVENT_PATH
# name: Upload coverage
- uses: actions/upload-artifact@v3
if: always()
with:
name: screenshots
path: ./spec/tmp/screenshots
- uses: actions/upload-artifact@v3
if: always()
with:
name: assets-manifest-${{ matrix.slice }}
path: ./tmp/assets_manifest.json
system_tests:
name: System tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11
ports: [ "5432:5432" ]
ports: ["5432:5432"]
options: >-
--health-cmd pg_isready
--health-interval 10s
Expand All @@ -106,10 +154,53 @@ jobs:
if: "github.ref != 'refs/heads/master' || github.ref != 'refs/heads/develop'"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- uses: OpenSourcePolitics/rspec-action@fix/chromedriver_lock_119
- uses: actions/checkout@v3
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ env.RUBY_VERSION }}
bundler-cache: true
- run: |
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_${{env.CHROME_VERSION}}-1_amd64.deb
sudo dpkg -i /tmp/chrome.deb
rm /tmp/chrome.deb
name: Install Chrome version ${{ env.CHROME_VERSION }}
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: yarn install --prefer-offline --frozen-lockfile
- name: Create db
run: |
bundle exec rails parallel:create parallel:migrate
- name: Register cache hash
id: cache-hash
run: |
echo "::set-output name=hash::$(bundle exec rake test:assets_hash)"
- uses: OpenSourcePolitics/cache-precompile-action@master
with:
key: asset-cache-${{ runner.os }}-${{ steps.cache-hash.outputs.hash }}
- run: mkdir -p ./spec/tmp/screenshots
name: Create the screenshots folder
- uses: nanasess/setup-chromedriver@v2
with:
chromedriver-version: ${{ env.CHROME_VERSION }}
- run: bundle exec rspec --exclude-pattern "spec/system/**/*_spec.rb"
name: RSpec
# - run: ./.github/upload_coverage.sh decidim-app $GITHUB_EVENT_PATH
# name: Upload coverage
- uses: actions/upload-artifact@v3
if: always()
with:
name: screenshots
path: ./spec/tmp/screenshots
- uses: actions/upload-artifact@v3
if: always()
with:
command: 'bundle exec rspec "spec/system"'
prepare_command: "bundle exec rails db:create db:migrate"
name: assets-manifest-${{ matrix.slice }}
path: ./tmp/assets_manifest.json
test_build:
name: Test build docker image
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ gem "omniauth-rails_csrf_protection", "~> 1.0"
gem "puma", ">= 5.5.1"
gem "rack-attack", "~> 6.6"
gem "sys-filesystem"
gem "wicked_pdf", "2.6.3"

group :development do
gem "listen", "~> 3.1"
Expand Down
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ GEM
websocket-extensions (0.1.5)
wicked (1.4.0)
railties (>= 3.0.7)
wicked_pdf (2.7.0)
wicked_pdf (2.6.3)
activesupport
wisper (2.0.1)
wisper-rspec (1.1.0)
Expand Down Expand Up @@ -1043,6 +1043,7 @@ DEPENDENCIES
spring-watcher-listen (~> 2.0)
sys-filesystem
web-console (= 4.0.4)
wicked_pdf (= 2.6.3)

RUBY VERSION
ruby 3.0.6p216
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require_relative "../lib/active_storage/downloadable"

# TODO : add missing dep to decidim-initiatives/lib/decidim/initiatives/engine.rb
# require "wicked_pdf"
require "wicked_pdf"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Expand Down
67 changes: 67 additions & 0 deletions spec/jobs/decidim/forms/export_questionnaire_answers_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::Forms::ExportQuestionnaireAnswersJob do
subject { described_class }

let!(:user) { create(:user, :admin) }
let!(:title) { "The answers" }
let!(:questionnaire) { create(:questionnaire) }
let!(:questions) { create_list(:questionnaire_question, 3, questionnaire: questionnaire) }
let!(:answers) { questions.map { |q| create(:answer, question: q, questionnaire: questionnaire) } }
let!(:collection) { [answers] }

describe "queue" do
it "is queued to events" do
expect(subject.queue_name).to eq "exports"
end
end

describe "when everything is OK" do
let(:mailer) { double :mailer }

it "sends an email" do
allow(Decidim::ExportMailer)
.to receive(:export)
.and_return(mailer)
expect(mailer)
.to receive(:deliver_now)

subject.perform_now(user, title, collection)
end
end

describe "when no answers" do
it "doesn't send the email" do
collection = []

expect(Decidim::ExportMailer)
.not_to receive(:export)

subject.perform_now(user, title, collection)
end
end

describe "when no user" do
it "doesn't send the email" do
user = nil

expect(Decidim::ExportMailer)
.not_to receive(:export)

subject.perform_now(user, title, collection)
end
end

describe "when user has no email" do
it "doesn't send the email" do
user.update(email: "")

expect(Decidim::ExportMailer)
.not_to receive(:export)

subject.perform_now(user, title, collection)
end
end
end
9 changes: 9 additions & 0 deletions spec/wicked_pdf_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require "spec_helper"

describe "WickedPdf" do
it "has version 2.6.3" do
expect(WickedPdf::VERSION).to eq("2.6.3")
end
end
Loading