質問編集履歴
1
モデルを追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,6 +16,35 @@
|
|
16
16
|
Finished in 9.78 seconds (files took 1.4 seconds to load)
|
17
17
|
1 example, 1 failure
|
18
18
|
```
|
19
|
+
|
20
|
+
**モデル**
|
21
|
+
```SouvenirModel
|
22
|
+
class Souvenir < ApplicationRecord
|
23
|
+
belongs_to :user
|
24
|
+
mount_uploader :picture ,PictureUploader
|
25
|
+
validates:name, presence: true,length: {maximum:70}
|
26
|
+
validates:comment, presence: true,length: {maximum:250}
|
27
|
+
validates:spot, presence: true
|
28
|
+
validates:price, presence: true
|
29
|
+
validates:genre, presence: true
|
30
|
+
validate :picture_size
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def picture_size
|
35
|
+
if picture.size > 5.megabytes
|
36
|
+
errors.add(:picture, "should be less than 5MB")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def souvenir_params
|
41
|
+
params.require(:souvenirs).permit(:name, :spot, :price, :genre, :picture, :comment)
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
```
|
19
48
|
**コントローラー**
|
20
49
|
```SouvenirController
|
21
50
|
class SouvenirsController < ApplicationController
|
@@ -66,6 +95,22 @@
|
|
66
95
|
end
|
67
96
|
end
|
68
97
|
```
|
98
|
+
```UserFactory
|
99
|
+
FactoryBot.define do
|
100
|
+
|
101
|
+
factory :user, class: User do
|
102
|
+
name { "MyString" }
|
103
|
+
email { "MyString@gmail.com" }
|
104
|
+
password {"MyString"}
|
105
|
+
password_confirmation {"MyString"}
|
106
|
+
|
107
|
+
trait :failure do
|
108
|
+
name {' '}
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
```
|
69
114
|
###試したこと
|
70
115
|
RequestSpec中にsouvenirインスタンスが生成されたことはdebuggerで確認できました。
|
71
116
|
```
|