Hello Rubyists,
I’m a bit stumped on this one. I have a signup controller that lets
people add their name, email address and a passcode to a mailing list.
When I go through the UI, everything works as I would expect - a record
is added to the appropriate table in the database, and the flash sends
the greeting I want to the next page. But when I run my functional
tests, they blow up! Not sure what to do at this point, so hopefully a
kind soul on here can point me in the right direction.
Okay, the code follows below. There’s no code in the model other than
the usual "validates’ methods, so I didn’t include it.
Error message:
- Failure:
test_sign_up_adds_new_recipient(SignupControllerTest)
[/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/assertions/response_assertions.rb:26:in
assert_response' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/assertions/response_assertions.rb:18:in
assert_response’
/home/kodama/blog/test/functional/signup_controller_test.rb:20:in
`test_sign_up_adds_new_recipient’]:
Expected response to be a <:redirect>, but was <200>
My test method: (all the asserts fail)
def test_sign_up_adds_new_recipient
num_recipients = Recipient.count
post :signup, :signup => {:name => “test”, :email_address =>
“[email protected]”,:passcode => “test”}
assert_response :redirect
assert_equal “Thank you for signing up!”, flash[:notice]
assert_equal num_recipients + 1, Recipient.count
end
My controller code: (standard controller, nothing special other than
this method)
#Add a new recipient through the sign-up sheet
def signup
@recipient = Recipient.new(params[:signup])
if @recipient.save
flash[:notice] = “Thank you for signing up!”
redirect_to :controller => ‘read’, :action => ‘list’
else
render :action => ‘new’
end
end
My view code: (signup/new.rhtml)
<% form_tag :action => ‘signup’ do %>
<%= render :partial => ‘signup’ %>
<%= submit_tag “Sign me up!” %>
<% end %>
The partial:
Thanks,
kodama