forked from decidim/decidim
-
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.
Add Taxonomies to open data file (decidim#13846)
- Loading branch information
1 parent
2d639be
commit 7fd9478
Showing
6 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
decidim-core/app/serializers/decidim/exporters/open_data_taxonomy_serializer.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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Exporters | ||
class OpenDataTaxonomySerializer < Decidim::Exporters::Serializer | ||
# Public: Initializes the serializer with a resource | ||
def initialize(resource) | ||
@resource = resource | ||
end | ||
|
||
# Public: Exports a hash with the serialized data for this resource. | ||
def serialize | ||
{ | ||
id: resource.id, | ||
name: resource.name, | ||
parent_id: resource.parent_id, | ||
weight: resource.weight, | ||
children_count: resource.children_count, | ||
taxonomizations_count: resource.taxonomizations_count, | ||
created_at: resource.created_at, | ||
updated_at: resource.updated_at, | ||
filters_count: resource.filters_count, | ||
filter_items_count: resource.filter_items_count, | ||
part_of: resource.part_of, | ||
is_root: resource.root? | ||
} | ||
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
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
62 changes: 62 additions & 0 deletions
62
decidim-core/spec/serializers/decidim/exporters/open_data_taxonomy_serializer_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,62 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
module Decidim::Exporters | ||
describe OpenDataTaxonomySerializer do | ||
subject { described_class.new(resource) } | ||
|
||
let(:resource) { create(:taxonomy) } | ||
let(:serialized) { subject.serialize } | ||
|
||
describe "#serialize" do | ||
it "includes the id" do | ||
expect(serialized).to include(id: resource.id) | ||
end | ||
|
||
it "includes the name" do | ||
expect(serialized).to include(name: resource.name) | ||
end | ||
|
||
it "includes the parent_id" do | ||
expect(serialized).to include(parent_id: resource.parent_id) | ||
end | ||
|
||
it "includes the weight" do | ||
expect(serialized).to include(weight: resource.weight) | ||
end | ||
|
||
it "includes the children_count" do | ||
expect(serialized).to include(children_count: resource.children_count) | ||
end | ||
|
||
it "includes the taxonomizations_count" do | ||
expect(serialized).to include(taxonomizations_count: resource.taxonomizations_count) | ||
end | ||
|
||
it "includes the created_at" do | ||
expect(serialized).to include(created_at: resource.created_at) | ||
end | ||
|
||
it "includes the updated_at" do | ||
expect(serialized).to include(updated_at: resource.updated_at) | ||
end | ||
|
||
it "includes the filters_count" do | ||
expect(serialized).to include(filters_count: resource.filters_count) | ||
end | ||
|
||
it "includes the filter_items_count" do | ||
expect(serialized).to include(filter_items_count: resource.filter_items_count) | ||
end | ||
|
||
it "includes the part_of" do | ||
expect(serialized).to include(part_of: resource.part_of) | ||
end | ||
|
||
it "includes the is_root" do | ||
expect(serialized).to include(is_root: resource.root?) | ||
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