0
我在使用Rspec測試我的新用戶配置文件頁時出現問題。它通過瀏覽器工作,但是Rspec正在爆炸。用戶配置文件控制器Rspec測試因路由而失敗
我使用devise和單獨的控制器來編輯配置文件字段。
這是一個請求規格。
it 'Shows the user profile with their non-private data' do
visit user_path(@user)
page.should have_content @user.full_name
end
與此錯誤失敗:
Failure/Error: visit user_path(@user)
ActionController::RoutingError:
No route matches {:action=>"show", :controller=>"users"}
我不同意
#routes.rb
devise_for :users, :controllers => {:registrations => "registrations"}
resources :users, :only => [:edit, :update, :show]
更新和編輯路徑傭工的工作就好了。
控制器動作:
class UsersController < ApplicationController
layout 'profile', :except => [:show]
#... edit and update omitted
def show
@user = User.find(params[:id])
end
end
耙路線顯示:
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) registrations#cancel
user_registration POST /users(.:format) registrations#create
new_user_registration GET /users/sign_up(.:format) registrations#new
edit_user_registration GET /users/edit(.:format) registrations#edit
PUT /users(.:format) registrations#update
DELETE /users(.:format) registrations#destroy
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
所以它並沒有真正像遺贈是我的路線干擾,更重要的是,一切都在瀏覽器的工作原理。我在這裏錯過了什麼?
我也試圖使被稱爲輪廓,而不是默認顯示的成員動作,即有相同的結果