Skip to content

Commit

Permalink
Merge pull request #30 from AlchemyCMS/re-add-deprecated-attribute
Browse files Browse the repository at this point in the history
Add deprecated attribute to elements and contents
  • Loading branch information
tvdeyen authored Jan 21, 2021
2 parents d48fab3 + 8f59fd7 commit d81d885
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
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

0 comments on commit d81d885

Please sign in to comment.