我正在尝试对查询结果进行存根以检索一些记录。这是查询:
ouid = OrganizationalUnit.where("billing_id = ? AND status = 'active'", data[:billing_id]).select(:id)
user_id = User.where("group_id in (14,17) AND organizational_unit_id in (?) AND status = 'active'", ouid).select(:id).first
我试图用这个来存根:
ou_value = double'fake ou',{ 'id' => '654321' }
select_double = double 'fake select', {'select' => [ou_value]}
OrganizationalUnit.stub( :where).and_return(select_double)
这是行不通的。我对用户表的查询如下所示:
SELECT id FROM `users` WHERE (group_id in (14,17) AND organizational_unit_id in ('--- !ruby/object:RSpec::Mocks::Mock\n__null_object: false\nname: fake ou\noptions:\n :__declared_as: Double\n') AND status = 'active') LIMIT 1
它应该看起来像这样:
SELECT id FROM `users` WHERE (group_id in (14,17) AND organizational_unit_id in (654321) AND status = 'active') LIMIT 1
我究竟做错了什么?
谢谢