tôi tạo điều khiển với InherritedResourceLàm thế nào để kiểm tra bộ điều khiển với các tuyến đường lồng nhau sử dụng rspec
class AppsController < InheritedResources::Base
belongs_to :company
# Devise
before_filter :login_or_oauth_required
# CanCan
load_and_authorize_resource
end
và cố gắng thử nghiệm nó với RSpec bằng phương pháp này
require "spec_helper"
include Devise::TestHelpers
describe AppsController do
before(:each) do
@company_1 = Factory.build(:company)
application_1 = Factory.create(:application, :company => @company_1)
application_2 = Factory.create(:application, :company => @company_1)
application_3 = Factory.create(:application, :company => @company_1)
@company_2 = Factory.build(:company)
@user_1 = Factory.create(:user)
role_1 = Factory.create(:publisher_role, :company => @company_1)
profile_1 = Factory.create(:profile, :company => @company_1, :user => @user_1, :roles => [role_1])
end
describe "index action" do
it "user_1 should have 3 applications from company_1" do
sign_in @user_1
params = {"company_id"=>"1"}
get :index
assigns[:apps].should have(3).items
end
end
end
Kết quả là
Failure/Error: get :index
ActionController::RoutingError:
No route matches {:controller=>"apps"}
Cách yêu cầu Rspec "Nhận" vào tuyến đường lồng nhau của tôi
tuyến My
resources :companies do
resources :apps do
resources :shelves do
resources :publications
end
end
end
Tôi cố gắng làm theo Câu hỏi này How to test controllers with nested routes using Rspec? nhưng nó không hoạt động trên trường hợp của tôi
tôi sử dụng Rails 3.1.1 và rspac 2,7
fwiw, Rails Hướng dẫn làm nản lòng các nguồn lực làm tổ ngoài một cấp "Tài nguyên không bao giờ nên được lồng vào nhau hơn 1 cấp độ sâu" (http://guides.rubyonrails.org/routing.html#nested-resources) giới thiệu người đọc đến [monstrosity] này (http://weblog.jamisbuck.org/2007/2/5/nesting-resources). Nhưng ya làm watcha phải làm. – brntsllvn