Closed rlee0001 closed 8 years ago
Figured this out. FactoryGirl
was being included in test_helper.rb
, and adding itself as an ancestor of Object
, defining a create
method there. Any method defined by an abstract superclass of your controller is automatically excluded from action_methods. This issue wasn't related to JSONAPI::Resources, and could affect any rails project. I guess, be careful with what you include in test_helper.rb
.
I'm trying to create a controller test using
MiniTest
to test myJSONAPI::ResourceController
. Most of the actions work fine from within the test (index, show, update, etc...), but when I try to call create, I get anActionNotFound
error. This is happening for allJSONAPI::ResourceController
s, always for thecreate
action. When tested from a web browser with the server actually running,create
works perfectly fine. So it has something to do with testing.My test looks like this:
post :create, data: { ... }
And the error is:
Using pry and poking around a bit, I've determined that the immediate cause is here:
For the
JSONAPI::ResourceController
s, thataction_method?
check returns false for thecreate
action. Going deeper, I get this:And inspecting
self.class.action_methods
gives this:Note the absence of the
create
action. I just can't figure out why. I don't do anything interesting in the controller...in fact, the controller is blank except my implementation ofcontext
andbase_response_meta
and my inclusion ofPundit
. I just extendJSONAPI::ResourceController
.Since this is only an issue when running tests, I'm wondering if there is something
JSONAPI::Resources
is doing, somethingPundit
is doing, or somethingMiniTest
is doing.