Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/proposal serializer extends #17

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ def author_metadata
phone_number: ""
}
if proposal.creator.decidim_author_type == "Decidim::UserBaseEntity"
user = Decidim::User.find proposal.creator_author.id
begin
user = Decidim::User.find proposal.creator_author.id
rescue ActiveRecord::RecordNotFound
user = Decidim::UserGroup.find proposal.creator_author.id
end

author_metadata[:name] = user.try(:name).presence || ""
author_metadata[:nickname] = user.try(:nickname).presence || ""
Expand Down
21 changes: 21 additions & 0 deletions spec/services/decidim/proposals/proposal_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,27 @@ module Proposals
expect(serialized[:author][:phone_number]).not_to be_empty
end

context "and proposal has user_group as author" do
let!(:proposal) { create(:proposal, :user_group_author, :accepted) }

before do
proposal.coauthorships.clear
user = create(:user, organization: proposal.component.participatory_space.organization)
user_group = create(:user_group, :verified, organization: user.organization, users: [user])
proposal.coauthorships.create(author: user_group)
end

it "serializes author" do
expect(serialized).to include(:author)
end

it "data in author are not empty" do
expect(serialized[:author][:name]).not_to be_empty
expect(serialized[:author][:nickname]).not_to be_empty
expect(serialized[:author][:email]).not_to be_empty
end
end

context "when proposal was created by admin from backoffice" do
let!(:admin) { create(:user, :admin) }

Expand Down
Loading