require 'test_helper' class BasicFieldsTest < ActiveSupport::TestCase BASIC_FIELDS = %w(email phone text password color date datetime datetime_local number range search telephone time url week) def assigns {resource: resource} end def field_type_map Hash[BASIC_FIELDS.map {|f| [f, f]}].merge( {'phone' => 'tel', 'telephone' => 'tel', 'datetime_local' => 'datetime-local' }) end def label_html '' end test "all fields work" do BASIC_FIELDS.each do |type| fragment = -> (ctx) { express_form(:foo) { send(type, :bar) } } html = arbre(&fragment) assert_match label_html, html assert_match(/input.*type="#{field_type_map[type]}"/, html) # assert_match "#{type}_field(:foo, :bar, {})", arbre(&fragment) end end test "passing html options to fields work" do options = {class: 'form-field'} BASIC_FIELDS.each do |type| html = arbre { express_form(:foo) { send(type, :bar, options) } } assert_match label_html, html assert_match /input.*type="#{field_type_map[type]}"/, html assert_match /input.*class="form-field"/, html end end test "textarea uses rails text_area helper" do html = arbre { express_form(:foo) { textarea :bar } } assert_match label_html, html assert_match /