0

我正在从HotDealHomepage01 中的模型中查询数据,该模型存在于ProductDetailController这样的

def Homepage01
    @hotdetail=HotDeal.where("department_id=?",1).limit(15).offset(0)
end

我需要使用 Rspec 测试或验证数据。如何验证 RSpec 或黄瓜框架中的数据或任何 mysql 错误。?

4

1 回答 1

1

Create a hotdeal factory using factory girl with department_id 1.

Inside your product_detail_controller_spec.rb (which should rather be plural btw, i.e. product_details for your controller and your spec) write:

require 'spec_helper'

describe ClientsController do
  describe "GET Homepage01" do
    it "assigns the right records" do
      FactoryGirl.create(:hot_deal)
      hotdetail = HotDeal.where("department_id=?",1).limit(15).offset(0)
      get "Homepage01"
      assigns(:hotdetail).should eq(hotdetail)
    end
  end
end

This will make sure that your query works 1) technically and 2) as expected.

于 2013-04-04T12:10:38.210 回答