-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathvalidation_spec.rb
More file actions
235 lines (199 loc) · 6.06 KB
/
validation_spec.rb
File metadata and controls
235 lines (199 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
require 'spec_helper'
feature 'person#new' do
context 'without validation' do
scenario 'new form' do
visit '/people/new'
page.should have_css('input#person_name')
page.should_not have_css('input#person_name[required=required]')
end
scenario 'new_without_html5_validation form' do
visit '/people/new_without_html5_validation'
page.should have_css('input#person_email')
page.should_not have_css('input#person_email[required=required]')
end
end
context 'with required validation' do
background do
Person.validates_presence_of :name, :bio
end
after do
Person._validators.clear
end
scenario 'new form' do
visit '/people/new'
find('input#person_name')[:required].should == 'required'
find('textarea#person_bio')[:required].should == 'required'
end
scenario 'new_without_html5_validation form' do
visit '/people/new_without_html5_validation'
find('input#person_name')[:required].should be_nil
end
scenario 'new_with_required_true form' do
visit '/people/new_with_required_true'
find('input#person_email')[:required].should == 'required'
end
context 'disabling html5_validation in class level' do
background do
Person.class_eval do |kls|
kls.auto_html5_validation = false
end
end
after do
Person.class_eval do |kls|
kls.auto_html5_validation = nil
end
end
scenario 'new form' do
visit '/people/new'
find('input#person_name')[:required].should be_nil
end
end
context 'disabling html5_validations in gem' do
background do
Html5Validators.enabled = false
end
after do
Html5Validators.enabled = true
end
scenario 'new form' do
visit '/people/new'
find('input#person_name')[:required].should be_nil
find('textarea#person_bio')[:required].should be_nil
end
end
end
context 'with maxlength validation' do
background do
Person.validates_length_of :name, maximum: 20
Person.validates_length_of :bio, maximum: 100
end
scenario 'new form' do
visit '/people/new'
find('input#person_name')[:maxlength].should == '20'
find('textarea#person_bio')[:maxlength].should == '100'
end
end
context 'with minlength validation' do
background do
Person.validates_length_of :name, minimum: 3
Person.validates_length_of :bio, minimum: 10
end
scenario 'new form' do
visit '/people/new'
find('input#person_name')[:minlength].should == '3'
find('textarea#person_bio')[:minlength].should == '10'
end
end
context 'with validation context' do
background do
Person.validates_presence_of :name, :bio, {:on => :create}
end
after do
Person._validators.clear
end
scenario 'new form' do
visit '/people/new'
find('input#person_name')[:required].should be_nil
find('textarea#person_bio')[:required].should be_nil
end
end
end
feature 'item#new' do
context 'without validation' do
scenario 'new form' do
visit '/items/new'
page.should have_css('input#item_name')
page.should_not have_css('input#item_name[required=required]')
end
scenario 'new_without_html5_validation form' do
visit '/items/new_without_html5_validation'
page.should have_css('textarea#item_description')
page.should_not have_css('textarea#item_description[required=required]')
end
end
context 'with required validation' do
background do
Item.validates_presence_of :name, :description
end
after do
Item._validators.clear
end
scenario 'new form' do
visit '/items/new'
find('input#item_name')[:required].should == 'required'
find('textarea#item_description')[:required].should == 'required'
end
scenario 'new_without_html5_validation form' do
visit '/items/new_without_html5_validation'
find('input#item_name')[:required].should be_nil
end
scenario 'new_with_required_true form' do
visit '/items/new_with_required_true'
find('input#item_name')[:required].should == 'required'
end
context 'disabling html5_validation in class level' do
background do
Item.class_eval do |kls|
kls.auto_html5_validation = false
end
end
after do
Item.class_eval do |kls|
kls.auto_html5_validation = nil
end
end
scenario 'new form' do
visit '/items/new'
find('input#item_name')[:required].should be_nil
end
end
context 'disabling html5_validations in gem' do
background do
Html5Validators.enabled = false
end
after do
Html5Validators.enabled = true
end
scenario 'new form' do
visit '/items/new'
find('input#item_name')[:required].should be_nil
find('textarea#item_description')[:required].should be_nil
end
end
end
context 'with maxlength validation' do
background do
Item.validates_length_of :name, maximum: 20
Item.validates_length_of :description, maximum: 100
end
scenario 'new form' do
visit '/items/new'
find('input#item_name')[:maxlength].should == '20'
find('textarea#item_description')[:maxlength].should == '100'
end
end
context 'with minlength validation' do
background do
Item.validates_length_of :name, minimum: 3
Item.validates_length_of :description, minimum: 10
end
scenario 'new form' do
visit '/items/new'
find('input#item_name')[:minlength].should == '3'
find('textarea#item_description')[:minlength].should == '10'
end
end
context 'with validation context' do
background do
Item.validates_presence_of :name, :description, {:on => :create}
end
after do
Item._validators.clear
end
scenario 'new form' do
visit '/items/new'
find('input#item_name')[:required].should be_nil
find('textarea#item_description')[:required].should be_nil
end
end
end