我正在尝试让let a = [{ id: 1 }, { id: 2 }]
let one = a[0]
let two = a[1]
console.log(a[0])
console.log(a[1])
[one, two] = [two, one]
console.log(a[0])
console.log(a[1])
返回一个字符串。如果未设置,则应该对外部服务进行调用,设置并返回。
这里更详细的是我的测试:
@user.stripe_customer_id
其中context 'Stripe ID' do
it 'should not be writable' do
expect { @user.stripe_customer_id = 'random_id_123123' }
.to raise_error(NoMethodError)
end
it 'should be generated if it does not exist' do
@user.save
expect(@user.stripe_customer_id).to include('cus')
end
end
是有效的@user
实例。
Rspec失败并出现以下情况:
User << ActiveRecord
Failed examples:
rspec ./spec/models/user_spec.rb:87 # User Stripe ID should be generated if it does not exist
文件包含以下行:
User.rb
答案 0 :(得分:1)
您正在尝试覆盖stripe_customer_id
def stripe_customer_id
self[:stripe_customer_id] || write_attribute(:stripe_customer_id, new_customer_id)
end
这是我刚刚写完的未经测试的代码。但我很确定这应该适合您的情况。请试试让我知道。