rspec/rspec-rails — Issue #513: rspec custom put action in rails 3.1.3 with rspec2 not working
Author: emclab
Created: 2012-03-05 18:47:17+00:00
State: open

Not sure if this is a right place to post this problem. There is a custom approve action in our purchasing controller. The approve action sets the 3 values for 3 fields. The approve works as designed in our test. However we could not find a way to rspec it. Here is our rspec code:

it "should approve for vp_eng" do
session[:vp_eng] = true
proj = Factory(:project)
u = Factory(:user)
session[:user_id] = u.id
pur = Factory(:sourcing, :input_by_id => u.id, :approved_by_vp_eng => false)
put 'approve', :project_id => proj.id, :id => pur.id, :purchasing => {:approved_by_vp_eng => true, :approve_vp_eng_id => session[:user_id]},:method => :put
pur.reload.approve_vp_eng_id.should == session[:user_id]
end

The error is that Got nil, expected 1 (u.id). Here is the code in routes.rb:

resources :purchasings, :only => [:index, :new, :create, :edit, :update, :show] do
member do
put :approve
end
end

The put was not executed (it was executed as get most likely) and none has been changed. Any suggestion? Thank so much