質問編集履歴
3
<code>をやってみました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,33 @@
|
|
1
|
+
```ここに言語を入力
|
2
|
+
class UserTest < ActiveSupport::TestCase
|
3
|
+
def Setup
|
4
|
+
@user = User.new(name: "Example User", email: "user@example.com")
|
5
|
+
end
|
6
|
+
|
7
|
+
test "should be valid" do
|
8
|
+
assert_equal @user.valid?
|
9
|
+
end
|
10
|
+
|
11
|
+
test "name should be present" do
|
12
|
+
@user.name = " "
|
13
|
+
assert_not @user.valid?
|
14
|
+
end
|
15
|
+
|
16
|
+
test "email should be present" do
|
17
|
+
@user.email = " "
|
18
|
+
assert_not @user.valid?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
ーーーーーーーーーーーーーーーーーーーーーーー
|
23
|
+
|
24
|
+
class User < ApplicationRecord
|
25
|
+
validates :name, presence: true
|
26
|
+
validates :email, presence: true
|
27
|
+
end
|
28
|
+
|
29
|
+
|
1
|
-
### 前提・実現したいこと
|
30
|
+
```### 前提・実現したいこと
|
2
31
|
現在、Railsチュートリアルの第6章にて、name、email等の賊子の検証テストを行っているのですが、どうしても、No Method errorが出て2か所パスが出来ません。いろいろ他サイトを調べたのですが、適切な答えが見つからず前に進めません。
|
3
32
|
お詳しい方いらっしゃいましたら、ご教示頂けませんでしょうか、よろしくお願いします。
|
4
33
|
|
2
ソースコードをシングルクオーテーションで囲みました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
``
|
25
25
|
app/test/models/user_test.rbファイル
|
26
26
|
↓
|
27
|
-
|
27
|
+
'''
|
28
28
|
require_relative '../test_helper'
|
29
29
|
|
30
30
|
class UserTest < ActiveSupport::TestCase
|
@@ -46,19 +46,17 @@
|
|
46
46
|
assert_not @user.valid?
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
'''
|
50
50
|
|
51
51
|
app/models/user.rbファイル
|
52
52
|
↓
|
53
|
-
|
53
|
+
'''
|
54
|
-
|
55
54
|
class User < ApplicationRecord
|
56
55
|
validates :name, presence: true
|
57
56
|
validates :email, presence: true
|
58
57
|
end
|
58
|
+
'''
|
59
59
|
|
60
|
-
</code>
|
61
|
-
|
62
60
|
```
|
63
61
|
|
64
62
|
### 試したこと
|
1
ソースコードの部分を<code>タグで囲みました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -24,6 +24,7 @@
|
|
24
24
|
``
|
25
25
|
app/test/models/user_test.rbファイル
|
26
26
|
↓
|
27
|
+
<code>
|
27
28
|
require_relative '../test_helper'
|
28
29
|
|
29
30
|
class UserTest < ActiveSupport::TestCase
|
@@ -45,14 +46,18 @@
|
|
45
46
|
assert_not @user.valid?
|
46
47
|
end
|
47
48
|
end
|
49
|
+
</code>
|
48
50
|
|
49
51
|
app/models/user.rbファイル
|
50
52
|
↓
|
53
|
+
<code>
|
54
|
+
|
51
55
|
class User < ApplicationRecord
|
52
56
|
validates :name, presence: true
|
53
57
|
validates :email, presence: true
|
54
58
|
end
|
55
59
|
|
60
|
+
</code>
|
56
61
|
|
57
62
|
```
|
58
63
|
|