質問編集履歴
2
該当ソースコードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -102,6 +102,162 @@
|
|
102
102
|
|
103
103
|
### 該当のソースコード
|
104
104
|
|
105
|
+
```usertest
|
106
|
+
|
107
|
+
require 'test_helper'
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
class UserTest < ActiveSupport::TestCase
|
112
|
+
|
113
|
+
def setup
|
114
|
+
|
115
|
+
@user = User.new(name: "Example User", email: "user@example.com",
|
116
|
+
|
117
|
+
password: "foobar", password_confirmation: "foobar")
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
test "should be valid" do
|
124
|
+
|
125
|
+
assert @user.valid?
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
test "name should be present" do
|
132
|
+
|
133
|
+
@user.name = ""
|
134
|
+
|
135
|
+
assert_not @user.valid?
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
test "email should be present" do
|
142
|
+
|
143
|
+
@user.email = " "
|
144
|
+
|
145
|
+
assert_not @user.valid?
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
test "name should not be too long" do
|
152
|
+
|
153
|
+
@user.name = "a" * 51
|
154
|
+
|
155
|
+
assert_not @user.valid?
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
test "email should not be too long" do
|
162
|
+
|
163
|
+
@user.email = "a" * 244 + "@example.com"
|
164
|
+
|
165
|
+
assert_not @user.valid?
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
test "email validation should accept valid addresses" do
|
172
|
+
|
173
|
+
valid_addresses = %w[user@example.com USER@foo.COM A_US-ER@foo.bar.org
|
174
|
+
|
175
|
+
first.last@foo.jp alice+bob@baz.cn]
|
176
|
+
|
177
|
+
valid_addresses.each do |valid_address|
|
178
|
+
|
179
|
+
@user.email = valid_address
|
180
|
+
|
181
|
+
assert @user.valid?, "#{valid_address.inspect} should be valid"
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
test "email validation should reject invalid addresses" do
|
190
|
+
|
191
|
+
invalid_addresses = %w[user@example,com user_at_foo.org user.name@example.
|
192
|
+
|
193
|
+
foo@bar_baz.com foo@bar+baz.com]
|
194
|
+
|
195
|
+
invalid_addresses.each do |invalid_address|
|
196
|
+
|
197
|
+
@user.email = invalid_address
|
198
|
+
|
199
|
+
assert_not @user.valid?, "#{invalid_address.inspect} should be invalid"
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
test "email addresses should be unique" do
|
208
|
+
|
209
|
+
duplicate_user = @user.dup
|
210
|
+
|
211
|
+
duplicate_user.email = @user.email.upcase
|
212
|
+
|
213
|
+
@user.save
|
214
|
+
|
215
|
+
assert_not duplicate_user.valid?
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
test "email addresses should be saved as lower-case" do
|
222
|
+
|
223
|
+
mixed_case_email = "Foo@ExAMPle.CoM"
|
224
|
+
|
225
|
+
@user.email = mixed_case_email
|
226
|
+
|
227
|
+
@user.save
|
228
|
+
|
229
|
+
assert_equal mixed_case_email.downcase, @user.reload.email
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
test "" do
|
236
|
+
|
237
|
+
@user.password = @user.password_confirmation = " " * 6
|
238
|
+
|
239
|
+
assert_not @user.valid?
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
test do
|
246
|
+
|
247
|
+
@user.password = @user.password_confirmation = "a" * 5
|
248
|
+
|
249
|
+
assert_not @user.vaild?
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
```
|
258
|
+
|
259
|
+
|
260
|
+
|
105
261
|
|
106
262
|
|
107
263
|
```Gimfile
|
@@ -198,7 +354,7 @@
|
|
198
354
|
|
199
355
|
|
200
356
|
|
201
|
-
```
|
357
|
+
```
|
202
358
|
|
203
359
|
$ rails db:drop
|
204
360
|
|
@@ -212,7 +368,7 @@
|
|
212
368
|
|
213
369
|
|
214
370
|
|
215
|
-
```
|
371
|
+
```
|
216
372
|
|
217
373
|
$rake db:migrate:reset
|
218
374
|
|
@@ -222,7 +378,7 @@
|
|
222
378
|
|
223
379
|
|
224
380
|
|
225
|
-
```
|
381
|
+
```
|
226
382
|
|
227
383
|
$bundle install
|
228
384
|
|
@@ -232,7 +388,7 @@
|
|
232
388
|
|
233
389
|
|
234
390
|
|
235
|
-
```
|
391
|
+
```
|
236
392
|
|
237
393
|
$ sudo yum install -y tmux
|
238
394
|
|
1
タイトル
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rails
|
1
|
+
railsテストでwrong number of argumentsのエラー出て困っています
|
test
CHANGED
File without changes
|