spec/unit/yaks/mapper/form/field_spec.rb in yaks-0.9.0 vs spec/unit/yaks/mapper/form/field_spec.rb in yaks-0.10.0
- old
+ new
@@ -1,9 +1,9 @@
RSpec.describe Yaks::Mapper::Form::Field do
include_context 'yaks context'
- let(:field) { described_class.new( full_args ) }
+ let(:field) { described_class.new(full_args) }
let(:name) { :the_field }
let(:full_args) { {name: name, options: options}.merge(args) }
let(:options) { [] }
let(:args) {
{
@@ -13,11 +13,13 @@
}
}
let(:mapper) do
Class.new(Yaks::Mapper) do
- def month ; 'January' ; end
+ def month
+ 'January'
+ end
end.new(yaks_context)
end
describe '.create' do
it 'can take all args as a hash' do
@@ -87,8 +89,47 @@
type: "text",
value: "hello"
)
expect(field.to_resource_fields(mapper)).to eql [form_field]
end
+ end
+ end
+
+ describe "#resource_options" do
+ context "when empty" do
+ it "should always be the same identical object" do
+ opt1 = described_class.new(name: :foo).resource_options(mapper)
+ opt2 = described_class.new(name: :bar).resource_options(mapper)
+ expect(opt1).to eql []
+ expect(opt1).to equal opt2
+ end
+ end
+
+ context "with select options" do
+ let(:options) do
+ [
+ Yaks::Mapper::Form::Field::Option.new(value: 0, label: "zero"),
+ Yaks::Mapper::Form::Field::Option.new(value: 1, label: "one"),
+ Yaks::Mapper::Form::Field::Option.new(value: 2, label: "two", if: ->{ false })
+ ]
+ end
+
+ it "should map to Resource::Field::Option instances" do
+ expect(field.resource_options(mapper))
+ .to eql [
+ Yaks::Resource::Form::Field::Option.new(value: 0, label: "zero"),
+ Yaks::Resource::Form::Field::Option.new(value: 1, label: "one")
+ ]
+ end
+ end
+ end
+
+ describe "#resource_attributes" do
+ it "should have all the HTML form field attributes" do
+ expect(field.resource_attributes).to eql [
+ :name, :label, :type, :required, :rows, :value, :pattern,
+ :maxlength, :minlength, :size, :readonly, :multiple, :min,
+ :max, :step, :list, :placeholder, :checked, :disabled
+ ]
end
end
end