Merge branch 'issue-355'
Conflicts: test/form_builder/general_test.rb
This commit is contained in:
commit
cb691edfe2
|
@ -0,0 +1,16 @@
|
||||||
|
# TODO: Delete this file when we drop support for Rails 3.0
|
||||||
|
# This method is already implemented in active_support 3.1
|
||||||
|
|
||||||
|
unless Hash.new.respond_to?(:deep_dup)
|
||||||
|
class Hash
|
||||||
|
# Returns a deep copy of hash.
|
||||||
|
def deep_dup
|
||||||
|
duplicate = self.dup
|
||||||
|
duplicate.each_pair do |k,v|
|
||||||
|
tv = duplicate[k]
|
||||||
|
duplicate[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_dup : v
|
||||||
|
end
|
||||||
|
duplicate
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'simple_form/core_ext/hash'
|
||||||
|
|
||||||
module SimpleForm
|
module SimpleForm
|
||||||
class FormBuilder < ActionView::Helpers::FormBuilder
|
class FormBuilder < ActionView::Helpers::FormBuilder
|
||||||
attr_reader :template, :object_name, :object, :wrapper
|
attr_reader :template, :object_name, :object, :wrapper
|
||||||
|
@ -98,7 +100,7 @@ module SimpleForm
|
||||||
# given SimpleForm.time_zone_priority and SimpleForm.country_priority are used respectivelly.
|
# given SimpleForm.time_zone_priority and SimpleForm.country_priority are used respectivelly.
|
||||||
#
|
#
|
||||||
def input(attribute_name, options={}, &block)
|
def input(attribute_name, options={}, &block)
|
||||||
options = @defaults.deep_merge(options) if @defaults
|
options = @defaults.deep_dup.deep_merge(options) if @defaults
|
||||||
|
|
||||||
chosen =
|
chosen =
|
||||||
if name = options[:wrapper]
|
if name = options[:wrapper]
|
||||||
|
|
|
@ -287,6 +287,16 @@ class FormBuilderTest < ActionView::TestCase
|
||||||
assert_select 'input.default_class#specific_id'
|
assert_select 'input.default_class#specific_id'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'builder should receive a default argument and pass it to the inputs without changing the defaults' do
|
||||||
|
with_concat_form_for @user, :defaults => { :input_html => { :class => 'default_class', :id => 'default_id' } } do |f|
|
||||||
|
concat(f.input :name)
|
||||||
|
concat(f.input :credit_limit)
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_select "input.string.default_class[name='user[name]']"
|
||||||
|
assert_no_select "input.string[name='user[credit_limit]']"
|
||||||
|
end
|
||||||
|
|
||||||
# WITHOUT OBJECT
|
# WITHOUT OBJECT
|
||||||
test 'builder should generate properly when object is not present' do
|
test 'builder should generate properly when object is not present' do
|
||||||
with_form_for :project, :name
|
with_form_for :project, :name
|
||||||
|
|
Loading…
Reference in New Issue