With this in model:
tracked owner: -> controller, _ { controller.current_user },
parameters: :tracked_attributes I get:
NoMethodError:
undefined method `current_user' for nil:NilClassDespite I have the user signed_in in specs (I use helpers from Devise ...). It seems like the controller is not being passed to model in tests.
Test (here's a controller spec, but the same happens for view spec):
RSpec.describe SomeController, type: :controller do
let(:user ...
context 'user is signed in' do
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
user = create(:user, :active)
sign_in user
end
describe 'GET #some_action' do
it 'loads the requested resource ...' do
get :some_action, params: { id: resource.id }
expect(assigns(:resource)).to eq(resource)
end
end
...Fails on 'get :some_action'. When I debug it with binding.pry just before that line, I can call controller.current_user and it returns proper user resource.