forked from consuldemocracy/consuldemocracy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 'Refactor code and increase tests coverage for cus…
…tom export legislation process feature' (#11) from export_legislation_process_specs into master Reviewed-on: https://git.nubarron.teide.int/shs-consul/cabildoabierto-consul/pulls/11
- Loading branch information
Showing
8 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
spec/models/custom/legislation/annotations/exporter_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require "rails_helper" | ||
|
||
describe Legislation::Annotations::Exporter do | ||
let(:annotation) { create(:legislation_annotation) } | ||
|
||
context "#to_csv" do | ||
scenario "generate csv with answer content" do | ||
I18n.with_locale(:es) do | ||
csv = Legislation::Annotations::Exporter.new(annotation.draft_version.process).to_csv | ||
|
||
comment = annotation.comments.first | ||
version = annotation.draft_version | ||
csv_contents = "ID,Comentario,Usuario,ID del borrador,Versión del borrador,ID de la anotación,Texto de la anotación\n"\ | ||
"#{comment.id},#{comment.body},#{comment.user.id},#{version.id},#{version.title},"\ | ||
"#{annotation.id},#{annotation.quote}\n" | ||
expect(csv).to eq csv_contents | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require "rails_helper" | ||
|
||
describe Legislation::Answers::Exporter do | ||
let(:answer) { create(:legislation_answer) } | ||
|
||
context "#to_csv" do | ||
scenario "generate csv with answer content" do | ||
I18n.with_locale(:es) do | ||
csv = Legislation::Answers::Exporter.new(answer.question.process).to_csv | ||
|
||
csv_contents = "ID,Tipo de respuesta,ID de la pregunta,Texto de la pregunta,Respuesta,Usuario\n"\ | ||
"#{answer.id},Opcional,#{answer.question.id},#{answer.question.title},"\ | ||
"#{answer.question_option.value},#{answer.user.id}\n" | ||
expect(csv).to eq csv_contents | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require "rails_helper" | ||
|
||
describe Legislation::Proposals::Exporter do | ||
let(:proposal) { create(:legislation_proposal) } | ||
|
||
context "#to_csv" do | ||
scenario "generate csv with answer content" do | ||
I18n.with_locale(:es) do | ||
csv = Legislation::Proposals::Exporter.new(proposal.process).to_csv | ||
|
||
csv_contents = "ID,Título de la propuesta,Descripción de la propuesta,ID del autor,Votos totales,Número de comentarios\n"\ | ||
"#{proposal.id},#{proposal.title},#{proposal.description},#{proposal.author.id},"\ | ||
"#{proposal.cached_votes_total},#{proposal.comments_count}\n" | ||
expect(csv).to eq csv_contents | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "rails_helper" | ||
|
||
describe "Admin collaborative legislation", :admin do | ||
context "Index" do | ||
scenario "Shows a download link per process", :no_js do | ||
process = create(:legislation_process) | ||
|
||
visit admin_legislation_processes_path(filter: "all", locale: :es) | ||
within "#legislation_process_#{process.id}" do | ||
click_link("Descargar CSV") | ||
end | ||
|
||
header = page.response_headers["Content-Disposition"] | ||
expect(header).to match(/^attachment;/) | ||
expect(header).to match(/filename="process_#{process.id}.zip"$/) | ||
expect(page.body).to include "process.csv" | ||
expect(page.body).to include "questions_answers.csv" | ||
expect(page.body).to include "draft_comments.csv" | ||
expect(page.body).to include "proposals.csv" | ||
end | ||
end | ||
end |