Skip to content

Commit

Permalink
Add SimpleFormBuilder spec
Browse files Browse the repository at this point in the history
It checks if SimpleForm#input method is callable.
And checks for correct wrapping of a normal text field.
  • Loading branch information
abinoam committed Apr 8, 2024
1 parent a468821 commit 7c8985a
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions spec/ransack/helpers/simple_form_builder_spec.rb
Original file line number Diff line number Diff line change
@@ -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.*?><label.*?<\/label>.*?<input.*?\/>.*?<\/div>/)
end

it "the wrapping div should have class 'q_name_cont'" do
expect(subject).to match(/<div.*?class=".*?q_name_cont.*?".*?>/)
end

it "should generate correct label text with predicate from locale files" do
expect(subject).to match(/<label.*?>.*?Full Name contains.*?<\/label>/)
end

it "should generate correct input name=\"q[name_cont]\"" do
expect(subject).to match(/<input.*?name="q\[name_cont\]".*?\/>/)
end

it "should generate correct input id=\"q_name_cont\"" do
expect(subject).to match(/<input.*?id="q_name_cont".*?\/>/)
end

it "should generate correct input type=\"text\"" do
expect(subject).to match(/<input.*?type="text".*?\/>/)
end
end
end
end
end
end

0 comments on commit 7c8985a

Please sign in to comment.