Is it possible to use the refinements feature to stub a controller action?
I am defining the refinement in "my_controller_refinement.rb"
require "my_controller"
module MyControllerRefinement
refine MyController do
def create_item(my_object = {})
return "test_id"
end
end
end
And using it in the test as follows -
require_relative "my_controller_refinement"
class MyControllerTest < ActionController::TestCase
using MyControllerRefinement
test "get item" do
post :create { my_object: { name: "Test", id: "test_id" } }
# Post redirects to the show page
assert_redirected_to action: "show", id: "test_id"
end
end
The test dir is as -
test/
--> my_controller_refinement.rb
--> my_controller_test.rb
But the refinement doesnt kick in and the actual controller action seems to get called.
Am I missing something or can refinements not be used for such "stubbing" ?
This won't work because of the way Refinements work currently. The docs (cited below) have the full scoop, but in essence the scoping on a refinement is very narrow.