1
這些是我的Cashout模型的一些代碼。我可以使用rspec測試所有模型,但我不知道如何測試這些示波器。如何用rspec測試示波器
cashout.rb
class Cashout < ActiveRecord::Base
belongs_to :partner
scope :add_virtual_columns, select(
"cashouts.*,
(SELECT SUM(c.amount) FROM cashouts c WHERE c.partner_id = cashouts.partner_id) as total_paid_amount,
(
(
CASE
WHEN (SELECT partner_type FROM partners WHERE cashouts.partner_id = partners.id) = 'administrator'
THEN
(
CASE
WHEN (SELECT SUM(cr.partner_profit) FROM contact_records cr WHERE cr.partner_id in (SELECT id FROM partners WHERE company_id in (SELECT company_id FROM partners WHERE id = cashouts.partner_id))) IS NULL
THEN 0
ELSE (SELECT SUM(cr.partner_profit + cr.company_profit) FROM contact_records cr WHERE cr.partner_id in (SELECT id FROM partners WHERE company_id in (SELECT company_id FROM partners WHERE id = cashouts.partner_id)))
END
)
ELSE
(
CASE
WHEN (SELECT SUM(cr.partner_profit) FROM contact_records cr WHERE cr.partner_id = cashouts.partner_id) IS NULL
THEN 0
ELSE (SELECT SUM(cr.partner_profit) FROM contact_records cr WHERE cr.partner_id = cashouts.partner_id)
END
)
END
)
-
(SELECT SUM(c.amount) FROM cashouts c WHERE c.partner_id = cashouts.partner_id)
) as unpaid_amount"
).group('cashouts.id')
scope :sort_by_total_paid_amount_asc, order("total_paid_amount ASC")
scope :sort_by_total_paid_amount_desc, order("total_paid_amount DESC")
scope :sort_by_unpaid_amount_asc, order("unpaid_amount ASC")
scope :sort_by_unpaid_amount_desc, order("unpaid_amount DESC")
end
你知道如何測試這些示波器使用RSpec和factorygirl?