Sha256: 2bd89dc6ec4604e2d3f074b0e7d2c2c28aa93cda5e252121e975cbeb8e58d9bb

Contents?: true

Size: 1.44 KB

Versions: 4

Compression:

Stored size: 1.44 KB

Contents

RSpec.describe Yaks::Mapper::Form do
  include_context 'yaks context'

  let(:form)   { described_class.create( full_args ) }
  let(:name)      { :the_name }
  let(:full_args) { {name: name}.merge(args) }
  let(:args) {
    {
      action: '/foo',
      title: 'a title',
      method: 'PATCH',
      media_type: 'application/hal+json',
      fields: fields
    }
  }
  let(:fields) { [] }

  describe '.create' do
    it 'should have a name of nil when ommitted' do
      expect(described_class.create.name).to be_nil
    end
  end

  describe '#add_to_resource' do
    let(:mapper) { Yaks::Mapper.new(yaks_context) }
    let(:resource) { form.new.add_to_resource(Yaks::Resource.new, mapper, nil) }

    context 'with fields' do
      let(:fields) {
        [
          Yaks::Mapper::Form::Field.new(
            name: 'field name',
            label: 'field label',
            type: 'text',
            value: 7
          )
        ]
      }
    end

    context 'with a truthy condition' do
      let(:form) { described_class.create { condition { true }}}

      it 'should add the form' do
        expect(form.add_to_resource(Yaks::Resource.new, mapper, nil).forms.length).to be 1
      end
    end

    context 'with a falsey condition' do
      let(:form) { described_class.create { condition { false }}}

      it 'should not add the form' do
        expect(form.add_to_resource(Yaks::Resource.new, mapper, nil).forms.length).to be 0
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yaks-0.8.3 spec/unit/yaks/mapper/form_spec.rb
yaks-0.8.2 spec/unit/yaks/mapper/form_spec.rb
yaks-0.8.1 spec/unit/yaks/mapper/form_spec.rb
yaks-0.8.0 spec/unit/yaks/mapper/form_spec.rb