1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

Bring tests back to life.

This commit is contained in:
José Valim 2010-11-07 10:18:37 +01:00
parent 973e23c289
commit f32b5184a6
11 changed files with 31 additions and 38 deletions

View file

@ -31,9 +31,11 @@ GEM
arel (1.0.1)
activesupport (~> 3.0.0)
builder (2.1.2)
columnize (0.3.2)
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.4.2)
linecache (0.43)
mail (2.2.9)
activesupport (>= 2.3.6)
i18n (~> 0.4.1)
@ -62,7 +64,11 @@ GEM
rake (>= 0.8.4)
thor (~> 0.14.0)
rake (0.8.7)
test-unit (2.1.1)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
thor (0.14.4)
treetop (1.4.8)
polyglot (>= 0.3.1)
@ -74,4 +80,4 @@ PLATFORMS
DEPENDENCIES
mocha
rails (= 3.0.0)
test-unit
ruby-debug

View file

@ -23,10 +23,10 @@ SimpleForm.setup do |config|
# config.error_notification_tag = :p
# CSS class to add for error notification helper.
# config.error_notification_class = ''
# config.error_notification_class = :error_notification
# ID to add for error notification helper.
# config.error_notification_id = ''
# config.error_notification_id = nil
# You can wrap all inputs in a pre-defined tag.
# config.wrapper_tag = :div

View file

@ -37,7 +37,7 @@ module SimpleForm
# CSS class to add for error notification helper.
mattr_accessor :error_notification_class
@@error_notification_class = nil
@@error_notification_class = :error_notification
# ID to add for error notification helper.
mattr_accessor :error_notification_id

View file

@ -26,8 +26,7 @@ module SimpleForm
end
def html_options
css_class = SimpleForm.error_notification_class || @options[:class]
@options[:class] = "error_notification #{css_class}".strip
@options[:class] = "#{SimpleForm.error_notification_class} #{@options[:class]}".strip
@options[:id] = SimpleForm.error_notification_id if SimpleForm.error_notification_id
@options
end

View file

@ -81,11 +81,11 @@ module SimpleForm
def input(attribute_name, options={}, &block)
column = find_attribute_column(attribute_name)
input_type = default_input_type(attribute_name, column, options)
if block_given?
SimpleForm::Inputs::BlockInput.new(self, block).render
SimpleForm::Inputs::BlockInput.new(self, attribute_name, column, input_type, options, &block).render
else
klass = self.class.mappings[input_type] ||
self.class.const_get(:"#{input_type.to_s.camelize}Input")
klass = self.class.mappings[input_type] || self.class.const_get("#{input_type.to_s.camelize}Input")
klass.new(self, attribute_name, column, input_type, options).render
end
end
@ -159,8 +159,8 @@ module SimpleForm
options = args.extract_options!
options[:class] = "button #{options[:class]}".strip
args << options
if respond_to?(:"#{type}_button")
send(:"#{type}_button", *args, &block)
if respond_to?("#{type}_button")
send("#{type}_button", *args, &block)
else
send(type, *args, &block)
end

View file

@ -1,8 +1,9 @@
module SimpleForm
module Inputs
class BlockInput < Base
def initialize(builder, block)
@builder, @block = builder, block
def initialize(*args, &block)
super
@block = block
end
def input

View file

@ -4,12 +4,8 @@ class ErrorTest < ActionView::TestCase
def with_error_for(object, attribute_name, type, options={}, &block)
with_concat_form_for(object) do |f|
f.attribute_name = attribute_name
f.reflection = Association.new(Company, :company, {}) if options.delete(:setup_association)
f.input_type = type
f.options = options
SimpleForm::Inputs::Base.new(f).error.to_s
SimpleForm::Inputs::Base.new(f, attribute_name, nil, type, options).error.to_s
end
end

View file

@ -4,12 +4,8 @@ class HintTest < ActionView::TestCase
def with_hint_for(object, attribute_name, type, options={}, &block)
with_concat_form_for(object) do |f|
f.attribute_name = attribute_name
f.reflection = Association.new(Company, :company, {}) if options.delete(:setup_association)
f.input_type = type
f.options = options
SimpleForm::Inputs::Base.new(f).hint.to_s
SimpleForm::Inputs::Base.new(f, attribute_name, nil, type, options).hint.to_s
end
end

View file

@ -2,19 +2,14 @@
require 'test_helper'
class LabelTest < ActionView::TestCase
setup do
SimpleForm::Inputs::Base.reset_i18n_cache :translate_required_html
end
def with_label_for(object, attribute_name, type, options={})
with_concat_form_for(object) do |f|
f.attribute_name = attribute_name
f.reflection = Association.new(Company, :company, {}) if options.delete(:setup_association)
f.input_type = type
f.options = options
SimpleForm::Inputs::Base.new(f).label
SimpleForm::Inputs::Base.new(f, attribute_name, nil, type, options).label
end
end

View file

@ -222,7 +222,7 @@ class InputTest < ActionView::TestCase
test 'mapping input should generate an error if type is not found' do
with_concat_form_for(@user) do |f|
assert_raise(RuntimeError, "Could not find method for nil") do
SimpleForm::Inputs::MappingInput.new(f).input
SimpleForm::Inputs::MappingInput.new(f, "unknown", nil, nil, {}).input
end
end
end

View file

@ -28,7 +28,7 @@ else
end
class SimpleForm::FormBuilder
attr_accessor :attribute_name, :column, :reflection, :input_type, :options
attr_accessor :reflection, :options
end
class ActionView::TestCase