我不知道我做错了什么,所以请帮帮我。
所以正如标题所说,在浏览器中一切都很好。所以我想这是我无法正确的规范。
我已经多次重写了我的助手、控制器和规范中的代码。
这是我现在的规格:
describe "visit as admin" do
before do
sign_in admin
visit organization_users_path # row 20 of users_controller_spec
end
it "should display right page" do
page.should have_selector('title', text: "Users")
end
end
当我运行它时,我得到:
1) Organization::UsersController visit as admin should display right page
Failure/Error: visit organization_users_path
NoMethodError:
undefined method `users' for nil:NilClass
# ./app/controllers/organization/users_controller.rb:5:in `index'
# ./spec/controllers/organization/users_controller_spec.rb:20:in `block (3 levels) in <top (required)>'
这是我的控制器和助手:
# helper
def current_organization
@current_organization ||= current_user.organization
end
def admin_user
unless current_user.admin?
redirect_to root_path
end
end
#controller
class Organization::UsersController < ApplicationController
before_filter :admin_user
def index
@users = current_organization.users
end
end
编辑1:来自rake routes
:
organization_users GET /organization/users(.:format) organization/users#index