Mappings should be inherited.

This commit is contained in:
Johan Andersson 2011-01-05 20:52:49 +01:00
parent 968e9325b5
commit 7c3b42ba22
3 changed files with 31 additions and 2 deletions

View File

@ -1,7 +1,10 @@
require 'active_support/core_ext/class/attribute'
module SimpleForm
module MapType
def mappings
@mappings ||= {}
def self.extended(base)
base.class_attribute :mappings
base.mappings = {}
end
def map_type(*types)

View File

@ -9,6 +9,12 @@ class FormBuilderTest < ActionView::TestCase
end
end
def with_custom_form_for(object, *args, &block)
with_concat_custom_form_for(object) do |f|
f.input(*args, &block)
end
end
def with_button_for(object, *args)
with_concat_form_for(object) do |f|
f.button(*args)
@ -583,4 +589,10 @@ class FormBuilderTest < ActionView::TestCase
assert_select 'form ul', :count => 1
assert_select 'form ul li', :count => 3
end
# CUSTOM FORM BUILDER
test 'custom builder should inherit mappings' do
with_custom_form_for @user, :email
assert_select 'form input[type=email]#user_email.custom'
end
end

View File

@ -28,4 +28,18 @@ module MiscHelpers
def with_concat_form_for(object, &block)
concat simple_form_for(object, &block)
end
def with_concat_custom_form_for(object, &block)
concat custom_form_for(object, &block)
end
def custom_form_for(object, *args, &block)
simple_form_for(object, *(args << { :builder => CustomFormBuilder }), &block)
end
end
class CustomFormBuilder < SimpleForm::FormBuilder
def input(attribute_name, *args, &block)
super(attribute_name, *(args << { :input_html => { :class => 'custom' } }), &block)
end
end