Sha256: d104bb0d4a2bbfe83d9ad3f0016b09d742273cbdccfade77fb5917aca1db5933

Contents?: true

Size: 1.82 KB

Versions: 13

Compression:

Stored size: 1.82 KB

Contents

require 'spec_helper'

require_relative '../../../../../lib/locomotive/steam/adapters/filesystem/yaml_loader.rb'
require_relative '../../../../../lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb'

describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentEntry do

  let(:site_path)     { default_fixture_site_path }
  let(:content_type)  { instance_double('Bands', _id: 42, slug: 'bands', association_fields: [], select_fields: []) }
  let(:scope)         { instance_double('Scope', locale: :en, context: { content_type: content_type }) }
  let(:loader)        { described_class.new(site_path) }

  describe '#load' do

    subject { loader.load(scope).sort { |a, b| a[:_label] <=> b[:_label] } }

    it 'tests various stuff' do
      expect(subject.size).to eq 3
      expect(subject.first[:_label]).to eq 'Alice in Chains'
      expect(subject.first[:content_type]).to eq nil
    end

    context 'a content type with a belongs_to field' do

      let(:field)         { instance_double('Field', name: 'band', type: :belongs_to) }
      let(:content_type)  { instance_double('Songs', slug: 'songs', association_fields: [field], select_fields: []) }

      it 'adds a new attribute for the foreign key' do
        expect(subject.first[:band_id]).to eq 'pearl-jam'
        expect(subject.first[:band]).to eq nil
        expect(subject.first[:position_in_band]).to eq 0
      end

    end

    context 'a content type with a select field' do

      let(:field)         { instance_double('Field', name: 'kind', type: :select) }
      let(:content_type)  { instance_double('Bands', slug: 'bands', select_fields: [field], association_fields: []) }

      it 'adds a new attribute for the foreign key' do
        expect(subject.first[:kind_id]).to eq 'grunge'
        expect(subject.first[:kind]).to eq nil
      end

    end

  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
locomotivecms_steam-1.0.1 spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb
locomotivecms_steam-1.0.0 spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb
locomotivecms_steam-1.0.0.rc10 spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb
locomotivecms_steam-1.0.0.rc9 spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb
locomotivecms_steam-1.0.0.rc8 spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb
locomotivecms_steam-1.0.0.rc6 spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb
locomotivecms_steam-1.0.0.rc4 spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb
locomotivecms_steam-1.0.0.rc3 spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb
locomotivecms_steam-1.0.0.rc2 spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb
locomotivecms_steam-1.0.0.rc1 spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb
locomotivecms_steam-1.0.0.pre.beta.3 spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb
locomotivecms_steam-1.0.0.pre.beta.2 spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb
locomotivecms_steam-1.0.0.pre.beta.1 spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb