forked from decidim/decidim
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow downloading only one resource in the Open Data page (decidim#13500
) Co-authored-by: Alexandru Emil Lupu <[email protected]>
- Loading branch information
1 parent
a9631b7
commit fe8de3c
Showing
24 changed files
with
524 additions
and
65 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
decidim-accountability/spec/system/download_open_data_files_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,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
require "decidim/core/test/shared_examples/download_open_data_shared_context" | ||
require "decidim/core/test/shared_examples/download_open_data_shared_examples" | ||
|
||
describe "Download Open Data files", download: true do | ||
let(:organization) { create(:organization) } | ||
|
||
include_context "when downloading open data files" | ||
|
||
it "lets the users download open data files" do | ||
download_open_data_file | ||
|
||
expect(File.basename(download_path)).to include("open-data.zip") | ||
Zip::File.open(download_path) do |zipfile| | ||
expect(zipfile.glob("*open-data-results.csv").length).to eq(1) | ||
end | ||
end | ||
|
||
describe "results" do | ||
let(:file_name) { "open-data-results.csv" } | ||
|
||
context "when there is none" do | ||
it "returns an empty file" do | ||
download_open_data_file | ||
content = extract_content_from_zip(download_path, file_name) | ||
expect(content).to eq("\n") | ||
end | ||
end | ||
|
||
context "when the result's component is unpublished" do | ||
let!(:result) { create(:result, component:) } | ||
let(:resource_title) { translated_attribute(result.title).gsub('"', '""') } | ||
let(:component) { create(:accountability_component, :unpublished, organization:) } | ||
|
||
it_behaves_like "does not include it in the open data ZIP file" | ||
end | ||
|
||
context "when the result's component is published" do | ||
let!(:result) { create(:result, component:) } | ||
let(:resource_title) { translated_attribute(result.title).gsub('"', '""') } | ||
let(:component) { create(:accountability_component, organization:) } | ||
|
||
it_behaves_like "includes it in the open data ZIP file" | ||
end | ||
end | ||
|
||
describe "open data page" do | ||
let(:resource_type) { "results" } | ||
let!(:result) { create(:result, component:) } | ||
let(:component) { create(:accountability_component, organization:) } | ||
let(:resource_title) { translated_attribute(result.title).gsub('"', '""') } | ||
|
||
it_behaves_like "includes it in the open data CSV file" | ||
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
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
57 changes: 57 additions & 0 deletions
57
decidim-budgets/spec/system/download_open_data_files_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,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
require "decidim/core/test/shared_examples/download_open_data_shared_context" | ||
require "decidim/core/test/shared_examples/download_open_data_shared_examples" | ||
|
||
describe "Download Open Data files", download: true do | ||
let(:organization) { create(:organization) } | ||
|
||
include_context "when downloading open data files" | ||
|
||
it "lets the users download open data files" do | ||
download_open_data_file | ||
|
||
expect(File.basename(download_path)).to include("open-data.zip") | ||
Zip::File.open(download_path) do |zipfile| | ||
expect(zipfile.glob("*open-data-projects.csv").length).to eq(1) | ||
end | ||
end | ||
|
||
describe "projects" do | ||
let(:file_name) { "open-data-projects.csv" } | ||
|
||
context "when there is none" do | ||
it "returns an empty file" do | ||
download_open_data_file | ||
content = extract_content_from_zip(download_path, file_name) | ||
expect(content).to eq("\n") | ||
end | ||
end | ||
|
||
context "when the project's component is unpublished" do | ||
let!(:project) { create(:project, component:) } | ||
let(:resource_title) { translated_attribute(project.title).gsub('"', '""') } | ||
let(:component) { create(:budgets_component, :unpublished, organization:) } | ||
|
||
it_behaves_like "does not include it in the open data ZIP file" | ||
end | ||
|
||
context "when the project's component is published" do | ||
let!(:project) { create(:project, component:) } | ||
let(:resource_title) { translated_attribute(project.title).gsub('"', '""') } | ||
let(:component) { create(:budgets_component, organization:) } | ||
|
||
it_behaves_like "includes it in the open data ZIP file" | ||
end | ||
end | ||
|
||
describe "open data page" do | ||
let(:resource_type) { "projects" } | ||
let!(:project) { create(:project, component:) } | ||
let(:component) { create(:budgets_component, organization:) } | ||
let(:resource_title) { translated_attribute(project.title).gsub('"', '""') } | ||
|
||
it_behaves_like "includes it in the open data CSV file" | ||
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
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
Oops, something went wrong.