html5_validators 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.travis.yml +11 -6
- data/Gemfile +1 -0
- data/README.md +3 -2
- data/Rakefile +10 -8
- data/gemfiles/Gemfile.rails-3.2 +1 -5
- data/gemfiles/Gemfile.rails-5.0 +6 -0
- data/html5_validators.gemspec +2 -1
- data/lib/html5_validators.rb +1 -0
- data/lib/html5_validators/action_view/form_helpers.rb +1 -0
- data/lib/html5_validators/action_view/form_helpers_rails3.rb +1 -0
- data/lib/html5_validators/active_model/helper_methods.rb +1 -0
- data/lib/html5_validators/active_model/validations.rb +1 -0
- data/lib/html5_validators/active_record/base.rb +9 -5
- data/lib/html5_validators/version.rb +2 -1
- data/{spec → test}/fake_app.rb +5 -1
- data/test/features/validation_test.rb +206 -0
- data/test/models/active_record/inherited_test.rb +18 -0
- data/{spec/spec_helper.rb → test/test_helper.rb} +7 -12
- metadata +13 -13
- data/spec/features/validation_spec.rb +0 -205
- data/spec/models/active_record/inherited_spec.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e661f883c54a76d6b77c4bfe4693d56a79292d04
|
4
|
+
data.tar.gz: d3eb675e09dbd2bcf4dacd142ac719f4c036f85b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e8e247612a555fcb2d48bbda8ec5780afc0fc04fdef16cc2c465bbc57e599a408a92cfa6597ffee50c689b45a5eeeb35ca272a559c8c444eeaf3dd5ec95c5aa
|
7
|
+
data.tar.gz: b7826041634d9996bf8616c1998de4072b6bfcb90894725b864bd22e555961ae4a160a39433725dde957ea8c2aa3751c80a1829b14e06daca0d94f5babf7bda6
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
@@ -2,9 +2,9 @@ language: ruby
|
|
2
2
|
|
3
3
|
rvm:
|
4
4
|
- 2.0.0
|
5
|
-
- 2.1
|
6
|
-
- 2.2.
|
7
|
-
- 2.3.
|
5
|
+
- 2.1.10
|
6
|
+
- 2.2.6
|
7
|
+
- 2.3.3
|
8
8
|
- ruby-head
|
9
9
|
|
10
10
|
gemfile:
|
@@ -12,19 +12,24 @@ gemfile:
|
|
12
12
|
- gemfiles/Gemfile.rails-4.0
|
13
13
|
- gemfiles/Gemfile.rails-4.1
|
14
14
|
- gemfiles/Gemfile.rails-4.2
|
15
|
+
- gemfiles/Gemfile.rails-5.0
|
15
16
|
- gemfiles/Gemfile.rails-edge
|
16
17
|
|
17
18
|
sudo: false
|
18
19
|
|
19
20
|
matrix:
|
20
21
|
exclude:
|
22
|
+
- rvm: 2.0.0
|
23
|
+
gemfile: gemfiles/Gemfile.rails-5.0
|
24
|
+
- rvm: 2.1.10
|
25
|
+
gemfile: gemfiles/Gemfile.rails-5.0
|
21
26
|
- rvm: 2.0.0
|
22
27
|
gemfile: gemfiles/Gemfile.rails-edge
|
23
|
-
- rvm: 2.1
|
28
|
+
- rvm: 2.1.10
|
24
29
|
gemfile: gemfiles/Gemfile.rails-edge
|
25
|
-
- rvm: 2.2.
|
30
|
+
- rvm: 2.2.6
|
26
31
|
gemfile: gemfiles/Gemfile.rails-3.2
|
27
|
-
- rvm: 2.3.
|
32
|
+
- rvm: 2.3.3
|
28
33
|
gemfile: gemfiles/Gemfile.rails-3.2
|
29
34
|
- rvm: ruby-head
|
30
35
|
gemfile: gemfiles/Gemfile.rails-3.2
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -127,7 +127,8 @@ Set `auto_html5_validation = false` attribute to ActiveModelish object.
|
|
127
127
|
|
128
128
|
### 3. Per model class (via model class attribute)
|
129
129
|
|
130
|
-
Set `auto_html5_validation = false` to ActiveModelish class variable.
|
130
|
+
Set `auto_html5_validation = false` to ActiveModelish class' class variable.
|
131
|
+
This configuration will never be propagated to inherited children classes.
|
131
132
|
|
132
133
|
* Model
|
133
134
|
```ruby
|
@@ -169,7 +170,7 @@ end
|
|
169
170
|
|
170
171
|
* Ruby 2.0, 2.1, 2.2, 2.3, 2.4 (trunk)
|
171
172
|
|
172
|
-
* Rails 3.2.x, 4.0.x, 4.1, 4.2, 5.0 (edge)
|
173
|
+
* Rails 3.2.x, 4.0.x, 4.1, 4.2, 5.0, 5.1 (edge)
|
173
174
|
|
174
175
|
* HTML5 compatible browsers
|
175
176
|
|
data/Rakefile
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rake/testtask'
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
t.libs << 'test'
|
7
|
+
t.pattern = 'test/**/*_test.rb'
|
8
|
+
t.warning = true
|
9
|
+
t.verbose = true
|
10
|
+
end
|
6
11
|
|
7
|
-
task :
|
8
|
-
task default: :spec
|
9
|
-
|
10
|
-
RSpec::Core::RakeTask.new(spec: :noop)
|
12
|
+
task default: :test
|
data/gemfiles/Gemfile.rails-3.2
CHANGED
@@ -3,11 +3,7 @@ source 'https://rubygems.org'
|
|
3
3
|
gem 'railties', '~> 3.2.0'
|
4
4
|
gem 'activerecord', '~> 3.2.0'
|
5
5
|
gem 'nokogiri', '~> 1.5.0'
|
6
|
-
gem 'rspec-rails', '~> 2.14.1'
|
7
|
-
gem 'test-unit'
|
8
6
|
gem 'capybara', '~> 2.0.0'
|
9
|
-
|
10
|
-
gem 'mime-types', '< 2'
|
11
|
-
gem 'rubyzip', '< 1'
|
7
|
+
gem 'test-unit-rails', '1.0.2'
|
12
8
|
|
13
9
|
gemspec path: '..'
|
data/html5_validators.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
2
3
|
$:.push File.expand_path('../lib', __FILE__)
|
3
4
|
require 'html5_validators/version'
|
4
5
|
|
@@ -19,7 +20,7 @@ Gem::Specification.new do |s|
|
|
19
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
21
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
22
|
s.require_paths = ['lib']
|
22
|
-
s.add_development_dependency '
|
23
|
+
s.add_development_dependency 'test-unit-rails'
|
23
24
|
s.add_development_dependency 'capybara', '>= 2'
|
24
25
|
s.add_development_dependency 'sqlite3'
|
25
26
|
s.add_development_dependency 'rake'
|
data/lib/html5_validators.rb
CHANGED
@@ -1,22 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Html5Validators
|
2
3
|
module ActiveRecordExtension
|
3
4
|
extend ActiveSupport::Concern
|
4
5
|
|
5
6
|
# Future subclasses will pick up the model extension
|
6
7
|
module ClassMethods
|
7
|
-
|
8
8
|
def inherited(kls)
|
9
9
|
super
|
10
|
-
kls
|
11
|
-
|
12
|
-
end
|
10
|
+
class << kls
|
11
|
+
attr_accessor :auto_html5_validation
|
12
|
+
end
|
13
|
+
kls.auto_html5_validation = true
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
17
|
included do
|
17
18
|
# Existing subclasses pick up the model extension as well
|
18
19
|
self.descendants.each do |kls|
|
19
|
-
|
20
|
+
class << kls
|
21
|
+
attr_accessor :auto_html5_validation
|
22
|
+
end
|
23
|
+
kls.auto_html5_validation = true
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
data/{spec → test}/fake_app.rb
RENAMED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'active_record'
|
2
3
|
require 'action_controller/railtie'
|
3
4
|
|
@@ -28,7 +29,10 @@ app.routes.draw do
|
|
28
29
|
end
|
29
30
|
|
30
31
|
# models
|
31
|
-
class
|
32
|
+
class ApplicationRecord < ActiveRecord::Base
|
33
|
+
self.abstract_class = true
|
34
|
+
end
|
35
|
+
class Person < ApplicationRecord
|
32
36
|
end
|
33
37
|
class Item
|
34
38
|
if ActiveModel::VERSION::STRING >= '4'
|
@@ -0,0 +1,206 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class ActiveRecordValidationTest < ActionDispatch::IntegrationTest
|
5
|
+
sub_test_case 'without validation' do
|
6
|
+
test 'new form' do
|
7
|
+
visit '/people/new'
|
8
|
+
assert page.has_css? 'input#person_name'
|
9
|
+
assert page.has_no_css? 'input#person_name[required=required]'
|
10
|
+
end
|
11
|
+
|
12
|
+
test 'new_without_html5_validation form' do
|
13
|
+
visit '/people/new_without_html5_validation'
|
14
|
+
assert page.has_css? 'input#person_email'
|
15
|
+
assert page.has_no_css? 'input#person_email[required=required]'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
sub_test_case 'with required validation' do
|
20
|
+
setup do
|
21
|
+
Person.validates_presence_of :name, :bio
|
22
|
+
end
|
23
|
+
teardown do
|
24
|
+
Person._validators.clear
|
25
|
+
end
|
26
|
+
test 'new form' do
|
27
|
+
visit '/people/new'
|
28
|
+
|
29
|
+
assert_equal 'required', find('input#person_name')[:required]
|
30
|
+
assert_equal 'required', find('textarea#person_bio')[:required]
|
31
|
+
end
|
32
|
+
test 'new_without_html5_validation form' do
|
33
|
+
visit '/people/new_without_html5_validation'
|
34
|
+
|
35
|
+
assert_nil find('input#person_name')[:required]
|
36
|
+
end
|
37
|
+
test 'new_with_required_true form' do
|
38
|
+
visit '/people/new_with_required_true'
|
39
|
+
|
40
|
+
assert_equal 'required', find('input#person_email')[:required]
|
41
|
+
end
|
42
|
+
|
43
|
+
sub_test_case 'disabling html5_validation in class level' do
|
44
|
+
setup do
|
45
|
+
Person.class_eval do |kls|
|
46
|
+
kls.auto_html5_validation = false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
teardown do
|
50
|
+
Person.class_eval do |kls|
|
51
|
+
kls.auto_html5_validation = nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
test 'new form' do
|
55
|
+
visit '/people/new'
|
56
|
+
|
57
|
+
assert_nil find('input#person_name')[:required]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
sub_test_case 'disabling html5_validations in gem' do
|
62
|
+
setup do
|
63
|
+
Html5Validators.enabled = false
|
64
|
+
end
|
65
|
+
teardown do
|
66
|
+
Html5Validators.enabled = true
|
67
|
+
end
|
68
|
+
test 'new form' do
|
69
|
+
visit '/people/new'
|
70
|
+
|
71
|
+
assert_nil find('input#person_name')[:required]
|
72
|
+
assert_nil find('textarea#person_bio')[:required]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
sub_test_case 'with maxlength validation' do
|
78
|
+
setup do
|
79
|
+
Person.validates_length_of :name, maximum: 20
|
80
|
+
Person.validates_length_of :bio, maximum: 100
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'new form' do
|
84
|
+
visit '/people/new'
|
85
|
+
|
86
|
+
assert_equal '20', find('input#person_name')[:maxlength]
|
87
|
+
assert_equal '100', find('textarea#person_bio')[:maxlength]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
sub_test_case 'with minlength validation' do
|
92
|
+
setup do
|
93
|
+
Person.validates_length_of :name, minimum: 3
|
94
|
+
Person.validates_length_of :bio, minimum: 10
|
95
|
+
end
|
96
|
+
|
97
|
+
test 'new form' do
|
98
|
+
visit '/people/new'
|
99
|
+
|
100
|
+
assert_equal '3', find('input#person_name')[:minlength]
|
101
|
+
assert_equal '10', find('textarea#person_bio')[:minlength]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class ActiveModelValidationTest < ActionDispatch::IntegrationTest
|
107
|
+
sub_test_case 'without validation' do
|
108
|
+
test 'new form' do
|
109
|
+
visit '/items/new'
|
110
|
+
assert page.has_css? 'input#item_name'
|
111
|
+
assert page.has_no_css? 'input#item_name[required=required]'
|
112
|
+
end
|
113
|
+
|
114
|
+
test 'new_without_html5_validation form' do
|
115
|
+
visit '/items/new_without_html5_validation'
|
116
|
+
assert page.has_css? 'textarea#item_description'
|
117
|
+
assert page.has_no_css? 'textarea#item_description[required=required]'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
sub_test_case 'with required validation' do
|
122
|
+
setup do
|
123
|
+
Item.validates_presence_of :name, :description
|
124
|
+
end
|
125
|
+
teardown do
|
126
|
+
Item._validators.clear
|
127
|
+
end
|
128
|
+
test 'new form' do
|
129
|
+
visit '/items/new'
|
130
|
+
|
131
|
+
assert_equal 'required', find('input#item_name')[:required]
|
132
|
+
assert_equal 'required', find('textarea#item_description')[:required]
|
133
|
+
end
|
134
|
+
test 'new_without_html5_validation form' do
|
135
|
+
visit '/items/new_without_html5_validation'
|
136
|
+
|
137
|
+
assert_nil find('input#item_name')[:required]
|
138
|
+
end
|
139
|
+
test 'new_with_required_true form' do
|
140
|
+
visit '/items/new_with_required_true'
|
141
|
+
|
142
|
+
assert_equal 'required', find('input#item_name')[:required]
|
143
|
+
end
|
144
|
+
|
145
|
+
sub_test_case 'disabling html5_validation in class level' do
|
146
|
+
setup do
|
147
|
+
Item.class_eval do |kls|
|
148
|
+
kls.auto_html5_validation = false
|
149
|
+
end
|
150
|
+
end
|
151
|
+
teardown do
|
152
|
+
Item.class_eval do |kls|
|
153
|
+
kls.auto_html5_validation = nil
|
154
|
+
end
|
155
|
+
end
|
156
|
+
test 'new form' do
|
157
|
+
visit '/items/new'
|
158
|
+
|
159
|
+
assert_nil find('input#item_name')[:required]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
sub_test_case 'disabling html5_validations in gem' do
|
164
|
+
setup do
|
165
|
+
Html5Validators.enabled = false
|
166
|
+
end
|
167
|
+
teardown do
|
168
|
+
Html5Validators.enabled = true
|
169
|
+
end
|
170
|
+
test 'new form' do
|
171
|
+
visit '/items/new'
|
172
|
+
|
173
|
+
assert_nil find('input#item_name')[:required]
|
174
|
+
assert_nil find('textarea#item_description')[:required]
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
sub_test_case 'with maxlength validation' do
|
180
|
+
setup do
|
181
|
+
Item.validates_length_of :name, maximum: 20
|
182
|
+
Item.validates_length_of :description, maximum: 100
|
183
|
+
end
|
184
|
+
|
185
|
+
test 'new form' do
|
186
|
+
visit '/items/new'
|
187
|
+
|
188
|
+
assert_equal '20', find('input#item_name')[:maxlength]
|
189
|
+
assert_equal '100', find('textarea#item_description')[:maxlength]
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
sub_test_case 'with minlength validation' do
|
194
|
+
setup do
|
195
|
+
Item.validates_length_of :name, minimum: 3
|
196
|
+
Item.validates_length_of :description, minimum: 10
|
197
|
+
end
|
198
|
+
|
199
|
+
test 'new form' do
|
200
|
+
visit '/items/new'
|
201
|
+
|
202
|
+
assert_equal '3', find('input#item_name')[:minlength]
|
203
|
+
assert_equal '10', find('textarea#item_description')[:minlength]
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
if defined? ActiveRecord
|
5
|
+
class Html5Validators::ActiveRecordExtensionTest < ActiveSupport::TestCase
|
6
|
+
test 'An AR model' do
|
7
|
+
assert_respond_to Class.new(ActiveRecord::Base), :auto_html5_validation
|
8
|
+
end
|
9
|
+
|
10
|
+
test "Changing a model's auto_html5_validation value doesn't affect other model's auto_html5_validation value" do
|
11
|
+
cow = Class.new ApplicationRecord
|
12
|
+
horse = Class.new ApplicationRecord
|
13
|
+
cow.auto_html5_validation = false
|
14
|
+
|
15
|
+
assert_equal true, horse.auto_html5_validation
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,22 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
3
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
4
|
# load Rails first
|
4
5
|
require 'rails'
|
5
|
-
require '
|
6
|
+
require 'bundler/setup'
|
7
|
+
Bundler.require
|
8
|
+
|
6
9
|
# needs to load the app before loading rspec/rails => capybara
|
7
10
|
require 'fake_app'
|
8
|
-
require '
|
11
|
+
require 'test/unit/rails/test_help'
|
9
12
|
# Requires supporting files with custom matchers and macros, etc,
|
10
13
|
# in ./support/ and its subdirectories.
|
11
14
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
config.expect_with(:rspec) { |c| c.syntax = :should }
|
16
|
-
end
|
17
|
-
|
18
|
-
config.before :all do
|
19
|
-
ActiveRecord::Migration.verbose = false
|
20
|
-
CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'people'
|
21
|
-
end
|
22
|
-
end
|
16
|
+
ActiveRecord::Migration.verbose = false
|
17
|
+
CreateAllTables.up
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html5_validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: test-unit-rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- gemfiles/Gemfile.rails-4.0
|
86
86
|
- gemfiles/Gemfile.rails-4.1
|
87
87
|
- gemfiles/Gemfile.rails-4.2
|
88
|
+
- gemfiles/Gemfile.rails-5.0
|
88
89
|
- gemfiles/Gemfile.rails-edge
|
89
90
|
- html5_validators.gemspec
|
90
91
|
- lib/html5_validators.rb
|
@@ -94,10 +95,10 @@ files:
|
|
94
95
|
- lib/html5_validators/active_model/validations.rb
|
95
96
|
- lib/html5_validators/active_record/base.rb
|
96
97
|
- lib/html5_validators/version.rb
|
97
|
-
-
|
98
|
-
-
|
99
|
-
-
|
100
|
-
-
|
98
|
+
- test/fake_app.rb
|
99
|
+
- test/features/validation_test.rb
|
100
|
+
- test/models/active_record/inherited_test.rb
|
101
|
+
- test/test_helper.rb
|
101
102
|
homepage: https://github.com/amatsuda/html5_validators
|
102
103
|
licenses:
|
103
104
|
- MIT
|
@@ -118,13 +119,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
119
|
version: '0'
|
119
120
|
requirements: []
|
120
121
|
rubyforge_project: html5_validators
|
121
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.6.8
|
122
123
|
signing_key:
|
123
124
|
specification_version: 4
|
124
125
|
summary: Automatic client side validation using HTML5 Form Validation
|
125
126
|
test_files:
|
126
|
-
-
|
127
|
-
-
|
128
|
-
-
|
129
|
-
-
|
130
|
-
has_rdoc:
|
127
|
+
- test/fake_app.rb
|
128
|
+
- test/features/validation_test.rb
|
129
|
+
- test/models/active_record/inherited_test.rb
|
130
|
+
- test/test_helper.rb
|
@@ -1,205 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
feature 'person#new' do
|
4
|
-
context 'without validation' do
|
5
|
-
scenario 'new form' do
|
6
|
-
visit '/people/new'
|
7
|
-
page.should have_css('input#person_name')
|
8
|
-
page.should_not have_css('input#person_name[required=required]')
|
9
|
-
end
|
10
|
-
|
11
|
-
scenario 'new_without_html5_validation form' do
|
12
|
-
visit '/people/new_without_html5_validation'
|
13
|
-
page.should have_css('input#person_email')
|
14
|
-
page.should_not have_css('input#person_email[required=required]')
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'with required validation' do
|
19
|
-
background do
|
20
|
-
Person.validates_presence_of :name, :bio
|
21
|
-
end
|
22
|
-
after do
|
23
|
-
Person._validators.clear
|
24
|
-
end
|
25
|
-
scenario 'new form' do
|
26
|
-
visit '/people/new'
|
27
|
-
|
28
|
-
find('input#person_name')[:required].should == 'required'
|
29
|
-
find('textarea#person_bio')[:required].should == 'required'
|
30
|
-
end
|
31
|
-
scenario 'new_without_html5_validation form' do
|
32
|
-
visit '/people/new_without_html5_validation'
|
33
|
-
|
34
|
-
find('input#person_name')[:required].should be_nil
|
35
|
-
end
|
36
|
-
scenario 'new_with_required_true form' do
|
37
|
-
visit '/people/new_with_required_true'
|
38
|
-
|
39
|
-
find('input#person_email')[:required].should == 'required'
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'disabling html5_validation in class level' do
|
43
|
-
background do
|
44
|
-
Person.class_eval do |kls|
|
45
|
-
kls.auto_html5_validation = false
|
46
|
-
end
|
47
|
-
end
|
48
|
-
after do
|
49
|
-
Person.class_eval do |kls|
|
50
|
-
kls.auto_html5_validation = nil
|
51
|
-
end
|
52
|
-
end
|
53
|
-
scenario 'new form' do
|
54
|
-
visit '/people/new'
|
55
|
-
|
56
|
-
find('input#person_name')[:required].should be_nil
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'disabling html5_validations in gem' do
|
61
|
-
background do
|
62
|
-
Html5Validators.enabled = false
|
63
|
-
end
|
64
|
-
after do
|
65
|
-
Html5Validators.enabled = true
|
66
|
-
end
|
67
|
-
scenario 'new form' do
|
68
|
-
visit '/people/new'
|
69
|
-
|
70
|
-
find('input#person_name')[:required].should be_nil
|
71
|
-
find('textarea#person_bio')[:required].should be_nil
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context 'with maxlength validation' do
|
77
|
-
background do
|
78
|
-
Person.validates_length_of :name, maximum: 20
|
79
|
-
Person.validates_length_of :bio, maximum: 100
|
80
|
-
end
|
81
|
-
|
82
|
-
scenario 'new form' do
|
83
|
-
visit '/people/new'
|
84
|
-
|
85
|
-
find('input#person_name')[:maxlength].should == '20'
|
86
|
-
find('textarea#person_bio')[:maxlength].should == '100'
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context 'with minlength validation' do
|
91
|
-
background do
|
92
|
-
Person.validates_length_of :name, minimum: 3
|
93
|
-
Person.validates_length_of :bio, minimum: 10
|
94
|
-
end
|
95
|
-
|
96
|
-
scenario 'new form' do
|
97
|
-
visit '/people/new'
|
98
|
-
|
99
|
-
find('input#person_name')[:minlength].should == '3'
|
100
|
-
find('textarea#person_bio')[:minlength].should == '10'
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
feature 'item#new' do
|
106
|
-
context 'without validation' do
|
107
|
-
scenario 'new form' do
|
108
|
-
visit '/items/new'
|
109
|
-
page.should have_css('input#item_name')
|
110
|
-
page.should_not have_css('input#item_name[required=required]')
|
111
|
-
end
|
112
|
-
|
113
|
-
scenario 'new_without_html5_validation form' do
|
114
|
-
visit '/items/new_without_html5_validation'
|
115
|
-
page.should have_css('textarea#item_description')
|
116
|
-
page.should_not have_css('textarea#item_description[required=required]')
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context 'with required validation' do
|
121
|
-
background do
|
122
|
-
Item.validates_presence_of :name, :description
|
123
|
-
end
|
124
|
-
after do
|
125
|
-
Item._validators.clear
|
126
|
-
end
|
127
|
-
scenario 'new form' do
|
128
|
-
visit '/items/new'
|
129
|
-
|
130
|
-
find('input#item_name')[:required].should == 'required'
|
131
|
-
find('textarea#item_description')[:required].should == 'required'
|
132
|
-
end
|
133
|
-
scenario 'new_without_html5_validation form' do
|
134
|
-
visit '/items/new_without_html5_validation'
|
135
|
-
|
136
|
-
find('input#item_name')[:required].should be_nil
|
137
|
-
end
|
138
|
-
scenario 'new_with_required_true form' do
|
139
|
-
visit '/items/new_with_required_true'
|
140
|
-
|
141
|
-
find('input#item_name')[:required].should == 'required'
|
142
|
-
end
|
143
|
-
|
144
|
-
context 'disabling html5_validation in class level' do
|
145
|
-
background do
|
146
|
-
Item.class_eval do |kls|
|
147
|
-
kls.auto_html5_validation = false
|
148
|
-
end
|
149
|
-
end
|
150
|
-
after do
|
151
|
-
Item.class_eval do |kls|
|
152
|
-
kls.auto_html5_validation = nil
|
153
|
-
end
|
154
|
-
end
|
155
|
-
scenario 'new form' do
|
156
|
-
visit '/items/new'
|
157
|
-
|
158
|
-
find('input#item_name')[:required].should be_nil
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context 'disabling html5_validations in gem' do
|
163
|
-
background do
|
164
|
-
Html5Validators.enabled = false
|
165
|
-
end
|
166
|
-
after do
|
167
|
-
Html5Validators.enabled = true
|
168
|
-
end
|
169
|
-
scenario 'new form' do
|
170
|
-
visit '/items/new'
|
171
|
-
|
172
|
-
find('input#item_name')[:required].should be_nil
|
173
|
-
find('textarea#item_description')[:required].should be_nil
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
context 'with maxlength validation' do
|
179
|
-
background do
|
180
|
-
Item.validates_length_of :name, maximum: 20
|
181
|
-
Item.validates_length_of :description, maximum: 100
|
182
|
-
end
|
183
|
-
|
184
|
-
scenario 'new form' do
|
185
|
-
visit '/items/new'
|
186
|
-
|
187
|
-
find('input#item_name')[:maxlength].should == '20'
|
188
|
-
find('textarea#item_description')[:maxlength].should == '100'
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
context 'with minlength validation' do
|
193
|
-
background do
|
194
|
-
Item.validates_length_of :name, minimum: 3
|
195
|
-
Item.validates_length_of :description, minimum: 10
|
196
|
-
end
|
197
|
-
|
198
|
-
scenario 'new form' do
|
199
|
-
visit '/items/new'
|
200
|
-
|
201
|
-
find('input#item_name')[:minlength].should == '3'
|
202
|
-
find('textarea#item_description')[:minlength].should == '10'
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|