Sha256: 06459ef8a7a185e8e09a8326e8ca59c7d8505cf17606a79ef6e5af20564eee14

Contents?: true

Size: 1.72 KB

Versions: 83

Compression:

Stored size: 1.72 KB

Contents

require 'spec_helper'

describe Tenon::HasHistory::AttrSerializer do
  let(:serializer) { Tenon::HasHistory::AttrSerializer.new(attrs, item_version) }
  let(:item_version) { Tenon::ItemVersion.new(item: item) }
  let(:item) { create(:page) }

  context '#serialize' do
    context 'with basic attrs' do
      let(:attrs) { predefined_attrs[:basic] }

      it 'should clear out the ID' do
        expect(serializer.serialize).to eq(Marshal.dump(title: 'Title'))
      end
    end

    context 'when the attrs have excepted fields' do
      let(:attrs) { predefined_attrs[:with_excepted] }

      it 'should clear out the ID' do
        expect(serializer.serialize).to eq(Marshal.dump(title: 'Title'))
      end
    end

    context 'when the attrs have children that are not included' do
      let(:attrs) { predefined_attrs[:unincluded_children] }

      it 'should clear them out' do
        expect(serializer.serialize).to eq(Marshal.dump(title: 'Title'))
      end
    end

    context 'when the attrs have children that are included' do
      let(:attrs) { predefined_attrs[:included_children] }

      it 'should keep them' do
        expected = Marshal.dump(attrs.deep_reject_key!(:id))
        expect(serializer.serialize).to eq(expected)
      end
    end
  end
end

def predefined_attrs
  {
    basic: { title: 'Title', id: 14 },
    with_excepted: { title: 'Title', lft: 3, rgt: 5, depth: 6 },
    unincluded_children: {
      title: 'Title',
      fake_children_attributes: {
        first: { test: 'item' },
        second: { test: 'item' }
      }
    },
    included_children: {
      title: 'Title',
      content_tenon_content_rows_attributes: {
        first: { foo: 'bar', id: 1 },
        second: { foo: 'bar', id: 2 }
      }
    }
  }
end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
tenon-1.1.8 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.1.7 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.1.6 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.1.5 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.1.4 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.1.3 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.1.2 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.1.1 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.0.76 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.0.75 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.0.74 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.0.73 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.0.72 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.0.71 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.0.70 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.0.69 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.0.68 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.0.67 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.0.66 spec/lib/tenon/has_history/attr_serializer_spec.rb
tenon-1.0.65 spec/lib/tenon/has_history/attr_serializer_spec.rb