List Info

Thread: Expected response to be a <:redirect>, but was <200>




Expected response to be a <:redirect>, but was <200>
country flaguser name
United States
2007-09-10 17:35:52
Greetings, i have a question about a functional test failing
with the
sentence:

Expected response to be a <:redirect>, but was
<200>

The controller's function is

def create
    monster = Monster.new(params[:monster])
    movement = monster.movements.build(params[:movement])
    attack = monster.attacks.build(params[:attack])
    if monster.save
      flash[:notice] = 'Monster was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

while test is

def test_create
    num_monsters = Monster.count

    post :create, :monster =>
monsters(:first).attributes

    assert_response :redirect
    assert_redirected_to :action => 'list'

    assert_equal num_monsters + 1, Monster.count
  end

by log i see that monster is created but is not directed in
the list
action and i can't understand why ...
may you help me?

ah ... this is my log

Processing AdminController#create (for 0.0.0.0 at 2007-09-11
00:09:09)
[POST]
  Session ID:
  Parameters: {"action"=>"create",
"monster"=>{"alignment_id"=>1,
"ana_frequency_id"=>1,
"dimension_id"=>1,
"dv_asterischi"=>0,
"salvezza"=>23, "morale"=>3,
"nome"=>"mostro_first",
"numero1"=>"1",
"tesoro"=>nil, "descrizione"=>nil,
"intelligenza"=>2,
"numero2"=>"1",
"id"=>3, "terrain_id"=>1,
"dv"=>2.0, "ca"=>5,
"klass_id"=>1,
"monster_type_id"=>1},
"controller"=>"admin"}
  Monster Load (0.001781)   SELECT * FROM monsters WHERE
(monsters.nome = 'mostro_first') LIMIT 1
Rendering layoutfalseactionnew within layouts/admin
Rendering admin/new
  Dimension Load (0.001151)   SELECT * FROM dimensions
  AnaMovement Load (0.000953)   SELECT * FROM ana_movements
  Klass Load (0.000936)   SELECT * FROM klasses
  Alignment Load (0.001031)   SELECT * FROM alignments
  MonsterType Load (0.000446)   SELECT * FROM monster_types
  AnaFrequency Load (0.000436)   SELECT * FROM
ana_frequencies
  Terrain Load (0.001174)   SELECT * FROM terrains
Rendered admin/_form (0.06160)
Completed in 0.09117 (10 reqs/sec) | Rendering: 0.06507
(71%) | DB:
0.01091 (11%) | 200 OK [http://test.host/admin
/create?
monster=alignment_id1salvezza23dv_asterischi0dimension_id1an
a_frequency_id1tesoronumero11nomemostro_firstmorale3numero21
intelligenza2descrizioneterrain_id1id3dv2.0klass_id1ca5monst
er_type_id1]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails" group.
To post to this group, send email to rubyonrailsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-unsubscribegooglegroups.com
For more options, visit this group at http://gro
ups.google.com/group/rubyonrails
-~----------~----~----~----~------~----~------~--~---


Re: Expected response to be a <:redirect>, but was <200>
user name
2007-09-10 17:41:27
Try adding an error message to your test like: ;

assert_response :redirect, "Errors on model: #{assigns(:monster).errors.full_messages.to_sentence}&quot;

See if something is awry on your model this way.

James H.

On 9/10/07, Valerio Crini < vcrinigmail.com">vcrinigmail.com> wrote:

Greetings, i have a question about a functional test failing with the
sentence:

Expected response to be a <:redirect>, but was <200>;

The controller's function is

def create
&nbsp; &nbsp; monster = Monster.new(params[:monster])
&nbsp; &nbsp; movement = monster.movements.build (params[:movement])
 &nbsp; &nbsp;attack = monster.attacks.build(params[:attack])
&nbsp; &nbsp; if monster.save
 &nbsp; &nbsp;  flash[:notice] = 'Monster was successfully created.&#39;
 &nbsp;   ; redirect_to :action => 'list&#39;
