Reputation: 39
I am querying data from HotDeal
model in Homepage01 which is present in ProductDetailController
like this
def Homepage01
@hotdetail=HotDeal.where("department_id=?",1).limit(15).offset(0)
end
I need to test or validate the data using Rspec. How can i validate data or any mysql error in RSpec or cucumber framework.?
Upvotes: 0
Views: 328
Reputation: 14285
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.
Upvotes: 1