Ruby on rails 3 &引用;“没有路线匹配”;带rspec
我有一个控制器测试集在运行,其中三个测试成功,三个测试失败,并且有相同类型的错误 对于Ruby on rails 3 &引用;“没有路线匹配”;带rspec,ruby-on-rails-3,rspec,Ruby On Rails 3,Rspec,我有一个控制器测试集在运行,其中三个测试成功,三个测试失败,并且有相同类型的错误 对于edit、update和destroy操作的测试,我得到一个相关的错误,即No route matches{:controller=>“accounts”,action=>“edit”} 账户\u控制器\u规范rb describe AccountsController do before(:each) do @account_code = FactoryGirl.create(:account) end
edit
、update
和destroy
操作的测试,我得到一个相关的错误,即No route matches{:controller=>“accounts”,action=>“edit”}
账户\u控制器\u规范rb
describe AccountsController do
before(:each) do
@account_code = FactoryGirl.create(:account)
end
describe "GET 'index'" do
it "returns http success" do
get 'index'
expect(response).to be_success
end
end
describe "GET 'new'" do
it "returns http success" do
get 'new'
expect(response).to be_success
end
end
describe "POST 'create'" do
it "returns http success" do
post 'create'
expect(response).to be_success
end
end
describe "GET 'edit'" do
it "returns http success" do
get 'edit'
expect(response).to be_success
end
end
describe "POST 'update'" do
it "returns http success" do
post 'update'
expect(response).to be_success
end
end
describe "DELETE 'destroy'" do
it "returns http success" do
post 'destroy'
expect(response).to be_success
end
end
end
class AccountsController < ApplicationController
load_and_authorize_resource
def index
end
def new
end
def create
if @account.save
flash[:success] = "Account created"
redirect_to :action => :index
else
render 'new'
end
end
def update
if @account.update_attributes(params[:account])
flash[:success] = "Account Updated"
redirect_to :action => :index
else
render 'edit'
end
end
def edit
end
def destroy
@account.destroy
flash[:success] = "Account Deleted"
redirect_to accounts_path
end
end
resources :account_codes
帐户\u控制器.rb
describe AccountsController do
before(:each) do
@account_code = FactoryGirl.create(:account)
end
describe "GET 'index'" do
it "returns http success" do
get 'index'
expect(response).to be_success
end
end
describe "GET 'new'" do
it "returns http success" do
get 'new'
expect(response).to be_success
end
end
describe "POST 'create'" do
it "returns http success" do
post 'create'
expect(response).to be_success
end
end
describe "GET 'edit'" do
it "returns http success" do
get 'edit'
expect(response).to be_success
end
end
describe "POST 'update'" do
it "returns http success" do
post 'update'
expect(response).to be_success
end
end
describe "DELETE 'destroy'" do
it "returns http success" do
post 'destroy'
expect(response).to be_success
end
end
end
class AccountsController < ApplicationController
load_and_authorize_resource
def index
end
def new
end
def create
if @account.save
flash[:success] = "Account created"
redirect_to :action => :index
else
render 'new'
end
end
def update
if @account.update_attributes(params[:account])
flash[:success] = "Account Updated"
redirect_to :action => :index
else
render 'edit'
end
end
def edit
end
def destroy
@account.destroy
flash[:success] = "Account Deleted"
redirect_to accounts_path
end
end
resources :account_codes
我在这里看到两个错误
- 如果销毁和更新未使用正确的动词,则应使用“delete”表示销毁,使用“put”表示更新
- 您没有为这些操作提供“id”,您应该使用
,get:edit,id:1
put:update,id:1
PS:我想你在
show
动作中也会遇到同样的错误。如果您不需要该操作,请在routes上的资源中将其作为Exception::show
传递。rb提示必须传递要匹配的路由的id参数是我缺少的部分。