In Rails, how do I test that a particular model method is called by a controller -


i have controller, fooscontroller, wrapping model foo. foo has_many bar.

i can @foo.bars inside contrller, if know bar in turn has other relationships, want efficient , pre-fetch items. simplify it, have defined on model foo method:

def bars_deep   bars.includes([:other,:stuff]) end 

i want test when call methods of controller, calls @foo.bars_deep , not @foo.bars.

how do that? tried using minitest::mock, failed:

f = @foo mock = minitest::mock.new mock.expect :call, nil, [] f.stub :bars_deep, mock   :cmethod, id: @foo end assert mock.verify 

the problem is mocking on this instance of foo, different 1 loaded inside controller.

how can test controller calling bars_deep , preparing , not bars?


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -