[Ror-es] Test funcional, actualizando modelo desde controlador

Héctor Pérez Arenas ruby-forum-incoming at andreas-s.net
Thu Sep 13 17:55:08 GMT 2007


Hola,

Estoy teniendo problemas en los tests funcionales cuando intento
actualizar un modelo desde un controlador[1]. Estoy probándolo en una
aplicación recién creada, que sólo dispone del modelo user y el
controlador users, creados con el scaffold_resource [2].

En el test.log podemos ver como sí se ha modificado el usuario [3] al
final del método update del controlador [4]. Sin embargo, cuando vuelve
al test funcional, @user.name mantiene el valor antiguo. ¿Alguien puede
decirme qué hago mal? Gracias.



[1]
  def test_should_update_user_name
    @user=User.create(:name=>"nombre_inicial")
    put :update, :id => @user.id, :user => {:name=>"no_va"}
    assert_redirected_to user_path(assigns(:user))
    assert_equal "no_va", at user.name                             # <-- NO
VA
  end

  1) Failure:
test_should_update_user_name(UsersControllerTest)
[test/functional/users_controller_test.rb:55]:
<"no_va"> expected but was
<"nombre_inicial">.

[2]
rails prueba
cd prueba
ruby script/generate scaffold_resource user name:string

[3]
Processing UsersController#update (for 0.0.0.0 at 2007-09-13 19:43:10)
[PUT]
  Session ID:
  Parameters: {"user"=>{"name"=>"no_va"}, "action"=>"update",
"id"=>"66", "controller"=>"users"}
  User Load (0.000245)   SELECT * FROM users WHERE (users.`id` = 66)
  User Update (0.000223)   UPDATE users SET `name` = 'no_va' WHERE `id`
= 66
Redirected to http://test.host/users/66
---------------------
  User Update (0.000206)   UPDATE users SET `name` = 'no_va' WHERE `id`
= 66
true
no_va
Completed in 0.00427 (233 reqs/sec) | DB: 0.00166 (38%) | 302 Found
[http://test.host/users/66?user=nameno_va]
  SQL (0.044350)   ROLLBACK


[4]
  # PUT /users/1
  # PUT /users/1.xml
  def update
    @user = User.find(params[:id])

    respond_to do |format|
      if @user.update_attributes(params[:user])
        flash[:notice] = 'User was successfully updated.'
        format.html { redirect_to user_url(@user) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @user.errors.to_xml }
      end
    end
    logger.debug("---------------------")
    logger.debug(@user.save)
    logger.debug(@user.name)
  end
-- 
Posted via http://www.ruby-forum.com/.


More information about the Ror-es mailing list