From 7c8985a9596bb567e51086aad981aeb9ffd2de4f Mon Sep 17 00:00:00 2001 From: "Abinoam P. Marques Jr" Date: Mon, 8 Apr 2024 13:55:01 -0300 Subject: [PATCH] Add SimpleFormBuilder spec It checks if SimpleForm#input method is callable. And checks for correct wrapping of a normal text field. --- .../helpers/simple_form_builder_spec.rb | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 spec/ransack/helpers/simple_form_builder_spec.rb diff --git a/spec/ransack/helpers/simple_form_builder_spec.rb b/spec/ransack/helpers/simple_form_builder_spec.rb new file mode 100644 index 00000000..21825aec --- /dev/null +++ b/spec/ransack/helpers/simple_form_builder_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +module Ransack + module Helpers + describe SimpleFormBuilder do + + router = ActionDispatch::Routing::RouteSet.new + router.draw do + resources :people, :comments, :notes + end + + include router.url_helpers + + # FIXME: figure out a cleaner way to get this behavior + before do + @controller = ActionView::TestCase::TestController.new + @controller.instance_variable_set(:@_routes, router) + @controller.class_eval { include router.url_helpers } + @controller.view_context_class.class_eval { include router.url_helpers } + @s = Person.ransack + @controller.view_context.search_simple_form_for(@s) { |f| @f = f } + end + + describe "#input (from SimpleForm)" do + context "with :name_cont predicate" do + subject { @f.input(:name_cont) } + + it "should generate a wrapping div with both label and input inside" do + expect(subject).to match(/.*?.*?<\/div>/) + end + + it "the wrapping div should have class 'q_name_cont'" do + expect(subject).to match(//) + end + + it "should generate correct label text with predicate from locale files" do + expect(subject).to match(/.*?Full Name contains.*?<\/label>/) + end + + it "should generate correct input name=\"q[name_cont]\"" do + expect(subject).to match(//) + end + + it "should generate correct input id=\"q_name_cont\"" do + expect(subject).to match(//) + end + + it "should generate correct input type=\"text\"" do + expect(subject).to match(//) + end + end + end + end + end +end