I've looked around several questions on SO and can't find exactly what I'm looking for.
I have a simple rails controller. with a new method and private method:
class FooController < ApplicationController
before_action :load_bar
def new
@foo = @bar.foos.build
end
private
def load_bar
@bar = Bar.find params[:bar_id]
end
end
How do I properly test the new method, and should I be testing the load_bar method? I'm currently doing the following, but it doesn't feel quite right:
describe FooController do
let(:bar) { create(:bar) }
context 'GET new' do
let(:foo) { mock_model(Foo) }
it 'should assign a @foo' do
Bar.should_receive(:find).and_return(bar)
bar.stub_chain(:foos, :build).and_return(foo)
get :new, bar_id: bar
assigns(:foo).should == foo
end
end
end