Skip to content
Browse files

refactor disabled_test

separate expectations to own test cases
use assert_no_select instead of css selector
  • Loading branch information...
1 parent ece4dca commit d444d6ceefd9d72555e1782a8b796473c4478ef3 @nashby nashby committed Sep 6, 2012
Showing with 51 additions and 11 deletions.
  1. +51 −11 test/inputs/disabled_test.rb
View
62 test/inputs/disabled_test.rb
@@ -1,38 +1,78 @@
require 'test_helper'
class DisabledTest < ActionView::TestCase
- test 'input should generate disabled elements based on the disabled option' do
+ test 'string input should be disabled when disabled option is true' do
with_input_for @user, :name, :string, :disabled => true
assert_select 'input.string.disabled[disabled]'
+ end
+
+ test 'text input should be disabled when disabled option is true' do
with_input_for @user, :description, :text, :disabled => true
assert_select 'textarea.text.disabled[disabled]'
+ end
+
+ test 'numeric input should be disabled when disabled option is true' do
with_input_for @user, :age, :integer, :disabled => true
assert_select 'input.integer.disabled[disabled]'
+ end
+
+ test 'date input should be disabled when disabled option is true' do
with_input_for @user, :born_at, :date, :disabled => true
assert_select 'select.date.disabled[disabled]'
+ end
+
+ test 'datetime input should be disabled when disabled option is true' do
with_input_for @user, :created_at, :datetime, :disabled => true
assert_select 'select.datetime.disabled[disabled]'
+ end
+ test 'string input should not be disabled when disabled option is false' do
with_input_for @user, :name, :string, :disabled => false
- assert_select 'input.string:not(.disabled[disabled])'
+ assert_no_select 'input.string.disabled[disabled]'
+ end
+
+ test 'text input should not be disabled when disabled option is false' do
with_input_for @user, :description, :text, :disabled => false
- assert_select 'textarea.text:not(.disabled[disabled])'
+ assert_no_select 'textarea.text.disabled[disabled]'
+ end
+
+ test 'numeric input should not be disabled when disabled option is false' do
with_input_for @user, :age, :integer, :disabled => false
- assert_select 'input.integer:not(.disabled[disabled])'
+ assert_no_select 'input.integer.disabled[disabled]'
+ end
+
+ test 'date input should not be disabled when disabled option is false' do
with_input_for @user, :born_at, :date, :disabled => false
- assert_select 'select.date:not(.disabled[disabled])'
+ assert_no_select 'select.date.disabled[disabled]'
+ end
+
+ test 'datetime input should not be disabled when disabled option is false' do
with_input_for @user, :created_at, :datetime, :disabled => false
- assert_select 'select.datetime:not(.disabled[disabled])'
+ assert_no_select 'select.datetime.disabled[disabled]'
+ end
+ test 'string input should not be disabled when disabled option is not present' do
with_input_for @user, :name, :string
- assert_select 'input.string:not(.disabled[disabled])'
+ assert_no_select 'input.string.disabled[disabled]'
+ end
+
+ test 'text input should not be disabled when disabled option is not present' do
with_input_for @user, :description, :text
- assert_select 'textarea.text:not(.disabled[disabled])'
+ assert_no_select 'textarea.text.disabled[disabled]'
+ end
+
+ test 'numeric input should not be disabled when disabled option is not present' do
with_input_for @user, :age, :integer
- assert_select 'input.integer:not(.disabled[disabled])'
+ assert_no_select 'input.integer.disabled[disabled]'
+ end
+
+ test 'date input should not be disabled when disabled option is not present' do
with_input_for @user, :born_at, :date
- assert_select 'select.date:not(.disabled[disabled])'
+ assert_no_select 'select.date.disabled[disabled]'
+ end
+
+ test 'datetime input should not be disabled when disabled option is not present' do
with_input_for @user, :created_at, :datetime
- assert_select 'select.datetime:not(.disabled[disabled])'
+ assert_no_select 'select.datetime.disabled[disabled]'
end
end

0 comments on commit d444d6c

Please sign in to comment.
Something went wrong with that request. Please try again.