&nbsp; &nbsp; else
 &nbsp; &nbsp;  render :action => 'new&#39;
 &nbsp;  end
&nbsp; end

while test is

def test_create
 &nbsp; &nbsp;num_monsters = Monster.count

   ; post :create, :monster => monsters(:first).attributes

&nbsp;   ;assert_response :redirect
  ; &nbsp;assert_redirected_to :action => 'list&#39;

 ; &nbsp; assert_equal num_monsters + 1, Monster.count
 &nbsp;end

by log i see that monster is created but is not directed in the list
action and i can't understand why ...
may you help me?

ah ... this is my log

Processing AdminController#create (for 0.0.0.0 at 2007-09-11 00:09:09)
[POST]
&nbsp; Session ID:
&nbsp; Parameters: {"action"=&gt;"create", "monster"=&gt;{"alignment_id"=>1,
"ana_frequency_id"=&gt;1, "dimension_id&quot;=>1, "dv_asterischi&quot;=>0,
"salvezza";=>23, "morale"=&gt;3, "nome"=>"mostro_first&quot;, "numero1"=&gt;"1&quot;,
&quot;tesoro&quot;=>nil, "descrizione&quot;=>nil, "intelligenza&quot;=>2, "numero2"=&gt;"1&quot;,
&quot;id";=>3, "terrain_id";=>1, "dv&quot;=>2.0, "ca&quot;=>5, "klass_id"=>1,
&quot;monster_type_id";=>1}, "controller";=>";admin";}
 &nbsp;Monster Load ( 0.001781) &nbsp; SELECT * FROM monsters WHERE
(monsters.nome = 'mostro_first';) LIMIT 1
Rendering layoutfalseactionnew within layouts/admin
Rendering admin/new
  ;Dimension Load (0.001151)  ; SELECT * FROM dimensions
 &nbsp;AnaMovement Load (0.000953)  ; SELECT * FROM ana_movements
 &nbsp;Klass Load (0.000936)  ; SELECT * FROM klasses
&nbsp; Alignment Load (0.001031)  ; SELECT * FROM alignments
 &nbsp;MonsterType Load (0.000446)  ; SELECT * FROM monster_types
 ; AnaFrequency Load (0.000436)  ; SELECT * FROM ana_frequencies
 ; Terrain Load (0.001174)  ; SELECT * FROM terrains
Rendered admin/_form (0.06160)
Completed in 0.09117 (10 reqs/sec) | Rendering: 0.06507 (71%) | DB:
0.01091 (11%) | 200 OK [http://test.host/admin/create?
monster=alignment_id1salvezza23dv_asterischi0dimension_id1ana_frequency_id1tesoronumero11nomemostro_firstmorale3numero21intelligenza2descrizione terrain_id1id3dv2.0klass_id1ca5monster_type_id1]




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails"; group.
To post to this group, send email to rubyonrailsgooglegroups.com
To unsubscribe from this group, send email to rubyonrails-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails
-~----------~----~----~----~------~----~------~--~---

Re: Expected response to be a <:redirect>, but was <200>
country flaguser name
United States
2007-09-11 00:08:49
You've solved my problem: with your hint i was able to view
my model's
inconsistency that caused failing of my test.
Thanks a lot

Valerio C

On 11 Set, 00:41, "James Herdman"
<james.herd...gmail.com> wrote:
> Try adding an error message to your test like:
> assert_response :redirect, "Errors on model:
>
#{assigns(:monster).errors.full_messages.to_sentence}"
>
> See if something is awry on your model this way.
>
> James H.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails" group.
To post to this group, send email to rubyonrailsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-unsubscribegooglegroups.com
For more options, visit this group at http://gro
ups.google.com/group/rubyonrails
-~----------~----~----~----~------~----~------~--~---


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )