質問編集履歴
3
文字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -85,6 +85,8 @@
|
|
85
85
|
```
|
86
86
|
|
87
87
|
|
88
|
+
|
89
|
+
factories/master_costs.rb
|
88
90
|
|
89
91
|
```ruby
|
90
92
|
|
2
説明変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
Rspecでコントローラーのテストを行っていたところ、Ransack
|
1
|
+
Rspecでコントローラーのテストを行っていたところ、Ransackの検索テストでエラーが発生し、自分一人では解決に至らないので質問させていただきます。
|
2
2
|
|
3
3
|
|
4
4
|
|
5
5
|
http://biboroku.megaya.net/entry/2015/02/02/150619
|
6
6
|
|
7
|
-
上記の記事を参考に
|
7
|
+
上記の記事を参考にコードを書いています。
|
8
8
|
|
9
9
|
|
10
10
|
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
いつも大変お世話になっております。
|
2
|
-
|
3
1
|
Rspecでコントローラーのテストを行っていたところ、Ransack周りのテストだけ全く上手くいかず質問させていただきます。
|
4
2
|
|
5
3
|
|
@@ -36,31 +34,41 @@
|
|
36
34
|
|
37
35
|
|
38
36
|
|
37
|
+
Failures:
|
38
|
+
|
39
|
+
|
40
|
+
|
39
|
-
1) MasterCostsController GET #index search
|
41
|
+
1) MasterCostsController GET #index when master_costs searched
|
40
42
|
|
41
43
|
Failure/Error: @params[:q][:name_cont] = 'あああ'
|
42
44
|
|
45
|
+
|
46
|
+
|
43
47
|
NoMethodError:
|
44
48
|
|
45
|
-
undefined method `[]' for nil:NilClass
|
49
|
+
undefined method `[]' for nil:NilClass
|
50
|
+
|
51
|
+
# ./spec/controllers/master_costs_controller_spec.rb:28:in `block (4 levels) in <top (required)>'
|
46
52
|
|
47
53
|
|
48
54
|
|
49
|
-
|
55
|
+
Finished in 0.34403 seconds (files took 8.81 seconds to load)
|
56
|
+
|
57
|
+
3 examples, 1 failure
|
50
58
|
|
51
59
|
|
52
60
|
|
53
61
|
Failed examples:
|
54
62
|
|
63
|
+
|
64
|
+
|
55
|
-
rspec ./spec/controllers/master_costs_controller_spec.rb:2
|
65
|
+
rspec ./spec/controllers/master_costs_controller_spec.rb:27 # MasterCostsController GET #index when master_costs searched
|
56
66
|
|
57
67
|
```
|
58
68
|
|
59
69
|
```
|
60
70
|
|
61
71
|
app/controllers/master_costs_controller.rb
|
62
|
-
|
63
|
-
|
64
72
|
|
65
73
|
|
66
74
|
|
@@ -80,19 +88,47 @@
|
|
80
88
|
|
81
89
|
```ruby
|
82
90
|
|
91
|
+
FactoryGirl.define do
|
92
|
+
|
83
|
-
|
93
|
+
factory :master_cost do
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
sequence(:code)
|
98
|
+
|
99
|
+
sequence(:name) { |i| "MasterCostName#{ i }" }
|
100
|
+
|
101
|
+
cost_class { MasterCost.cost_classes.values.sample }
|
102
|
+
|
103
|
+
budger_class { MasterCost.budget_classes.values.sample }
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
@params = Hash.new,
|
108
|
+
|
109
|
+
@params[:q] = Hash.new
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
|
84
116
|
|
85
117
|
|
86
118
|
|
87
119
|
FactoryGirl.define do
|
88
120
|
|
89
|
-
f
|
121
|
+
before :each do
|
90
122
|
|
91
|
-
@
|
123
|
+
@data1 = create(:data, code: 1, name: 'あああ', cost_class: 1, budger_class: 'A')
|
92
124
|
|
93
|
-
@
|
125
|
+
@data2 = create(:data, code: 2, name: 'いいい', cost_class: 2, budger_class: 'AB')
|
94
126
|
|
127
|
+
@data3 = create(:data, code: 3, name: 'ううう', cost_class: 3, budger_class: 'A')
|
128
|
+
|
129
|
+
@params = Hash.new
|
130
|
+
|
95
|
-
@params[:q] = Hash.new
|
131
|
+
@params[:q][] = Hash.new
|
96
132
|
|
97
133
|
end
|
98
134
|
|
@@ -114,19 +150,25 @@
|
|
114
150
|
|
115
151
|
|
116
152
|
|
117
|
-
|
153
|
+
context 'when master_costs searched' do
|
154
|
+
|
155
|
+
before do
|
156
|
+
|
157
|
+
create_list(:master_cost, 10) #検索用のデータ
|
158
|
+
|
159
|
+
end
|
118
160
|
|
119
161
|
|
120
162
|
|
121
|
-
|
163
|
+
specify do
|
122
164
|
|
123
|
-
@params[:q][:name_cont] = 'あああ'
|
165
|
+
@params[:q][:name_cont] = 'あああ'
|
124
166
|
|
125
|
-
get :index, @params
|
167
|
+
get :index, @params
|
126
168
|
|
127
|
-
expect(assigns(:master_costs)).to match
|
169
|
+
expect(assigns(:master_costs)).to match_array([@data1])
|
128
170
|
|
129
|
-
end
|
171
|
+
end
|
130
172
|
|
131
173
|
end
|
132
174
|
|
@@ -134,20 +176,4 @@
|
|
134
176
|
|
135
177
|
|
136
178
|
|
137
|
-
説明が長くなってしまい申し訳ありません。
|
138
|
-
|
139
|
-
エラーログにある
|
140
|
-
|
141
|
-
```
|
142
|
-
|
143
|
-
NoMethodError:
|
144
|
-
|
145
|
-
undefined method `[]' for nil:NilClass
|
146
|
-
|
147
|
-
```
|
148
|
-
|
149
|
-
が
|
179
|
+
[:name_cont]がパラメータを受け取るにはどのようにしたらよいでしょうか?....
|
150
|
-
|
151
|
-
ヒント等頂けましたら幸いです。
|
152
|
-
|
153
|
-
何卒よろしくお願いいたします。
|