我已经运行了一个控制器测试集,其中三个测试成功,三个失败并出现相同类型的错误。
对于edit
,update
和destroy
操作的测试,我收到相关错误No route matches {:controller=>"accounts", action=>"edit"}
accounts_controller_spec.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
accounts_controller.rb
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
的routes.rb
resources :account_codes
答案 0 :(得分:1)
我在这里看到两个错误
get :edit, id: 1
,put :update, id: 1
... 尝试运行佣金路线以查看您的确切路线
PS:我认为你也会因show
动作而得到同样的错误。如果您不需要该操作,请将其作为except: :show
传递到routes.rb