【发布时间】:2017-10-27 06:06:53
【问题描述】:
我在模型中有以下范围
class ProductDetail < ApplicationRecord
scope :currently_active, lambda {
where('? BETWEEN start_time AND end_time', Time.zone.now)
}
end
我为它创建了工厂,但试图弄清楚如何为它编写 rspec。
我试图做类似下面的事情
subject { create(:product_detail) }
describe '#currently_active' do
context '#test' do
it 'test' do
product = build(:product_detail, start_time: Time.now, end_time: Time.now + 30.days)
end
end
end
【问题讨论】:
-
你不应该测试它,因为它是 Rails 的核心功能。专注于业务逻辑。
-
我为控制器添加了 rspec 测试用例。我还需要为范围添加测试用例。
标签: ruby ruby-on-rails-4 rspec