我想修改控制器中的一些东西并使用rspec测试它们.我想为Spree :: ProductsController创建新的操作.这就是我尝试过的
routes.rb resources :products prodcuts_controller_decorator.rb Spree::ProductsController.class_eval do before_filter :authenticate_spree_user!,:except => [:show,:index] def new @product = current_user.products.build end end products_controller_spec.rb require 'spec_helper' describe Spree::ProductsController do let(:user) {create(:user)} before(:each) do Spree::Core::Engine.routes BigPlanet::Application.routes controller.stub :spree_current_user => user end it "render new template" do get :new response.should render_template(:new) end end end
但它使用原始的Spree :: Controller并给出
Failure/Error: get :new ActionController::RoutingError: No route matches {:controller=>"spree/products",:action=>"new"}
如果有人能把我推向正确的方向,那就太好了.
解决方法
原文地址:https://www.jb51.cc/ruby/265057.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。