Ecco il codice rspec per il regolatore:Flash [: Avviso] .should_not be_nil fallito nel rspec
it "should render edit if update was not saved" do
item = Factory(:lease_item)
session[:corp_head] = true
post 'update', {:id => item.id, :name => 'nil'}
flash[:notice].should_not be_nil
response.should render 'edit'
end
L'aggiornamento controller è:
def update
if (eng? && dept_head?) || corp_head? || ceo?
@lease_item = LeaseItem.find(params[:id])
@lease_item.input_by_id = session[:user_id]
if @lease_item.update_attributes(params[:lease_item], :as => :roles_update)
#redirect
redirect_to URI.escape("/view_handler?index=0&msg=Lease item updated successfully")
else
#back to new
render 'edit', :notice => "Item NOT updated"
end
else
#back to previous page
redirect_to URI.escape("/view_handler?index=0&msg=NO right to update lease item")
end
end
Ecco il codice di errore da RSpec:
1) LeaseItemsController GET 'update' should render edit if update was not saved
Failure/Error: flash[:notice].should_not be_nil
expected: not nil
got: nil
"L'elemento NON aggiornato" era previsto in flash. Tuttavia, perché non c'è niente con il flash [: avviso]? O come rspec c'è un messaggio con render 'edit',: notice => 'Item NOT updated'
Grazie.
UPDATE:
Qui è il cambiamento nel controllore:
...........
else
#back to new
flash[:notice] = "Item NOT updated"
render 'edit'
end
.........
Ecco il codice RSpec che passa:
it "should render edit if update was not saved" do
item = Factory(:lease_item)
session[:corp_head] = true
post 'update', {:id => item.id, :lease_item => {:name => 'nil'}}
flash.should_not be_nil
response.should render_template(:action=> "edit")
end
non ha funzionato, se si usa il flash [: avviso ] .should_not be_nil (o .. flash.now [: notice] ...). L'errore è ottenuto nullo, che è lo stesso di prima. Anche response.should render 'edit' (o ... render: action => 'edit') non è passato bene. L'errore è NameError o NoMethodError. Non so perché.
si sta inviando "elemento non aggiornato" nel 'notice' variabile al partial 'edit', ma stai effettivamente impostando 'flash [: notice]'? – Karl
Come impostare il flash [: avviso]? – user938363
non c'è rendering 'foo',: notice => "blah" ... leggi i documenti. Usa flash [: avviso] = "Articolo NON aggiornato", quindi visualizza "modifica" – daniel