require 'test_helper' module ExpressAdmin class SmartFormTest < ActiveSupport::TestCase def compiled_widget_form(*args) ExpressAdmin::SmartForm.new(:widget, *args).compile end test "renders a form correct id" do assert_match '
', compiled_widget_form end test 'path prefix is provided' do action_attrib = 'action=\"{{@widget.try(:persisted?) ? admin_widget_path(@widget) : admin_widgets_path}}\"' assert_match action_attrib, compiled_widget_form(path_prefix: 'admin') end test "options_from_collection_for_select used for the related collection" do assert_match 'options_from_collection_for_select(Category.all.select(:id, :name).order(:name)', compiled_widget_form end test "options_from_collection_for_select use when a namespace is specified" do assert_match 'options_from_collection_for_select(ExampleEngine::Category.all.select(:id, :name).order(:name)', compiled_widget_form(namespace: "example_engine") end test "collection_select with collection_ids is used for has_many_through associations" do assert_match /collection_select.*tag_ids.*multiple: true/, compiled_widget_form end test "excluded fields are excluded" do refute_match 'column3', compiled_widget_form(exclude: [:column3]) end test "virtual attributes may be included" do assert_match 'password', compiled_widget_form(virtual: [:password]) end end end