refactor readonly_test

separate expectations to own test cases
use assert_no_select instead of css selector
This commit is contained in:
Vasiliy Ermolovich 2012-09-07 11:17:54 +03:00
parent 2ad7e87484
commit c4bceafcf8
1 changed files with 55 additions and 15 deletions

View File

@ -1,39 +1,79 @@
require 'test_helper'
class ReadonlyTest < ActionView::TestCase
test 'input should generate readonly elements based on the readonly option' do
test 'string input should generate readonly elements when readonly option is true' do
with_input_for @user, :name, :string, :readonly => true
assert_select 'input.string.readonly[readonly]'
end
test 'text input should generate readonly elements when readonly option is true' do
with_input_for @user, :description, :text, :readonly => true
assert_select 'textarea.text.readonly[readonly]'
end
test 'numeric input should generate readonly elements when readonly option is true' do
with_input_for @user, :age, :integer, :readonly => true
assert_select 'input.integer.readonly[readonly]'
end
test 'date input should generate readonly elements when readonly option is true' do
with_input_for @user, :born_at, :date, :readonly => true
assert_select 'select.date.readonly[readonly]'
end
test 'datetime input should generate readonly elements when readonly option is true' do
with_input_for @user, :created_at, :datetime, :readonly => true
assert_select 'select.datetime.readonly[readonly]'
end
test 'string input should generate readonly elements when readonly option is false' do
with_input_for @user, :name, :string, :readonly => false
assert_select 'input.string:not(.readonly[readonly])'
with_input_for @user, :description, :text, :readonly => false
assert_select 'textarea.text:not(.readonly[readonly])'
with_input_for @user, :age, :integer, :readonly => false
assert_select 'input.integer:not(.readonly[readonly])'
with_input_for @user, :born_at, :date, :readonly => false
assert_select 'select.date:not(.readonly[readonly])'
with_input_for @user, :created_at, :datetime, :readonly => false
assert_select 'select.datetime:not(.readonly[readonly])'
assert_no_select 'input.string.readonly[readonly]'
end
test 'text input should generate readonly elements when readonly option is false' do
with_input_for @user, :description, :text, :readonly => false
assert_no_select 'textarea.text.readonly[readonly]'
end
test 'numeric input should generate readonly elements when readonly option is false' do
with_input_for @user, :age, :integer, :readonly => false
assert_no_select 'input.integer.readonly[readonly]'
end
test 'date input should generate readonly elements when readonly option is false' do
with_input_for @user, :born_at, :date, :readonly => false
assert_no_select 'select.date.readonly[readonly]'
end
test 'datetime input should generate readonly elements when readonly option is false' do
with_input_for @user, :created_at, :datetime, :readonly => false
assert_no_select 'select.datetime.readonly[readonly]'
end
test 'string input should generate readonly elements when readonly option is not present' do
with_input_for @user, :name, :string
assert_select 'input.string:not(.readonly[readonly])'
assert_no_select 'input.string.readonly[readonly]'
end
test 'text input should generate readonly elements when readonly option is not present' do
with_input_for @user, :description, :text
assert_select 'textarea.text:not(.readonly[readonly])'
assert_no_select 'textarea.text.readonly[readonly]'
end
test 'numeric input should generate readonly elements when readonly option is not present' do
with_input_for @user, :age, :integer
assert_select 'input.integer:not(.readonly[readonly])'
assert_no_select 'input.integer.readonly[readonly]'
end
test 'date input should generate readonly elements when readonly option is not present' do
with_input_for @user, :born_at, :date
assert_select 'select.date:not(.readonly[readonly])'
assert_no_select 'select.date.readonly[readonly]'
end
test 'datetime input should generate readonly elements when readonly option is not present' do
with_input_for @user, :created_at, :datetime
assert_select 'select.datetime:not(.readonly[readonly])'
assert_no_select 'select.datetime.readonly[readonly]'
end
test 'input should generate readonly attribute when the field is readonly and the object is persisted' do