Sha256: e480ca9bd9c7c9d09d5613cba84337a2bd291640d5930ff7de559a03bf51cca9

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'

RSpec.describe Yaks::Mapper::Form do
  let(:form)   { described_class.new( 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 create an instance, first arg is the name' do

      expect( described_class.create(name, args) ).to eql form
    end

    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(:resource) { form.add_to_resource(Yaks::Resource.new, Yaks::Mapper.new(nil), nil) }

    it 'should add a form to the resource' do
      expect(resource.forms.length).to be 1
    end

    it 'should create a Yaks::Resource::Form with corresponding fields' do
      expect(resource.forms.first).to eql Yaks::Resource::Form.new( full_args )
    end

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

      it 'should map to Yaks::Resource::Form::Field instances' do
        expect(resource.forms.first.fields).to eql [
          Yaks::Resource::Form::Field.new(
            name: 'field name',
            label: 'field label',
            type: 'text',
            value: 7
          )
        ]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yaks-0.7.7 spec/unit/yaks/mapper/form_spec.rb