Forum: Ruby on Rails TypeError while doing tests

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
373c4dd765755059d502b2077c1722b9?d=identicon&s=25 Emilio Tagua (Guest)
on 2007-07-12 18:57
(Received via mailing list)
I have a problem testing an invalid situation, the valid situation
without merging params (or merging valid ones) works fine.

Controller:
# @user is setted with a filter

  def update
    if @user.update_attributes(params[:user])
      redirect_to(user_path(@user))
    else
      render :action => :show
    end
  end

Test:

  def test_should_not_update_user
    # Set session values
    session_company :one
    login_as        :emilio
    # I choose a name that invalid (is too short)
    update_user(:name => 's')
    assert          !users(:emilio).errors.empty?,
users(:emilio).errors.full_messages
    assert_response :success
  end

protected
  def update_user(options = {})
    put :update, :user => { :name => 'Testing name', :street => 'test
street',
                               :city => 'Testing City', :zipcode =>
'556678',
                               :state => 'Testing State', :country =>
'Argentina',
                               :password_actual => 'test',
                               :password => 'testing',
:password_confirmation => 'testing' }.merge(options)
  end

Test Output:
Started
E...
Finished in 0.214897 seconds.

  1) Error:
test_should_not_update_user(UsersControllerTest):
TypeError: can't convert nil into String

.....


Why i get an error on invalid name if the controller just render the
same page passing user errors...

Thanks in advance!
This topic is locked and can not be replied to.