File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed
actionview/lib/action_view/helpers
railties/test/application Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -1935,6 +1935,8 @@ def nested_child_index(name)
19351935 end
19361936
19371937 ActiveSupport . on_load ( :action_view ) do
1938- cattr_accessor ( :default_form_builder ) { ::ActionView ::Helpers ::FormBuilder }
1938+ cattr_accessor ( :default_form_builder , instance_writer : false , instance_reader : false ) do
1939+ ::ActionView ::Helpers ::FormBuilder
1940+ end
19391941 end
19401942end
Original file line number Diff line number Diff line change @@ -494,6 +494,45 @@ def index
494494 assert last_response . body =~ /csrf\- param/
495495 end
496496
497+ test "default form builder specified as a string" do
498+
499+ app_file 'config/initializers/form_builder.rb' , <<-RUBY
500+ class CustomFormBuilder < ActionView::Helpers::FormBuilder
501+ def text_field(attribute, *args)
502+ label(attribute) + super(attribute, *args)
503+ end
504+ end
505+ Rails.configuration.action_view.default_form_builder = "CustomFormBuilder"
506+ RUBY
507+
508+ app_file 'app/models/post.rb' , <<-RUBY
509+ class Post
510+ include ActiveModel::Model
511+ attr_accessor :name
512+ end
513+ RUBY
514+
515+
516+ app_file 'app/controllers/posts_controller.rb' , <<-RUBY
517+ class PostsController < ApplicationController
518+ def index
519+ render inline: "<%= begin; form_for(Post.new) {|f| f.text_field(:name)}; rescue => e; e.to_s; end %>"
520+ end
521+ end
522+ RUBY
523+
524+ add_to_config <<-RUBY
525+ routes.prepend do
526+ resources :posts
527+ end
528+ RUBY
529+
530+ require "#{ app_path } /config/environment"
531+
532+ get "/posts"
533+ assert_match ( /label/ , last_response . body )
534+ end
535+
497536 test "default method for update can be changed" do
498537 app_file 'app/models/post.rb' , <<-RUBY
499538 class Post
You can’t perform that action at this time.
0 commit comments