我有一个带有以下初始化方法的类来缓存数据库中的所有用户:
payment_id
在我的测试$log = Array();
$items = item::where("id",Auth::user()->id)->get();
foreach($items as $item){
$join_payment = join_payment::where("item_id",$item->id)->first();
if(!array_key_exists($join_payment->payment_id,$log){
$log[$join_payment->payment_id] = payment::where("id",$join_payment->payment_id)->first();
}
$log[$join_payment->payment_id][$item->id] = $item;
}
中,我有:
class Student < People
def initialize
super
@all_users = Hash[User.pluck(:name, :id)]
end
def get_id(name)
# puts @all_users => {}
return @all_users[name]
end
end
我的测试失败,因为@all_users为空{}。我无法弄清楚出了什么问题。我不想使用describe '#get_id'
。任何想法都表示赞赏。