Sto lavorando a una sorta di app di Yahoo Answers per migliorare le mie competenze su Rails. Finora ho impostato due modelli "Domanda" e "risposte" e si sono annidati in questo modo:Rspec e Rails con test di visualizzazione e risorse nidificate
resources :questions do
resources :answers
end
Ho fatto i test per i controllori, i modelli e viste le domande, ma sono avere un piccolo problema con la vista delle risposte e le rotte nidificate. Sto usando Rspec e Factory girl.
Ho il seguente test:
describe "answers/new.html.erb" do
before(:each) do
@question = Factory(:valid_question)
@answer = Factory(:valid_answer)
assign(:question, @question)
assign(:answer, stub_model(Answer,
:text => "MyString",
:question_id => 1
).as_new_record)
end
it "renders new answer form" do
render
assert_select "form", :action => question_answers_path(@question), :method => "post" do
assert_select "textarea#answer_text", :name => "answer[text]"
assert_select "input#answer_question_id", :name => "answer[question_id]"
end
end
end
e ogni volta che ho eseguito il test ricevo il seguente messaggio:
3) answers/new.html.erb renders new answer form
Failure/Error: render
ActionView::Template::Error:
No route matches {:controller=>"answers"}
# ./app/views/answers/new.html.erb:6:in `_app_views_answers_new_html_erb__3175854877830910784_6513500'
# ./spec/views/answers/new.html.erb_spec.rb:16:in `block (2 levels) in <top (required)>'
Ho provato molte cose come facendo
render new_question_answer_path(@question)
ma ottengo questo:
3) answers/new.html.erb renders new answer form
Failure/Error: render new_question_answer_path(@question.id)#, :format=>:html
ActionView::MissingTemplate:
Missing partial /questions/1/answers/new with {:handlers=>[:erb, :builder, :coffee], :formats=>[:html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :
url_encoded_form, :json], :locale=>[:en, :en]}. Searched in:
* "/home/juan/rails_projects/answers/app/views"
# ./spec/views/answers/new.html.erb_spec.rb:16:in `block (2 levels) in <top (required)>'
Per favore, aiutatemi con questo? Sono un po 'incapace in questo momento.