Permalink
Browse files

refactor readonly_test

separate expectations to own test cases
use assert_no_select instead of css selector
  • Loading branch information...
nashby committed Sep 7, 2012
1 parent 2ad7e87 commit c4bceafcf80e79b400e4ccdb6d0f98046c3effd5
Showing with 51 additions and 11 deletions.
  1. +51 −11 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])'
+ 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_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 false' do
with_input_for @user, :age, :integer, :readonly => false
- 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 false' do
with_input_for @user, :born_at, :date, :readonly => false
- 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 false' do
with_input_for @user, :created_at, :datetime, :readonly => false
- assert_select 'select.datetime:not(.readonly[readonly])'
+ 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

0 comments on commit c4bceaf

Please sign in to comment.