0
我遇到了一个问题,发现this answer,我相信会解决我的问题,但我无法让它工作。这些测试为什么不起作用?
这里是我的代码:
setup do
# where the hell do I put this
def main_app
Rails.application.class.routes.url_helpers
end
@routes = Engine.routes
end
test "should get index" do
get :index
assert_response :success
end
[email protected]:~/sizzle-chisel$ rake test
Started with run options --seed 60111
ERROR["test_should_get_index", Blog::Admin::ArticlesControllerTest, 0.3109516409999742]
test_should_get_index#Blog::Admin::ArticlesControllerTest (0.31s)
ActionView::Template::Error: ActionView::Template::Error: undefined method `root_path' for #<ActionDispatch::Routing::
RoutesProxy:0x00000006eda278>
Blog::Engine.routes.draw do
root "articles#index"
resources :articles
namespace :admin do
resources :articles
root to: 'articles#index'
end
end
我不断收到root_path是不确定的,因为在我的布局,有这样的代码:
<%= link_to "some link", main_app.root_path %>
我的代码库是Rails引擎...所以当我运行rake测试时,在main_app上没有定义root_path。
这不回答我的问题...阅读我发布的链接。我认为你不了解我的问题。 –