From c4bceafcf80e79b400e4ccdb6d0f98046c3effd5 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Fri, 7 Sep 2012 11:17:54 +0300 Subject: [PATCH] refactor readonly_test separate expectations to own test cases use assert_no_select instead of css selector --- test/inputs/readonly_test.rb | 70 ++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 15 deletions(-) diff --git a/test/inputs/readonly_test.rb b/test/inputs/readonly_test.rb index 49bd0b17..2cf65d84 100644 --- a/test/inputs/readonly_test.rb +++ b/test/inputs/readonly_test.rb @@ -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