I have the following controller action and test. I'm new to testing with Shoulda and I know there are areas of my controller that I can test further. For example, my flash messages as well as verifying the renders.
So my question is, how would I properly test this controller action in Shoulda?
My controller action (names have been changed to protect the innocent):
def my_action
return redirect_to(root_url) if @site.nil?
@owner = current_site.owner
if request.post?
if params[:password].blank? || params[:email].blank?
flash[:error] = "You must fill in both the e-mail and password fields"
render :action => "my_action"
else
if @owner.authenticated?(params[:password])
@owner.login = params[:email]
@owner.save!
@owner.do_some_method
flash[:success] = "Success."
render :action => "my_action"
else
flash[:error] = "Incorrect password"
render :action => "my_action"
end
end
end
end
My test:
context "on POST to :my_action" do
setup do
Owner.any_instance().expects(:do_some_method)
post :my_action, :email => '[email protected]', :password => 'test'
end
should_assign_to :owner
should "Change name and verify password and resend activation key" do
assert_equal true, assigns(:owner).authenticated?('test')
assert_equal '[email protected]', assigns(:owner).login
end
should_respond_with :success
end