新手问题 Rails 5.0 升级后 association 中 lambda 的 test 如何实现

teifuania · 2020年04月22日 · 3722 次阅读

新手小白求教。在升级一个 Rails app

Rails 4.2 --> 5.2

Ruby 2.3.x

有一个 model:RemoteEmployee 存在 association 如下

has_one :current_job, -> { current },
        class_name: 'RemoteJobHistory',
        foreign_key: :employee_id,
        primary_key: :employee_id

对应的 unit test 中 代码如下

it 'should have a current_job association' do
  expect(employee).to have_one(:current_job).with_foreign_key(:employee_id).
    class_name('RemoteJobHistory').conditions(:current)
end

升级后 test 报错,

ArgumentError:
  Unsupported argument type: current (Symbol)

原因应该是这个.conditions 被 deprecate 掉了。但是不知道如何解决。求教各位大佬!

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号