spec/unit/yaks/mapper/form_spec.rb in yaks-0.8.3 vs spec/unit/yaks/mapper/form_spec.rb in yaks-0.9.0
- old
+ new
@@ -12,19 +12,19 @@
media_type: 'application/hal+json',
fields: fields
}
}
let(:fields) { [] }
+ let(:mapper) { Yaks::Mapper.new(yaks_context) }
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) {
[
@@ -49,9 +49,33 @@
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
+
+ describe '#to_resource_form' do
+ context 'with dynamic elements' do
+ let(:form) do
+ described_class.create(name) do
+ dynamic do |object|
+ text object.name
+ end
+ end
+ end
+
+ it 'should render them based on the mapped object' do
+ mapper.call(fake(name: :anthony)) # hack to set the mapper's object
+ expect(form.to_resource_form(mapper)).to eql(
+ Yaks::Resource::Form.new(
+ name: :the_name,
+ fields: [
+ Yaks::Resource::Form::Field.new(name: :anthony, type: :text)
+ ]
+ )
+ )
+ end
end
end
end
end