我正在尝试在控制器中测试我的#new 视图
class ApplicationController < ActionController::Base
before_action :current_cart
protect_from_forgery with: :exception
private
def current_cart
@cart = Cart.find(session[:cart_id])
rescue ActiveRecord::RecordNotFound
@cart = Cart.create
session[:cart_id] = @cart.id
@cart
end
end
class controller < ApplicationController
def new
if @cart.line_items.empty?
redirect_to store_url, :notice => "Your cart is empty"
return
end
@order = Order.new
respond_to do |format|
format.html
format.xml { render :xml => @order }
end
end
规格:
describe "GET #new" do
it "renders the :new template" do
product = FactoryGirl.create(:product)
@cart.add_product(product.id)
get :new
response.should render_template :new
end
end
@cart
没有定义??
任何线索,谢谢