ruby on rails - How to write tests for spree controller decorator? -


i'd modify things in controller , test them using rspec. want create new action spree::productscontroller. i've tried

routes.rb  resources :products  prodcuts_controller_decorator.rb  spree::productscontroller.class_eval   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   let(:user) {create(:user)}      before(:each)       spree::core::engine.routes       bigplanet::application.routes       controller.stub :spree_current_user => user     end      "render new template"       :new       response.should render_template(:new)     end    end end 

but using original spree::controller , gives

failure/error: :new actioncontroller::routingerror: no route matches {:controller=>"spree/products", :action=>"new"} 

if can shove me in right direction it'd great.

try changing describe from

describe spree::productscontrollerdecorator 

to

describe spree::productscontroller 

rspec infers lot of stuff class being described. you'll want add following rspec file:

before(:each) { @routes = spree::core::engine.routes } 

this manually set routes in rspec include spree routes. since route spree/products_controller#new not defined in application (but in spree instead) you'll have manually override routes this.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -