RSPEC con ererited_resources sta reindirizzando invece di rendering su un aggiornamento fallito
-
31-10-2019 - |
Domanda
Sono nuovo sia a RSPEC che a eredità_resources. Ho una semplice risorsa, contatto, che ha un campo di nome. Il controller non ha funzionalità speciali.
class ContactsController < InheritedResources::Base
actions :all, :except => [:show]
end
Ho specifiche scritte per creare e indicare bene, usando mock_model. Tuttavia, quando si utilizza Mock_Model su Aggiornamento, non è riuscito a trovare il contatto quando si mette. Quindi, sono passato all'utilizzo di modelli reali:
describe "PUT update" do
let(:contact) { Contact.create(:name => "test 1") }
it "edits the contact" do
contact.name = "#{contact.name}-edited"
end
context "when the contact updates successfully" do
before do
contact.stub(:save).and_return(true)
end
it "redirects to the Contacts index" do
put :update, :id => contact.id, :contact => contact
#assigns[:contact].name = "test 1 - edited"
response.should redirect_to(:action => "index")
end
end
context "when the contact fails to save" do
before do
contact.stub(:save).and_return(false)
contact.stub(:update_attributes).and_return(false)
contact.stub(:errors).and_return(:errors => { :anything => "anything" })
end
it "renders the edit template" do
put :update, :id => contact.id, :contact => contact
response.should render_template :edit
end
end
end
Ricevo il seguente errore:
Failures:
1) ContactsController PUT update when the contact fails to save renders the edit template
Failure/Error: response.should render_template :edit
Expected block to return true value.
# ./spec/controllers/contacts_controller_spec.rb:82:in `block (4 levels) in <top (required)>'
Quando ispezione lo stato_code, è un reindirizzamento 302 a /contatti /: id.
Che cosa sto facendo di sbagliato?
Nessuna soluzione corretta
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow