Permalink
Browse files

refactor general_test

separate expectations to own test cases
use assert_no_select instead of css selector
  • Loading branch information...
1 parent d444d6c commit 2ad7e87484e244b8779db088815d9ea02fa99eae @nashby nashby committed Sep 7, 2012
Showing with 52 additions and 13 deletions.
  1. +52 −13 test/inputs/general_test.rb
@@ -15,39 +15,79 @@ class InputTest < ActionView::TestCase
assert_select 'select.datetime'
end
- test 'input should generate autofocus attribute based on the autofocus option' do
+ test 'string input should generate autofocus attribute when autofocus option is true' do
with_input_for @user, :name, :string, :autofocus => true
assert_select 'input.string[autofocus]'
+ end
+
+ test 'text input should generate autofocus attribute when autofocus option is true' do
with_input_for @user, :description, :text, :autofocus => true
assert_select 'textarea.text[autofocus]'
+ end
+
+ test 'numeric input should generate autofocus attribute when autofocus option is true' do
with_input_for @user, :age, :integer, :autofocus => true
assert_select 'input.integer[autofocus]'
+ end
+
+ test 'date input should generate autofocus attribute when autofocus option is true' do
with_input_for @user, :born_at, :date, :autofocus => true
assert_select 'select.date[autofocus]'
+ end
+
+ test 'datetime input should generate autofocus attribute when autofocus option is true' do
with_input_for @user, :created_at, :datetime, :autofocus => true
assert_select 'select.datetime[autofocus]'
+ end
+ test 'string input should generate autofocus attribute when autofocus option is false' do
with_input_for @user, :name, :string, :autofocus => false
- assert_select 'input.string:not([autofocus])'
+ assert_no_select 'input.string[autofocus]'
+ end
+
+ test 'text input should generate autofocus attribute when autofocus option is false' do
with_input_for @user, :description, :text, :autofocus => false
- assert_select 'textarea.text:not([autofocus])'
+ assert_no_select 'textarea.text[autofocus]'
+ end
+
+ test 'numeric input should generate autofocus attribute when autofocus option is false' do
with_input_for @user, :age, :integer, :autofocus => false
- assert_select 'input.integer:not([autofocus])'
+ assert_no_select 'input.integer[autofocus]'
+ end
+
+ test 'date input should generate autofocus attribute when autofocus option is false' do
with_input_for @user, :born_at, :date, :autofocus => false
- assert_select 'select.date:not([autofocus])'
+ assert_no_select 'select.date[autofocus]'
+ end
+
+ test 'datetime input should generate autofocus attribute when autofocus option is false' do
with_input_for @user, :created_at, :datetime, :autofocus => false
- assert_select 'select.datetime:not([autofocus])'
+ assert_no_select 'select.datetime[autofocus]'
+ end
+ test 'string input should generate autofocus attribute when autofocus option is not present' do
with_input_for @user, :name, :string
- assert_select 'input.string:not([autofocus])'
+ assert_no_select 'input.string[autofocus]'
+ end
+
+ test 'text input should generate autofocus attribute when autofocus option is not present' do
with_input_for @user, :description, :text
- assert_select 'textarea.text:not([autofocus])'
+ assert_no_select 'textarea.text[autofocus]'
+ end
+
+ test 'numeric input should generate autofocus attribute when autofocus option is not present' do
with_input_for @user, :age, :integer
- assert_select 'input.integer:not([autofocus])'
+ assert_no_select 'input.integer[autofocus]'
+ end
+
+ test 'date input should generate autofocus attribute when autofocus option is not present' do
with_input_for @user, :born_at, :date
- assert_select 'select.date:not([autofocus])'
+ assert_no_select 'select.date[autofocus]'
+ end
+
+ test 'datetime input should generate autofocus attribute when autofocus option is not present' do
with_input_for @user, :created_at, :datetime
- assert_select 'select.datetime:not([autofocus])'
+ assert_no_select 'select.datetime[autofocus]'
end
# With no object
@@ -66,12 +106,11 @@ class InputTest < ActionView::TestCase
with_input_for :project, :name, :select, :collection => ['Jose', 'Carlos']
assert_select 'select.select#project_name'
end
-
+
test 'input should not generate empty css class' do
swap SimpleForm, :generate_additional_classes_for => [:wrapper, :label] do
with_input_for :project, :name, :string
assert_no_select 'input#project_name[class]'
end
end
-
end

0 comments on commit 2ad7e87

Please sign in to comment.