diff --git a/app/serializers/alchemy/json_api/element_serializer.rb b/app/serializers/alchemy/json_api/element_serializer.rb index 5010864..9383a71 100644 --- a/app/serializers/alchemy/json_api/element_serializer.rb +++ b/app/serializers/alchemy/json_api/element_serializer.rb @@ -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 diff --git a/lib/alchemy/json_api/essence_serializer.rb b/lib/alchemy/json_api/essence_serializer.rb index aacf410..08a1e58 100644 --- a/lib/alchemy/json_api/essence_serializer.rb +++ b/lib/alchemy/json_api/essence_serializer.rb @@ -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 diff --git a/lib/alchemy/json_api/test_support/essence_serializer_behaviour.rb b/lib/alchemy/json_api/test_support/essence_serializer_behaviour.rb index a96de6b..39f63fd 100644 --- a/lib/alchemy/json_api/test_support/essence_serializer_behaviour.rb +++ b/lib/alchemy/json_api/test_support/essence_serializer_behaviour.rb @@ -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 diff --git a/spec/dummy/config/alchemy/elements.yml b/spec/dummy/config/alchemy/elements.yml index 3d2d940..d8fd2d6 100644 --- a/spec/dummy/config/alchemy/elements.yml +++ b/spec/dummy/config/alchemy/elements.yml @@ -14,6 +14,7 @@ contents: - name: intro type: EssenceText + deprecated: true - name: headline type: EssenceText settings: @@ -160,3 +161,6 @@ fixed: true unique: true nestable_elements: [text] + +- name: old + deprecated: true diff --git a/spec/serializers/alchemy/json_api/element_serializer_spec.rb b/spec/serializers/alchemy/json_api/element_serializer_spec.rb index 17b6180..32be395 100644 --- a/spec/serializers/alchemy/json_api/element_serializer_spec.rb +++ b/spec/serializers/alchemy/json_api/element_serializer_spec.rb @@ -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 } } }