extended_description_serializer_spec.rb 918 B

1234567891011121314151617181920212223242526272829303132333435
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe REST::ExtendedDescriptionSerializer do
  4. subject { serialized_record_json(record, described_class) }
  5. describe 'serialization' do
  6. context 'with text present' do
  7. let(:record) { ExtendedDescription.new text: 'Hello world', updated_at: Date.new(2024, 1, 1) }
  8. it 'returns expected values' do
  9. expect(subject)
  10. .to include(
  11. 'content' => eq(<<~HTML),
  12. <p>Hello world</p>
  13. HTML
  14. 'updated_at' => eq('2024-01-01')
  15. )
  16. end
  17. end
  18. context 'with text missing' do
  19. let(:record) { ExtendedDescription.new text: nil, updated_at: Date.new(2024, 1, 1) }
  20. it 'returns expected values' do
  21. expect(subject)
  22. .to include(
  23. 'content' => eq(''),
  24. 'updated_at' => eq('2024-01-01')
  25. )
  26. end
  27. end
  28. end
  29. end