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

Add deprecated attribute to elements and contents #30

Merged
merged 2 commits into from
Jan 21, 2021
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
5 changes: 5 additions & 0 deletions app/serializers/alchemy/json_api/element_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class ElementSerializer
:created_at,
:updated_at,
)

attribute :deprecated do |element|
!!element.definition[:deprecated]
end

belongs_to :parent_element, record_type: :element, serializer: self

belongs_to :page, record_type: :page, serializer: ::Alchemy::JsonApi::PageSerializer
Expand Down
3 changes: 3 additions & 0 deletions lib/alchemy/json_api/essence_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def self.included(klass)
klass.attribute :role do |essence|
essence.content.name
end
klass.attribute :deprecated do |essence|
!!essence.content.definition[:deprecated]
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

it "has the right keys and values" do
expect(subject).to have_key(:ingredient)
expect(subject[:deprecated]).to be(false)
end

context "a deprecated content" do
let(:content) { FactoryBot.create(:alchemy_content, name: "intro", element: element) }

it "has deprecated attribute set to true" do
expect(subject[:deprecated]).to eq(true)
end
end
end

Expand Down
4 changes: 4 additions & 0 deletions spec/dummy/config/alchemy/elements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
contents:
- name: intro
type: EssenceText
deprecated: true
- name: headline
type: EssenceText
settings:
Expand Down Expand Up @@ -160,3 +161,6 @@
fixed: true
unique: true
nestable_elements: [text]

- name: old
deprecated: true
11 changes: 11 additions & 0 deletions spec/serializers/alchemy/json_api/element_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,20 @@
expect(subject[:created_at]).to eq(element.created_at)
expect(subject[:updated_at]).to eq(element.updated_at)
expect(subject[:position]).to eq(element.position)
expect(subject[:deprecated]).to eq(false)
expect(subject.keys).not_to include(:tag_list, :display_name)
end

context "a deprecated element" do
let(:element) do
FactoryBot.create(:alchemy_element, name: "old")
end

it "has deprecated attribute set to true" do
expect(subject[:deprecated]).to eq(true)
end
end

context "with admin set to true" do
let(:options) { { params: { admin: true } } }

Expand Down