routes.rb tôiRSpec: thông số kỹ thuật điều khiển cho nguồn lực lồng 2 mức
namespace :magazine do
resources :pages do
resources :articles do
resources :comments
end
end
end
Trong khi viết thông số kỹ thuật điều khiển cho Bình luận:
describe "GET 'index'" do
before(:each) do
@user = FactoryGirl.create(:user)
@page = FactoryGirl.build(:page)
@page.creator = @user
@page.save
@article = FactoryGirl.create(:article)
@comment_attributes = FactoryGirl.attributes_for(:comment, :article_id => @article)
end
it "populates an array of materials" do
get :index, ??
#response.should be_success
assigns(:comments)
end
it "renders the :index view" do
get :index, ??
response.should render_template("index")
end
end
Bất kỳ ý tưởng làm thế nào để cung cấp cho các trang và bài viết tham khảo để có được: mục lục ?? nếu tôi cung cấp: nhận được: chỉ số,: article_id => @ article.id
Lỗi tôi nhận được là dưới đây:
Failure/Error: get :index, :article_id => @article.id
ActionController::RoutingError:
No route matches {:article_id =>"3", :controller=>"magazine/comments"}
đó làm việc nhờ :) – Oatmeal
Vì vậy, nếu tôi muốn thử nghiệm một tình huống tiêu cực - page_id không có trong yêu cầu - sau đó làm thế nào để tôi làm điều đó? –
Điều đó sẽ gây ra lỗi định tuyến. Hướng dẫn đường ray cho biết "tài nguyên nên [* không bao giờ * được lồng sâu hơn 1 cấp độ sâu] (http://guides.rubyonrails.org/routing.html#nested-resources)." – Substantial