> >>> it "should explicitly set created_by" do
> >>> controller.stub(:current_user) { mock_user }
> >>> mock_order.should_receive(:created_by=).with(mock_user)
> >>> post :create
> >>> end
>
> >>> This is my newly working spec. Does this look well thought out or is
> >>> there some glaring pitfa
> > > Seems reasonable to me. You could test with either an interaction based
> > > approach (use mocks and stubs to confirm that @object receives the
> > > "created_by" message with the expected param) or a state based approach
> > > (hit the controller action and then inspect the system state aft
> Here's a stripped down excerpt from my controller spec. I know how
> Order.should_receive(:method) works, but how do I translate that to an
> instance variable? I've tried assigns(:order).should_receive to no
> avail. Also, where do I put it? Above the post line won't work because
> @order doesn'
> > My controller does something like this for create
> > @object = Object.new(params[:object])
> > @object.created_by = current_user
> > if @object.save... yadda yadda yadda...
>
> > I have my model spec testing for the presence of created_by but I feel
> > compelled to test that my controller is
Looks like I didn't read the instructions before posting...
I'm hoping that the "moderator" is /dev/null - otherwise this might
come up as a repost.
Anyway.
I want my controller to set certain attributes on #create and #update
(mostly created_by, updated_by... etc.) -- implementing this is easy.
T