-
Notifications
You must be signed in to change notification settings - Fork 1
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 #491 from gencat/add/author_in_export_proposals
Add authors to proposals exportation
- Loading branch information
Showing
3 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
app/decorators/lib/decidim/proposals/proposal_serializer_decorator.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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module Lib::Decidim::Proposals::ProposalSerializerDecorator | ||
def self.decorate | ||
Decidim::Proposals::ProposalSerializer.class_eval do | ||
alias_method :original_serialize, :serialize | ||
|
||
# Add authors to proposal exportation | ||
def serialize | ||
original_serialize.merge({ | ||
authors_names: proposal.authors.pluck(:name) | ||
}) | ||
end | ||
end | ||
end | ||
end | ||
|
||
::Lib::Decidim::Proposals::ProposalSerializerDecorator.decorate |
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
54 changes: 54 additions & 0 deletions
54
spec/decorators/lib/decidim/proposals/proposal_serializer_decorator_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,54 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
# rubocop:disable RSpec/MultipleMemoizedHelpers | ||
module Decidim | ||
module Proposals | ||
describe ProposalSerializer do | ||
subject do | ||
described_class.new(proposal) | ||
end | ||
|
||
let!(:proposal) { create(:proposal, :accepted, body: body) } | ||
let!(:category) { create(:category, participatory_space: component.participatory_space) } | ||
let!(:scope) { create(:scope, organization: component.participatory_space.organization) } | ||
let(:participatory_process) { component.participatory_space } | ||
let(:component) { proposal.component } | ||
|
||
let!(:meetings_component) { create(:component, manifest_name: "meetings", participatory_space: participatory_process) } | ||
let(:meetings) { create_list(:meeting, 2, :published, component: meetings_component) } | ||
|
||
let!(:proposals_component) { create(:component, manifest_name: "proposals", participatory_space: participatory_process) } | ||
let(:other_proposals) { create_list(:proposal, 2, component: proposals_component) } | ||
let(:body) { Decidim::Faker::Localized.localized { ::Faker::Lorem.sentences(number: 3).join("\n") } } | ||
|
||
let(:expected_answer) do | ||
answer = proposal.answer | ||
Decidim.available_locales.each_with_object({}) do |locale, result| | ||
result[locale.to_s] = if answer.is_a?(Hash) | ||
answer[locale.to_s] || "" | ||
else | ||
"" | ||
end | ||
end | ||
end | ||
|
||
before do | ||
proposal.update!(category: category) | ||
proposal.update!(scope: scope) | ||
proposal.link_resources(meetings, "proposals_from_meeting") | ||
proposal.link_resources(other_proposals, "copied_from_component") | ||
end | ||
|
||
describe "#serialize" do | ||
let(:serialized) { subject.serialize } | ||
|
||
it "serializes the authors names" do | ||
expect(serialized).to include(authors_names: proposal.authors.pluck(:name)) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable RSpec/MultipleMemoizedHelpers |