Skip to content

Commit

Permalink
clenup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nashby committed Mar 1, 2012
1 parent 7c1aa0e commit ab366eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
36 changes: 18 additions & 18 deletions test/action_view_extensions/form_helper_test.rb
Expand Up @@ -9,95 +9,95 @@ class FormHelperTest < ActionView::TestCase
end

test 'SimpleForm should add default class to form' do
concat(simple_form_for(:user) do |f| end)
with_concat_form_for(:user)
assert_select 'form.simple_form'
end

test 'SimpleForm should use default browser validations by default' do
concat(simple_form_for(:user) do |f| end)
with_concat_form_for(:user)
assert_no_select 'form[novalidate]'
end

test 'SimpleForm should not use default browser validations if specified in the configuration options' do
swap SimpleForm, :browser_validations => false do
concat(simple_form_for(:user) do |f| end)
with_concat_form_for(:user)
assert_select 'form[novalidate="novalidate"]'
end
end

test 'a form specific disabled validation option should override the default enabled browser validation configuration option' do
concat(simple_form_for(:user, :html => { :novalidate => true }) do |f| end)
with_concat_form_for(:user, :html => { :novalidate => true })
assert_select 'form[novalidate="novalidate"]'
end

test 'a form specific enabled validation option should override the disabled browser validation configuration option' do
swap SimpleForm, :browser_validations => false do
concat(simple_form_for(:user, :html => { :novalidate => false }) do |f| end)
with_concat_form_for(:user, :html => { :novalidate => false })
assert_no_select 'form[novalidate]'
end
end

test 'SimpleForm should add object name as css class to form when object is not present' do
concat(simple_form_for(:user) do |f| end)
with_concat_form_for(:user, :html => { :novalidate => true })
assert_select 'form.simple_form.user'
end

test 'SimpleForm should add :as option as css class to form when object is not present' do
concat(simple_form_for(:user, :as => 'superuser') do |f| end)
with_concat_form_for(:user, :as => 'superuser')
assert_select 'form.simple_form.superuser'
end

test 'SimpleForm should add object class name with new prefix as css class to form if record is not persisted' do
@user.new_record!
concat(simple_form_for(@user) do |f| end)
with_concat_form_for(@user)
assert_select 'form.simple_form.new_user'
end

test 'SimpleForm should add :as option with new prefix as css class to form if record is not persisted' do
@user.new_record!
concat(simple_form_for(@user, :as => 'superuser') do |f| end)
with_concat_form_for(@user, :as => 'superuser')
assert_select 'form.simple_form.new_superuser'
end

test 'SimpleForm should add edit class prefix as css class to form if record is persisted' do
concat(simple_form_for(@user) do |f| end)
with_concat_form_for(@user)
assert_select 'form.simple_form.edit_user'
end

test 'SimpleForm should add :as options with edit prefix as css class to form if record is persisted' do
concat(simple_form_for(@user, :as => 'superuser') do |f| end)
with_concat_form_for(@user, :as => 'superuser')
assert_select 'form.simple_form.edit_superuser'
end

test 'SimpleForm should not add object class to form if css_class is specified' do
concat(simple_form_for(:user, :html => {:class => nil}) do |f| end)
with_concat_form_for(:user, :html => {:class => nil})
assert_no_select 'form.user'
end

test 'SimpleForm should add custom class to form if css_class is specified' do
concat(simple_form_for(:user, :html => {:class => 'my_class'}) do |f| end)
with_concat_form_for(:user, :html => {:class => 'my_class'})
assert_select 'form.my_class'
end

test 'pass options to SimpleForm' do
concat(simple_form_for(:user, :url => '/account', :html => { :id => 'my_form' }) do |f| end)
with_concat_form_for(:user, :url => '/account', :html => { :id => 'my_form' })
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|
with_concat_form_for(:user) do |f|
assert f.instance_of?(SimpleForm::FormBuilder)
end)
end
end

test 'fields for with a hash like model yeilds an instance of FormBuilder' do
@hash_backed_author = HashBackedAuthor.new

concat(simple_fields_for(:author, @hash_backed_author) do |f|
with_concat_fields_for(:author, @hash_backed_author) do |f|
assert f.instance_of?(SimpleForm::FormBuilder)
f.input :name
end)
end

assert_select "input[name='author[name]'][value='hash backed author']"
end
Expand Down
6 changes: 5 additions & 1 deletion test/support/misc_helpers.rb
Expand Up @@ -63,7 +63,11 @@ def custom_mapping_form_for(object, *args, &block)
end

def with_concat_form_for(*args, &block)
concat simple_form_for(*args, &block)
concat simple_form_for(*args, &(block || proc {}))
end

def with_concat_fields_for(*args, &block)
concat simple_fields_for(*args, &block)
end

def with_concat_custom_form_for(*args, &block)
Expand Down

0 comments on commit ab366eb

Please sign in to comment.