Sha256: 1362450f3180dea157666c18879c2b040f54e7a8bf60b55d89d7d3c92e84c2aa

Contents?: true

Size: 1.63 KB

Versions: 7

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'

describe Locomotive::Steam::ContentType do

  let(:fields) { [instance_double('Field1', label: 'Title', name: :title, localized: false), instance_double('Field2', label: 'Author', name: :author, localized: true)] }
  let(:repository) { instance_double('FieldRepository', all: fields, first: fields.first, find: nil) }
  let(:content_type) { described_class.new(name: 'Articles') }

  before { allow(content_type).to receive(:fields).and_return(repository) }

  describe '#label_field_name' do

    subject { content_type.label_field_name }
    it { is_expected.to eq :title }

    context 'defined within the content type itself' do

      before { allow(content_type.attributes).to receive(:[]).with(:label_field_name).and_return('author') }
      it { is_expected.to eq :author }

    end

  end

  describe '#fields_by_name' do

    subject { content_type.fields_by_name }
    it { expect(subject.keys).to eq ['title', 'author'] }
    it { expect(subject[:title]).to eq(subject['title']) }

  end

  describe '#order_by' do

    subject { content_type.order_by }
    it { is_expected.to eq(_position: 'asc') }

    context 'specifying manually' do

      before do
        content_type.attributes[:order_by] = 'manually'
        content_type.attributes[:order_direction] = 'desc'
      end
      it { is_expected.to eq(_position: 'desc') }

    end

    context 'order_by references an id of a field' do

      let(:field) { instance_double('Field', name: 'title') }
      let(:repository) { instance_double('FieldRepository', all: fields, first: fields.first, find: field) }

      it { is_expected.to eq(title: 'asc') }

    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
locomotivecms_steam-1.0.0.pre.beta.3 spec/unit/entities/content_type_spec.rb
locomotivecms_steam-1.0.0.pre.beta.2 spec/unit/entities/content_type_spec.rb
locomotivecms_steam-1.0.0.pre.beta.1 spec/unit/entities/content_type_spec.rb
locomotivecms_steam-1.0.0.pre.alpha.3 spec/unit/entities/content_type_spec.rb
locomotivecms_steam-1.0.0.pre.alpha.2 spec/unit/entities/content_type_spec.rb
locomotivecms_steam-1.0.0.pre.alpha.1 spec/unit/entities/content_type_spec.rb
locomotivecms_steam-1.0.0.pre.alpha spec/unit/entities/content_type_spec.rb