0

I have a thorough ability.rb defined that's working properly. However, when I write a controller spec that sends a request to an endpoint, cancan(can) repeatedly returns a 403.

In my ability.rb in the respective section for handling the endpoint I'm testing, when outputting {Model}.all.to_json it's outputting an empty array.

How can I fix this so that it recognizes the data in my test database, or change my test to bypass this?

Noah
  • 390
  • 1
  • 3
  • 15

2 Answers2

0

The data in the test database is reset on each iteration. If you want to use some specific state (e.g. data), you must re-create that state as part of the test.

Depending on the test framework, use the before or setup hook to create the data you need in the test suite before the test itself is executed.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
0

After going through a deep stare down of my code, I realized that one bit of data I wasn't creating through fixtures was failing validation, thus not being created.

My testing environment was setup properly, but I didn't have a create! call but rather a create, causing it not to be explicit with the validation errors.

Noah
  • 390
  • 1
  • 3
  • 15