Sha256: 3351118d6317f96ceca8dadbc9952b8e31e607c775b3b7a390d2c672999b2240

Contents?: true

Size: 1.42 KB

Versions: 8

Compression:

Stored size: 1.42 KB

Contents

RSpec.describe 'dynamic form fields' do
  let(:mapper) do
    Class.new(Yaks::Mapper) do
      type :awesome
      form :foo do
        fieldset do
          legend "I am legend"
          text :bar
        end
      end
    end
  end

  let(:yaks) { Yaks.new }

  it 'should create fieldsets with fields' do
    expect(yaks.map(:foo, mapper: mapper)).to eql Yaks::Resource.new(
      type: :awesome,
      forms: [
        Yaks::Resource::Form.new(
          name: :foo,
          fields: [
            Yaks::Resource::Form::Fieldset.new(
              fields: [
                Yaks::Resource::Form::Field.new(name: "I am legend", type: :legend),
                Yaks::Resource::Form::Field.new(name: :bar, type: :text)
              ]
            )
          ]
        )
      ]
    )
  end

  it 'should convert to halo' do
    expect(
      yaks.with(default_format: :halo, hooks: [[:skip, :serialize]]).call(:foo, mapper: mapper)
    ).to eql(
      {
        "_controls" => {
          "foo" => {
            "name" =>"foo",
            "fields" => [
              {
                "type" => "fieldset",
                "fields" => [
                  {
                    "name" => "I am legend",
                    "type" => "legend"
                  }, {
                    "name" => "bar",
                    "type" => "text"
                  }
                ]
              }
            ]
          }
        }
      }
    )
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
yaks-0.9.0 spec/integration/fieldset_spec.rb
yaks-0.8.3 spec/integration/fieldset_spec.rb
yaks-0.8.2 spec/integration/fieldset_spec.rb
yaks-0.8.1 spec/integration/fieldset_spec.rb
yaks-0.8.0 spec/integration/fieldset_spec.rb
yaks-0.8.0.beta2 spec/integration/fieldset_spec.rb
yaks-0.8.0.beta1 spec/integration/fieldset_spec.rb
yaks-0.8.0.alpha spec/integration/fieldset_spec.rb