Mira, no estoy del todo seguro que estas haciendo en el test, pero te recomiendo MUCHISIMO para los tests de integracion usar webrat. Quedan tests mucho mas claros de lo que queres hacer.
Y si empezas a usar webrat, mirate Stories, que la escribieron Damian Janowski y Michel Martens, ambos en esta lista. http://github.com/citrusbyte/stories Saludos -foca On Sat, Sep 12, 2009 at 4:15 PM, Leonardo Otero <[email protected]> wrote: > Estoy tratando de hacer el siguiente test de integración pero luego de que > hace el "put" no se persisten las modificaciones. > Que estoy haciendo mal? > > require 'test_helper' > class UpdatePostAndCreateCommentTestTest < ActionController::IntegrationTest > fixtures :posts, :comments > def test_update_1_post_and_update_1_comment > post = posts(:one) > db_post = Post.find(post.id) > p db_post.title > > p put '/posts/', :post => {:id=>post.id, :title=>"new Title", :body=> > post.body} > > db_post = Post.find(post.id) > p db_post.title > assert assigns(:post).valid? #assigns(:post) es null aqui? > assert_redirected_to post_path(assigns(:post)) > > post '/posts/post_comment', :comment => {:post_id=>(:post).id, > :comment=>"my new comment"} > assert assigns(:comment).valid? > assert_redirected_to :action => 'show' > end > end > ... > class PostsController < ApplicationController > # PUT /posts/1 > # PUT /posts/1.xml > def update > �...@post = Post.find(params[:id]) > respond_to do |format| > if @post.update_attributes(params[:post]) > flash[:notice] = 'Post was successfully updated.' > format.html { redirect_to(@post) } > format.xml { head :ok } > else > format.html { render :action => "edit" } > format.xml { render :xml => @post.errors, :status => > :unprocessable_entity } > end > end > end > end > -------------------- > y en posts.yml tengo: > one: > id: 11 > title: my first post > body: I will explain why life is good > -------------------- > Siendo esta la salida resultante: > "my first post" > 200 > "my first post" > 1) Error: > test_update_1_post_and_update_1_comment(UpdatePostAndCreateCommentTestTest): > NoMethodError: You have a nil object when you didn't expect it! You might > have expected an instance of ActiveRecord::Base. The error occurred while > evaluating nil.valid? > C:/Documents and Settings/Fanny/My > Documents/Leo/Courses/ROR_with_passion/rails_testing/solutions/exercise0/rubyweblog/test/integration/update_post_and_create_comment_test_test.rb:16:in > `test_update_1_post_and_update_1_comment' > C:/Program Files/NetBeans > 6.5.1/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/testing/setup_and_teardown.rb:33:in > `run_with_callbacks' > C:/Program Files/NetBeans > 6.5.1/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/integration.rb:600:in > `run' > C:/Program Files/NetBeans > 6.5.1/ruby2/jruby-1.1.4/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run' > C:/Program Files/NetBeans > 6.5.1/ruby2/jruby-1.1.4/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each' > C:/Program Files/NetBeans > 6.5.1/ruby2/jruby-1.1.4/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run' > C:/Program Files/NetBeans > 6.5.1/ruby2/jruby-1.1.4/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in > `run_suite' > C:/Program Files/NetBeans > 6.5.1/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.3.1/bin/rdebug-ide:76 > C:/Program Files/NetBeans > 6.5.1/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.3.1/bin/rdebug-ide:19:in > `load' > C:\Program Files\NetBeans 6.5.1\ruby2\jruby-1.1.4\bin\rdebug-ide:19 > > _______________________________________________ > Ruby mailing list > [email protected] > http://lista.rubyargentina.com.ar/listinfo.cgi/ruby-rubyargentina.com.ar > > _______________________________________________ Ruby mailing list [email protected] http://lista.rubyargentina.com.ar/listinfo.cgi/ruby-rubyargentina.com.ar
