spec/unit/yaks/mapper/form_spec.rb in yaks-0.8.0.beta2 vs spec/unit/yaks/mapper/form_spec.rb in yaks-0.8.0
- old
+ new
@@ -1,6 +1,8 @@
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) {
{
@@ -18,13 +20,13 @@
expect(described_class.create.name).to be_nil
end
end
describe '#add_to_resource' do
- let(:resource) { form.new.add_to_resource(Yaks::Resource.new, Yaks::Mapper.new(nil), nil) }
+ 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',
@@ -32,9 +34,25 @@
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