質問編集履歴

2

追加説明

2016/10/09 14:25

投稿

s.hiroaki
s.hiroaki

スコア21

test CHANGED
File without changes
test CHANGED
@@ -72,7 +72,7 @@
72
72
 
73
73
  def main_image?
74
74
 
75
- satus == "main_image"
75
+ status == "main_image"
76
76
 
77
77
  end
78
78
 
@@ -115,3 +115,13 @@
115
115
  このようにimage_urlが入ってきません。。。
116
116
 
117
117
  テストを通りません。
118
+
119
+ ちなみに、
120
+
121
+ ```
122
+
123
+ [1] pry(#<RSpec::ExampleGroups::CaptureImage::MainImage>)> capture_image.status = "sub_image"
124
+
125
+ ```
126
+
127
+ とすると、statusは普通に1に変わります。なぜかimage_urlだけ追加・変更不可です。

1

capture_imageモデルの実装コード追加

2016/10/09 14:25

投稿

s.hiroaki
s.hiroaki

スコア21

test CHANGED
File without changes
test CHANGED
@@ -56,27 +56,35 @@
56
56
 
57
57
  ```
58
58
 
59
+ ```ruby
60
+
61
+ class CaptureImage < ActiveRecord::Base
62
+
63
+ belongs_to :prototype
64
+
65
+ enum satus: {main_image: 0, sub_image: 1}
66
+
67
+ mount_uploader :image_url, ImageUploader
68
+
69
+ validates :image_url, presence: true, if: :main_image?
70
+
71
+
72
+
73
+ def main_image?
74
+
75
+ satus == "main_image"
76
+
77
+ end
78
+
79
+ end
80
+
81
+ ```
82
+
83
+ ※capture_imageモデル追加しました。(修正)
84
+
59
85
  (enumでmain_imageかsub_imageか管理しています)
60
86
 
61
87
  ###試したこと
62
-
63
- ```ruby
64
-
65
- describe "#main_image?" do
66
-
67
- it "valid with main_image" do
68
-
69
- capture_image = build(:capture_image, image_url:"rrrrr.png")
70
-
71
- binding.pry
72
-
73
- expect(capture_image).to be_valid
74
-
75
- end
76
-
77
- end
78
-
79
- ```
80
88
 
81
89
  上記のように実装して、binding.pryが起きたところで止めて確認しても、
82
90