質問編集履歴

3

追記

2019/10/08 01:18

投稿

Tsuyoponpon
Tsuyoponpon

スコア33

test CHANGED
File without changes
test CHANGED
@@ -46,7 +46,7 @@
46
46
 
47
47
 
48
48
 
49
- ###原因は判明しました!
49
+ ###追記:原因は判明しました!(解決方法はわかりません)
50
50
 
51
51
  ```
52
52
 

2

追記

2019/10/08 01:18

投稿

Tsuyoponpon
Tsuyoponpon

スコア33

test CHANGED
File without changes
test CHANGED
@@ -44,52 +44,48 @@
44
44
 
45
45
  ```
46
46
 
47
- ### 考えられる原因
48
47
 
49
- View(root_path)はこんな感じなのですが、、、
50
48
 
51
- ```erb
49
+ ###原因は判明しました!
52
50
 
51
+ ```
52
+
53
- #index.html.erb
53
+ #RecruitmentInfosController
54
54
 
55
55
 
56
56
 
57
- <% @recruitment_infos.each do |recruitment_info|%>
58
-
59
- <p><%= recruitment_info.title %></p>
60
-
61
- <p class="group_name"><%= recruitment_info.group %></p>
62
-
63
- <p><%= recruitment_info.content %></p>
64
-
65
- <a href="<%= recruitment_info.url %>"><%= recruitment_info.url %></a>
66
-
67
- <% end %>
68
-
69
-
70
-
71
- ```
72
-
73
- この前のコントローラーで、
74
-
75
- ```ruby
76
-
77
57
  def index
78
58
 
79
- @organization = VolunteerOrganization.select("name")
59
+ @organization = Organization.select("name")
80
60
 
81
61
  @recruitment_infos = RecruitmentInfo.where(group: @organization)
82
62
 
83
63
  end
84
64
 
65
+ ```
85
66
 
67
+ 以前は、「@organization => []」で失敗していましたが、これの原因は以下のバリデーションでした。
86
68
 
69
+ ```ruby
70
+
87
- (byebug)@organization => #<ActiveRecord::Relation []>
71
+ class Organization < ApplicationRecord
72
+
73
+ def undefinde_organization_name
74
+
75
+ errors.add(:name, 'この団体の求人情報はありません') unless RecruitmentInfo.find_by(group: name)
76
+
77
+ end
78
+
79
+ end
88
80
 
89
81
  ```
90
82
 
91
- まぁそら**「expected to find css ".group_name" but there were no matches」**で失敗すわな思うのすが、**この配列が空になる理由がわかりません**
83
+ そしてこのバリデーションが失敗する原因は、**「RecruitmentInfo=>[]」**でとでした
92
84
 
93
- たぶんテストの書き方が違うのかなとは思うのですが。。。
94
85
 
95
- もし解決策をご存知の方がおられましたら、ご教授いただけますと幸いです。
86
+
87
+
88
+
89
+ つまり、RecruitmentInfoモデル自体に、**テーブルが全く無い状態**でした。。。
90
+
91
+ ここにはスクレイピングで取得した情報を格納しているのですが、**テスト環境のDBには全く入っていない**ようです。ということは、**「テスト環境で開発環境のDBに接続する方法」**もしくは、**「rails r 'RecruitmentInfo'」のようにして、テスト環境でスクレイピングを実行し、テスト環境のDBに格納する方法」**が分かれば解決できるのかと思います。引き続き必死でその方法を探していますが、ご存知であればご教授いただけますと幸いです。

1

2019/10/08 01:14

投稿

Tsuyoponpon
Tsuyoponpon

スコア33

test CHANGED
File without changes
test CHANGED
@@ -88,7 +88,7 @@
88
88
 
89
89
  ```
90
90
 
91
- まぁ、そら**「expected to find css ".group_name" but there were no matches」**で失敗するわなとうのですが、**この配列が空になる理由がわかりません。**
91
+ まぁ、そら**「expected to find css ".group_name" but there were no matches」**で失敗するわなとうのですが、**この配列が空になる理由がわかりません。**
92
92
 
93
93
  たぶんテストの書き方が違うのかなとは思うのですが。。。
94
94