From e80257606b92377eb6fe87d6d7eb0d409a8cd746 Mon Sep 17 00:00:00 2001 From: AyakorK Date: Tue, 8 Oct 2024 10:55:00 +0200 Subject: [PATCH] fix: Fix User Answers Export --- Gemfile | 1 + Gemfile.lock | 3 +- config/application.rb | 2 +- .../export_questionnaire_answers_job_spec.rb | 67 +++++++++++++++++++ spec/wicked_pdf_spec.rb | 9 +++ 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 spec/jobs/decidim/forms/export_questionnaire_answers_job_spec.rb create mode 100644 spec/wicked_pdf_spec.rb diff --git a/Gemfile b/Gemfile index d156c6e7..4247e1dd 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index 0f8e0f97..75b929b1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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 diff --git a/config/application.rb b/config/application.rb index e708daff..20699625 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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. diff --git a/spec/jobs/decidim/forms/export_questionnaire_answers_job_spec.rb b/spec/jobs/decidim/forms/export_questionnaire_answers_job_spec.rb new file mode 100644 index 00000000..5b5f3ccc --- /dev/null +++ b/spec/jobs/decidim/forms/export_questionnaire_answers_job_spec.rb @@ -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 diff --git a/spec/wicked_pdf_spec.rb b/spec/wicked_pdf_spec.rb new file mode 100644 index 00000000..34049408 --- /dev/null +++ b/spec/wicked_pdf_spec.rb @@ -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