Tôi muốn ghi đè Devise::RegistrationsController
để triển khai một số chức năng tùy chỉnh. Để làm điều này, tôi đã tạo ra một mới RegistrationsController
như vậy:Cách viết kiểm tra bộ điều khiển khi bạn ghi đè bộ điều khiển đăng ký?
# /app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
def new
super
end
end
và thiết lập các tuyến đường của tôi như thế này:
devise_for :users, :controllers => { :registrations => "registrations" }
và cố gắng để kiểm tra nó như thế này:
describe RegistrationsController do
describe "GET 'new'" do
it "should be successful" do
get :new
response.should be_success
end
end
end
nhưng điều đó mang lại cho tôi một lỗi:
1) RegistrationsController GET 'new' should be successful
Failure/Error: get :new
AbstractController::ActionNotFound:
Could not find devise mapping for path "https://stackoverflow.com/users/sign_up".
Maybe you forgot to wrap your route inside the scope block? For example:
devise_scope :user do
match "/some/route" => "some_devise_controller"
end
# ./spec/controllers/registrations_controller_spec.rb:13:in `block (3 levels) in <top (required)>'
Vậy tôi đang làm gì sai?
Bạn sẽ thêm tập tin này vào - Tôi không thể hiểu được, cảm ơn. – eWizardII
Đặt nó trong các kiểm tra bộ điều khiển của bạn, ngay bên trong khối 'mô tả' đầu tiên. –
Trong spec - Tôi có điều khiển các registration_controller là nơi tôi đặt nó như sau vô ích: require 'spec_helper' mô tả RegistrationsController làm mô tả "GET 'chỉnh sửa'" làm trước: mỗi làm request.env [ 'devise.mapping'] = Devise.mappings [: hướng dẫn] cuối nó "nên được thành công" làm get 'chỉnh sửa' response.should be_success cuối cuối cuối – eWizardII