def get_payment
@payment = current_merchant.payments.find_by_id(params[:id]) if params[:id].match(/^(\d)+$/)
@payment ||= current_merchant.payments.find_by_reference(params[:id])
raise ActiveRecord::RecordNotFound if @payment.nil?
@payment
end
我已经为上面的代码编写了rspec但是看起来不合理。我已经为上面的代码编写了rspec但似乎不合理 Params [:id]仅包含整数,params [:reference]包含两个数字
describe "GET show" do
it "can find payment by id" do
get :show, id: payment.id
expect(response).to be_success
expect(assigns(:payment)).to eq(payment)
end
it "can find payment by reference" do
get :show, id: payment.reference
expect(response).to be_success
expect(assigns(:payment)).to eq(payment)
end
end