-
-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CSV & JSON export function fix (#11186)
* CSV/JSON export function fix * Added change to permissions.rb/initiatives to allow export * export_controller_spec.rb added for elections/voting and Initiatives Co-authored-by: Tom <101816158+greenwoodt@users.noreply.github.com>
- Loading branch information
1 parent
99f4839
commit ace88bd
Showing
6 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
decidim-elections/app/controllers/decidim/votings/admin/exports_controller.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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Votings | ||
module Admin | ||
# This controller allows exporting things. | ||
# It is targeted for customizations for exporting things that lives under | ||
# a participatory process. | ||
class ExportsController < Decidim::Admin::ExportsController | ||
include VotingAdmin | ||
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
53 changes: 53 additions & 0 deletions
53
decidim-elections/spec/controllers/decidim/votings/exports_controller_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,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
module Decidim | ||
module Votings | ||
module Admin | ||
describe ExportsController, type: :controller do | ||
routes { Decidim::Votings::AdminEngine.routes } | ||
|
||
let!(:organization) { create(:organization) } | ||
let!(:voting) { create(:voting, organization: organization) } | ||
let!(:user) { create(:user, :admin, :confirmed, organization: organization) } | ||
let!(:component) { create(:component, participatory_space: voting, manifest_name: "dummy") } | ||
|
||
let(:params) do | ||
{ | ||
id: "dummies", | ||
component_id: component.id, | ||
voting_slug: voting.slug | ||
} | ||
end | ||
|
||
before do | ||
request.env["decidim.current_organization"] = organization | ||
sign_in user, scope: :user | ||
end | ||
|
||
describe "POST create" do | ||
context "when a format is provided" do | ||
it "enqueues a job with the provided format" do | ||
params[:format] = "csv" | ||
|
||
expect(ExportJob).to receive(:perform_later) | ||
.with(user, component, "dummies", "csv", nil) | ||
|
||
post(:create, params: params) | ||
end | ||
end | ||
|
||
context "when a format is not provided" do | ||
it "enqueues a job with the default format" do | ||
expect(ExportJob).to receive(:perform_later) | ||
.with(user, component, "dummies", "json", nil) | ||
|
||
post(:create, params: params) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
decidim-initiatives/app/controllers/decidim/initiatives/admin/exports_controller.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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Initiatives | ||
module Admin | ||
# This controller allows exporting things. | ||
# It is targeted for customizations for exporting things that lives under | ||
# a participatory process. | ||
class ExportsController < Decidim::Admin::ExportsController | ||
include InitiativeAdmin | ||
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
53 changes: 53 additions & 0 deletions
53
decidim-initiatives/spec/controllers/decidim/initiatives/admin/exports_controller_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,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
module Decidim | ||
module Initiatives | ||
module Admin | ||
describe ExportsController, type: :controller do | ||
routes { Decidim::Initiatives::AdminEngine.routes } | ||
|
||
let!(:organization) { create(:organization) } | ||
let!(:initiative) { create(:initiative, organization: organization) } | ||
let!(:user) { create(:user, :admin, :confirmed, organization: organization) } | ||
let!(:component) { create(:component, participatory_space: initiative, manifest_name: "dummy") } | ||
|
||
let(:params) do | ||
{ | ||
id: "dummies", | ||
component_id: component.id, | ||
initiative_slug: initiative.slug | ||
} | ||
end | ||
|
||
before do | ||
request.env["decidim.current_organization"] = organization | ||
sign_in user, scope: :user | ||
end | ||
|
||
describe "POST create" do | ||
context "when a format is provided" do | ||
it "enqueues a job with the provided format" do | ||
params[:format] = "csv" | ||
|
||
expect(ExportJob).to receive(:perform_later) | ||
.with(user, component, "dummies", "csv", nil) | ||
|
||
post(:create, params: params) | ||
end | ||
end | ||
|
||
context "when a format is not provided" do | ||
it "enqueues a job with the default format" do | ||
expect(ExportJob).to receive(:perform_later) | ||
.with(user, component, "dummies", "json", nil) | ||
|
||
post(:create, params: params) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |