RSpec shared context "with current_organization setting" does not work with Grape API
In !143978 (merged), a Rspec shared context was introduced that would set the Current.organization
attribute to an organization. This allows us to have code like:
RSpec.describe Something do
it 'uses current organization', :with_current_organization do
expect(described_class.organization).to eq(current_organization)
end
end
This works fine for Rails controllers. But not for specs that use Grape API.
Some findings:
-
Current.reset
is called three times when:with_current_organization
context is used -
Current.reset
is called only once (as expected) when:with_current_organization
context is NOT used - GET/POST does not matter
- A simple example that does not fail has been added to the comments.
Implementation
Mock Current.organization
in this helper.
Edited by Rutger Wessels