Skip to content

Commit

Permalink
fix: Fix User Answers Export
Browse files Browse the repository at this point in the history
  • Loading branch information
AyakorK committed Oct 8, 2024
1 parent 65dfeec commit e802576
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 2 deletions.
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

0 comments on commit e802576

Please sign in to comment.