Sha256: 0fa6796c7a20c820536da3abca6b6fb7f7518994751e64e8d9c7ed6b804c2617

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

require 'brightcontent/view_lookup/abstract'

module Brightcontent::ViewLookup
  describe Abstract do
    class FakeFormField < Abstract
      def field_type
        :string
      end
    end

    let(:view_context) { double(:view_context) }
    let(:item) { double(:item, name: 'Item name') }
    let(:fake_form_field) { FakeFormField.new(view_context, field: 'name', item: item) }

    context 'with specific field partial' do
      it 'renders the parial' do
        expect(view_context).to receive(:render_if_exists)
          .with("fake_form_field_name", {field: 'name', item: item}) { "Result" }
        fake_form_field.call
      end
    end

    context 'with specific field type partial' do
      it 'renders the parial' do
        expect(view_context).to receive(:render_if_exists).once
        expect(view_context).to receive(:render_if_exists)
          .with("brightcontent/base/fake_form_fields/string", {field: 'name', item: item}) { "Result" }
        fake_form_field.call
      end
    end

    context 'without partial' do
      it 'renders the default value' do
        expect(view_context).to receive(:render_if_exists).once
        allow(fake_form_field).to receive(:field_type) { nil }
        expect(fake_form_field.call).to eq 'Item name'
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
brightcontent-core-2.1.1 spec/lib/brightcontent/view_lookup/abstract_spec.rb
brightcontent-core-2.1.0 spec/lib/brightcontent/view_lookup/abstract_spec.rb