I am having issues testing an overridden action of an Spree Controller Decorator that looks like this:
app/controllers/spree/checkout_controller_decorator.rb
Spree::CheckoutController.class_eval do
def update
do_something
redirect_to my_other_path
end
end
The spec I have is:
spec/controllers/spree/checkout_controller_spec.rb
describe Spree::CheckoutController do
routes { Spree::Core::Engine.routes }
it "does something" do
put :update
end
end
but it is never getting in my update definition, it is getting to the Spree original definition.
I tried reproducing the your above mentioned problem. I did run into the same problem. But after I looked into the test logs, For me it was complaining
Filter chain halted as :ensure_checkout_allowed rendered or redirected
Because of which the overridden controller was never executed. It failed even before it reached the overridden method.
This is what my spec file looks like: spec/controllers/checkout_controller_spec.rb
require "spec_helper"
describe Spree::CheckoutController do
let(:order) {FactoryGirl.create(:spree_order)}
before(:each) do
@routes = Spree::Core::Engine.routes
controller.stub :check_authorization => true
controller.stub :ensure_checkout_allowed => true
controller.stub :ensure_valid_state => true
controller.stub :current_order => order
end
it "does something" do
user = create(:spree_user)
user.spree_roles.create(:name => "admin")
sign_in(user)
puts @routes.inspect
spree_put :update, :order => {}
assigns(:test_obj).should eql(1)
end
end
This is what my overridden controller file looks like: /app/controller/spree/checkout_controller_decorator.rb
Spree::CheckoutController.class_eval do
def update
@test_obj = 1
render :nothing => true
end
end
You might have to stub some before_filters or write some code to make the before_filters pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With