diff --git a/test/action_view_extensions/builder_test.rb b/test/action_view_extensions/builder_test.rb index 504f9d5b..ab38ef74 100644 --- a/test/action_view_extensions/builder_test.rb +++ b/test/action_view_extensions/builder_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class BuilderTest < ActionView::TestCase # COLLECTION RADIO test 'collection radio accepts a collection and generate inputs from value method' do - concat(form_for @user do |f| + concat(form_for(@user) do |f| concat f.collection_radio :active, [true, false], :to_s, :to_s end) @@ -12,7 +12,7 @@ class BuilderTest < ActionView::TestCase end test 'collection radio accepts a collection and generate inputs from label method' do - concat(form_for @user do |f| + concat(form_for(@user) do |f| concat f.collection_radio :active, [true, false], :to_s, :to_s end) @@ -21,7 +21,7 @@ class BuilderTest < ActionView::TestCase end test 'collection radio accepts checked item' do - concat(form_for @user do |f| + concat(form_for(@user) do |f| concat f.collection_radio :active, [[1, true], [0, false]], :last, :first, :checked => true end) @@ -31,7 +31,7 @@ class BuilderTest < ActionView::TestCase test 'collection radio accepts multiple disabled items' do collection = [[1, true], [0, false], [2, 'other']] - concat(form_for @user do |f| + concat(form_for(@user) do |f| concat f.collection_radio :active, collection, :last, :first, :disabled => [true, false] end) @@ -42,7 +42,7 @@ class BuilderTest < ActionView::TestCase test 'collection radio accepts single disable item' do collection = [[1, true], [0, false]] - concat(form_for @user do |f| + concat(form_for(@user) do |f| concat f.collection_radio :active, collection, :last, :first, :disabled => true end) @@ -51,7 +51,7 @@ class BuilderTest < ActionView::TestCase end test 'collection radio accepts html options as input' do - concat(form_for @user do |f| + concat(form_for(@user) do |f| concat f.collection_radio :active, [[1, true], [0, false]], :last, :first, {}, :class => 'radio' end) @@ -62,7 +62,7 @@ class BuilderTest < ActionView::TestCase # COLLECTION CHECK BOX test 'collection check box accepts a collection and generate a serie of checkboxes for value method' do collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')] - concat(form_for @user do |f| + concat(form_for(@user) do |f| concat f.collection_check_boxes :tag_ids, collection, :id, :name end) @@ -73,7 +73,7 @@ class BuilderTest < ActionView::TestCase test 'collection check box accepts a collection and generate a serie of checkboxes with labels for label method' do collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')] - concat(form_for @user do |f| + concat(form_for(@user) do |f| concat f.collection_check_boxes :tag_ids, collection, :id, :name end) @@ -83,7 +83,7 @@ class BuilderTest < ActionView::TestCase test 'collection check box accepts selected values as :checked option' do collection = (1..3).map{|i| [i, "Tag #{i}"] } - concat(form_for @user do |f| + concat(form_for(@user) do |f| concat f.collection_check_boxes :tag_ids, collection, :first, :last, :checked => [1, 3] end) @@ -94,7 +94,7 @@ class BuilderTest < ActionView::TestCase test 'collection check box accepts a single checked value' do collection = (1..3).map{|i| [i, "Tag #{i}"] } - concat(form_for @user do |f| + concat(form_for(@user) do |f| concat f.collection_check_boxes :tag_ids, collection, :first, :last, :checked => 3 end) @@ -105,7 +105,7 @@ class BuilderTest < ActionView::TestCase test 'collection check box accepts multiple disabled items' do collection = (1..3).map{|i| [i, "Tag #{i}"] } - concat(form_for @user do |f| + concat(form_for(@user) do |f| concat f.collection_check_boxes :tag_ids, collection, :first, :last, :disabled => [1, 3] end) @@ -116,7 +116,7 @@ class BuilderTest < ActionView::TestCase test 'collection check box accepts single disable item' do collection = (1..3).map{|i| [i, "Tag #{i}"] } - concat(form_for @user do |f| + concat(form_for(@user) do |f| concat f.collection_check_boxes :tag_ids, collection, :first, :last, :disabled => 1 end) @@ -127,7 +127,7 @@ class BuilderTest < ActionView::TestCase test 'collection check box accepts a proc to disabled items' do collection = (1..3).map{|i| [i, "Tag #{i}"] } - concat(form_for @user do |f| + concat(form_for(@user) do |f| concat f.collection_check_boxes :tag_ids, collection, :first, :last, :disabled => proc { |i| i.first == 1 } end) @@ -138,7 +138,7 @@ class BuilderTest < ActionView::TestCase test 'collection check box accepts html options' do collection = [[1, 'Tag 1'], [2, 'Tag 2']] - concat(form_for @user do |f| + concat(form_for(@user) do |f| concat f.collection_check_boxes :tag_ids, collection, :first, :last, {}, :class => 'check' end) @@ -148,8 +148,8 @@ class BuilderTest < ActionView::TestCase test 'collection check box with fields for' do collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')] - concat(form_for @user do |f| - concat(f.fields_for :post do |p| + concat(form_for(@user) do |f| + concat(f.fields_for(:post) do |p| concat p.collection_check_boxes :tag_ids, collection, :id, :name end) end) @@ -163,8 +163,8 @@ class BuilderTest < ActionView::TestCase # SIMPLE FIELDS test 'simple fields for is available and yields an instance of FormBuilder' do - concat(form_for @user do |f| - concat(f.simple_fields_for :posts do |posts_form| + concat(form_for(@user) do |f| + concat(f.simple_fields_for(:posts) do |posts_form| assert posts_form.instance_of?(SimpleForm::FormBuilder) end) end) diff --git a/test/action_view_extensions/form_helper_test.rb b/test/action_view_extensions/form_helper_test.rb index a86de2f6..9073fe4b 100644 --- a/test/action_view_extensions/form_helper_test.rb +++ b/test/action_view_extensions/form_helper_test.rb @@ -9,28 +9,28 @@ class FormHelperTest < ActionView::TestCase end test 'simple form should add default class to form' do - concat(simple_form_for :user do |f| end) + concat(simple_form_for(:user) do |f| end) assert_select 'form.simple_form' end test 'simple form should add object name as css class to form when object is not present' do - concat(simple_form_for :user do |f| end) + concat(simple_form_for(:user) do |f| end) assert_select 'form.simple_form.user' end test 'simple form should add object class name as css class to form' do - concat(simple_form_for @user do |f| end) + concat(simple_form_for(@user) do |f| end) assert_select 'form.simple_form.user' end test 'pass options to simple form' do - concat(simple_form_for :user, :url => '/account', :html => { :id => 'my_form' } do |f| end) + concat(simple_form_for(:user, :url => '/account', :html => { :id => 'my_form' }) do |f| end) assert_select 'form#my_form' assert_select 'form[action=/account]' end test 'fields for yields an instance of FormBuilder' do - concat(simple_fields_for :user do |f| + concat(simple_fields_for(:user) do |f| assert f.instance_of?(SimpleForm::FormBuilder) end) end diff --git a/test/components/error_test.rb b/test/components/error_test.rb index 8a6a1219..4ccfe9a4 100644 --- a/test/components/error_test.rb +++ b/test/components/error_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class ErrorTest < ActionView::TestCase def with_error_for(object, attribute_name, type, options={}, &block) - concat(simple_form_for object do |f| + concat(simple_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 diff --git a/test/components/hint_test.rb b/test/components/hint_test.rb index 287b1f1c..499643bc 100644 --- a/test/components/hint_test.rb +++ b/test/components/hint_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class HintTest < ActionView::TestCase def with_hint_for(object, attribute_name, type, options={}, &block) - concat(simple_form_for object do |f| + concat(simple_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 diff --git a/test/components/label_test.rb b/test/components/label_test.rb index 0709e6fe..85f0ac57 100644 --- a/test/components/label_test.rb +++ b/test/components/label_test.rb @@ -1,3 +1,4 @@ +# encoding: UTF-8 require 'test_helper' class LabelTest < ActionView::TestCase @@ -7,7 +8,7 @@ class LabelTest < ActionView::TestCase end def with_label_for(object, attribute_name, type, options={}) - concat(simple_form_for object do |f| + concat(simple_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 @@ -94,14 +95,14 @@ class LabelTest < ActionView::TestCase with_label_for @user, :created_at, :datetime assert_select 'label.datetime' end - + test 'label should obtain required from ActiveModel::Validations when it is included' do with_label_for @validating_user, :name, :string assert_select 'label.required' with_label_for @validating_user, :status, :string assert_select 'label.optional' end - + test 'label should allow overriding required when ActiveModel::Validations is included' do with_label_for @validating_user, :name, :string, :required => false assert_select 'label.optional' diff --git a/test/components/wrapper_test.rb b/test/components/wrapper_test.rb index 218790c1..f0ddcfd4 100644 --- a/test/components/wrapper_test.rb +++ b/test/components/wrapper_test.rb @@ -2,14 +2,14 @@ require 'test_helper' class WrapperTest < ActionView::TestCase def with_error_for(object, attribute_name, options={}, &block) - concat(simple_form_for object do |f| + concat(simple_form_for(object) do |f| f.options = options f.input attribute_name end) end def with_form_for(object, *args, &block) - concat(simple_form_for object do |f| + concat(simple_form_for(object) do |f| concat f.input(*args, &block) end) end diff --git a/test/form_builder_test.rb b/test/form_builder_test.rb index a7570d0e..3e1c9ed1 100644 --- a/test/form_builder_test.rb +++ b/test/form_builder_test.rb @@ -1,39 +1,40 @@ +# encoding: UTF-8 require 'test_helper' class FormBuilderTest < ActionView::TestCase def with_form_for(object, *args, &block) - concat(simple_form_for object do |f| + concat(simple_form_for(object) do |f| concat f.input(*args, &block) end) end def with_button_for(object, *args) - concat(simple_form_for object do |f| + concat(simple_form_for(object) do |f| concat f.button(*args) end) end def with_error_for(object, *args) - concat(simple_form_for object do |f| + concat(simple_form_for(object) do |f| concat f.error(*args) end) end def with_hint_for(object, *args) - concat(simple_form_for object do |f| + concat(simple_form_for(object) do |f| concat f.hint(*args) end) end def with_label_for(object, *args) - concat(simple_form_for object do |f| + concat(simple_form_for(object) do |f| concat f.label(*args) end) end def with_association_for(object, *args) - concat(simple_form_for object do |f| + concat(simple_form_for(object) do |f| concat f.association(*args) end) end @@ -229,26 +230,26 @@ class FormBuilderTest < ActionView::TestCase assert_select 'span.error#cool', "can't be blank" end - # REQUIRED AND PRESENCE VALIDATION + # REQUIRED AND PRESENCE VALIDATION test 'builder input should obtain required from ActiveModel::Validations when it is included' do with_form_for @validating_user, :name assert_select 'input.required#validating_user_name' with_form_for @validating_user, :status assert_select 'input.optional#validating_user_status' end - + test 'builder input should allow overriding required when ActiveModel::Validations is included' do with_form_for @validating_user, :name, :required => false assert_select 'input.optional#validating_user_name' with_form_for @validating_user, :status, :required => true assert_select 'input.required#validating_user_status' end - + test 'builder input should be required by default when ActiveModel::Validations is not included' do with_form_for @user, :name assert_select 'input.required#user_name' end - + test 'builder input should allow disabling required when ActiveModel::Validations is not included' do with_form_for @user, :name, :required => false assert_no_select 'input.required' @@ -282,14 +283,14 @@ class FormBuilderTest < ActionView::TestCase end test 'builder allows wrapper tag to be given on demand' do - concat(simple_form_for @user do |f| + concat(simple_form_for(@user) do |f| concat f.input :name, :wrapper_tag => :b end) assert_select 'form b.required.string' end test 'builder allows wrapper class to be given on demand' do - concat(simple_form_for @user do |f| + concat(simple_form_for(@user) do |f| concat f.input :name, :wrapper_class => :wrapper end) assert_select 'form div.wrapper.required.string' diff --git a/test/inputs_test.rb b/test/inputs_test.rb index a5811c4f..75b8c8d0 100644 --- a/test/inputs_test.rb +++ b/test/inputs_test.rb @@ -1,3 +1,4 @@ +# encoding: UTF-8 require 'test_helper' class InputTest < ActionView::TestCase @@ -5,13 +6,13 @@ class InputTest < ActionView::TestCase setup do SimpleForm::Inputs::CollectionInput.reset_i18n_cache :boolean_collection end - + def with_input_for(object, attribute_name, type, options={}) - concat(simple_form_for object do |f| + concat(simple_form_for(object) do |f| concat f.input(attribute_name, options.merge(:as => type)) end) end - + # ALL test 'input should generate css class based on default input type' do with_input_for @user, :name, :string @@ -36,12 +37,12 @@ class InputTest < ActionView::TestCase with_input_for @user, :age, :integer assert_select 'input[type=number].integer#user_age' end - + test 'input should generate a float text field for float attributes ' do with_input_for @user, :age, :float assert_select 'input[type=number].float#user_age' end - + test 'input should generate a decimal text field for decimal attributes ' do with_input_for @user, :age, :decimal assert_select 'input[type=number].decimal#user_age' @@ -72,7 +73,7 @@ class InputTest < ActionView::TestCase with_input_for @user, :active, :boolean assert_select 'input[type=checkbox].boolean#user_active' end - + test 'input should generate a password field for password attributes' do with_input_for @user, :password, :password assert_select 'input[type=password].password#user_password' @@ -107,7 +108,7 @@ class InputTest < ActionView::TestCase assert_select 'select option[value=Brazil]', 'Brazil' assert_no_select 'select option[value=][disabled=disabled]' end - + test 'input should generate a country select with simple form default' do swap SimpleForm, :country_priority => [ 'Brazil' ] do with_input_for @user, :country, :country @@ -141,17 +142,17 @@ class InputTest < ActionView::TestCase assert_select "form select.datetime#user_created_at_#{i}i" end end - + test 'input should be able to pass options to datetime select' do with_input_for @user, :created_at, :datetime, :disabled => true, :prompt => { :year => 'ano', :month => 'mês', :day => 'dia' } - + assert_select 'select.datetime[disabled=disabled]' assert_select 'select.datetime option', 'ano' assert_select 'select.datetime option', 'mês' assert_select 'select.datetime option', 'dia' end - + test 'input should generate a date select for date attributes' do with_input_for @user, :born_at, :date assert_select 'select.date#user_born_at_1i' @@ -159,11 +160,11 @@ class InputTest < ActionView::TestCase assert_select 'select.date#user_born_at_3i' assert_no_select 'select.date#user_born_at_4i' end - + test 'input should be able to pass options to date select' do with_input_for @user, :born_at, :date, :as => :date, :disabled => true, :prompt => { :year => 'ano', :month => 'mês', :day => 'dia' } - + assert_select 'select.date[disabled=disabled]' assert_select 'select.date option', 'ano' assert_select 'select.date option', 'mês' @@ -183,11 +184,11 @@ class InputTest < ActionView::TestCase assert_select 'select.time#user_delivery_time_4i' assert_select 'select.time#user_delivery_time_5i' end - + test 'input should be able to pass options to time select' do with_input_for @user, :delivery_time, :time, :required => true, :disabled => true, :prompt => { :hour => 'hora', :minute => 'minuto' } - + assert_select 'select.time[disabled=disabled]' assert_select 'select.time option', 'hora' assert_select 'select.time option', 'minuto' @@ -214,13 +215,13 @@ class InputTest < ActionView::TestCase assert_select 'input[type=radio][value=true].radio#user_active_true' assert_select 'input[type=radio][value=false].radio#user_active_false' end - + test 'input as radio should generate internal labels by default' do with_input_for @user, :active, :radio assert_select 'label[for=user_active_true]', 'Yes' assert_select 'label[for=user_active_false]', 'No' end - + test 'input as radio should use i18n to translate internal labels' do store_translations(:en, :simple_form => { :yes => 'Sim', :no => 'Não' }) do with_input_for @user, :active, :radio @@ -228,14 +229,14 @@ class InputTest < ActionView::TestCase assert_select 'label[for=user_active_false]', 'Não' end end - + test 'input should generate a boolean select with options by default for select types' do with_input_for @user, :active, :select assert_select 'select.select#user_active' assert_select 'select option[value=true]', 'Yes' assert_select 'select option[value=false]', 'No' end - + test 'input as select should use i18n to translate select boolean options' do store_translations(:en, :simple_form => { :yes => 'Sim', :no => 'Não' }) do with_input_for @user, :active, :select @@ -243,53 +244,53 @@ class InputTest < ActionView::TestCase assert_select 'select option[value=false]', 'Não' end end - + test 'input should allow overriding collection for select types' do with_input_for @user, :name, :select, :collection => ['Jose', 'Carlos'] assert_select 'select.select#user_name' assert_select 'select option', 'Jose' assert_select 'select option', 'Carlos' end - + test 'input should mark the selected value by default' do @user.name = "Carlos" with_input_for @user, :name, :select, :collection => ['Jose', 'Carlos'] assert_select 'select option[selected=selected]', 'Carlos' end - + test 'input should mark the selected value also when using integers' do @user.age = 18 with_input_for @user, :age, :select, :collection => 18..60 assert_select 'select option[selected=selected]', '18' end - + test 'input should automatically set include blank' do with_input_for @user, :age, :select, :collection => 18..30 assert_select 'select option[value=]', '' end - + test 'input should not set include blank if otherwise is told' do with_input_for @user, :age, :select, :collection => 18..30, :include_blank => false assert_no_select 'select option[value=]', '' end - + test 'input should not set include blank if prompt is given' do with_input_for @user, :age, :select, :collection => 18..30, :prompt => "Please select foo" assert_no_select 'select option[value=]', '' end - + test 'input should not set include blank if multiple is given' do with_input_for @user, :age, :select, :collection => 18..30, :input_html => { :multiple => true } assert_no_select 'select option[value=]', '' end - + test 'input should detect label and value on collections' do users = [ setup_new_user(:id => 1, :name => "Jose"), setup_new_user(:id => 2, :name => "Carlos") ] with_input_for @user, :description, :select, :collection => users assert_select 'select option[value=1]', 'Jose' assert_select 'select option[value=2]', 'Carlos' end - + test 'input should allow overriding collection for radio types' do with_input_for @user, :name, :radio, :collection => ['Jose', 'Carlos'] assert_select 'input[type=radio][value=Jose]' @@ -297,13 +298,13 @@ class InputTest < ActionView::TestCase assert_select 'label.collection_radio', 'Jose' assert_select 'label.collection_radio', 'Carlos' end - + test 'input should mark the current radio value by default' do @user.name = "Carlos" with_input_for @user, :name, :radio, :collection => ['Jose', 'Carlos'] assert_select 'input[type=radio][value=Carlos][checked=checked]' end - + test 'input should allow using a collection with text/value arrays' do with_input_for @user, :name, :radio, :collection => [['Jose', 'jose'], ['Carlos', 'carlos']] assert_select 'input[type=radio][value=jose]' @@ -311,7 +312,7 @@ class InputTest < ActionView::TestCase assert_select 'label.collection_radio', 'Jose' assert_select 'label.collection_radio', 'Carlos' end - + test 'input should allow overriding label and value method for collections' do with_input_for @user, :name, :radio, :collection => ['Jose' , 'Carlos'], @@ -322,19 +323,19 @@ class InputTest < ActionView::TestCase assert_select 'label.collection_radio', 'JOSE' assert_select 'label.collection_radio', 'CARLOS' end - + # With no object test 'input should be generated properly when object is not present' do with_input_for :project, :name, :string assert_select 'input.string.required#project_name' end - + test 'input as radio should be generated properly when object is not present ' do with_input_for :project, :name, :radio assert_select 'input.radio#project_name_true' assert_select 'input.radio#project_name_false' end - + test 'input as select with collection should be generated properly when object is not present' do with_input_for :project, :name, :select, :collection => ['Jose', 'Carlos'] assert_select 'select.select#project_name' diff --git a/test/support/models.rb b/test/support/models.rb index 06b11cb3..7085ba43 100644 --- a/test/support/models.rb +++ b/test/support/models.rb @@ -36,7 +36,7 @@ class User < OpenStruct extend ActiveModel::Naming # Get rid of deprecation warnings - undef_method :id + undef_method :id if respond_to?(:id) def new_record! @new_record = true diff --git a/test/test_helper.rb b/test/test_helper.rb index 1b5eaf98..5a44a24a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,8 +1,8 @@ require 'rubygems' require 'test/unit' -gem "actionpack", "3.0.0.beta3" -gem "activemodel", "3.0.0.beta3" +gem "actionpack", "3.0.0.beta4" +gem "activemodel", "3.0.0.beta4" require 'active_model' require 'action_controller' @@ -59,7 +59,7 @@ class ActionView::TestCase :description => 'Hello!', :created_at => Time.now }.merge(options)) - + @validating_user = ValidatingUser.new({ :id => 1, :name => 'New in Simple Form!',