2016-07-29 60 views
1

我使用Rails 4.2 RSpec的3.5Rspec的的ActionController :: UrlGenerationError的Rails 4.2

後基本骨架一代,我試圖rspec的運行,但經常收到這樣的錯誤。

控制器測試

it "updates the requested" do 
    some_object = SomeObject.create! valid_attributes 
    put :update, params: {id: some_object.to_param, some_object: new_attributes}, session: valid_session 
    some_object.reload 
    skip("Add assertions for updated state") 
end 

給出了這樣的輸出

Failure/Error: put :update, params: {id: some_object.to_param, some_object: valid_attributes}, session: valid_session 

ActionController::UrlGenerationError: 
    No route matches {:action=>"update" 

和視圖測試

require 'rails_helper' 

    RSpec.describe "some_objects/edit", type: :view do 
    before(:each) do 
     @some_object = assign(:some_object, SomeObject.create!(
     :first_name => "MyString", 
     :last_name => "MyString" 
    )) 
    end 

    it "renders the edit some_object form" do 
     render 

     assert_select "form[action=?][method=?]", some_object_path(@some_object), "post" do 

     assert_select "input#some_object_first_name[name=?]", "some_object[first_name]" 

     assert_select "input#some_object_last_name[name=?]", "some_object[last_name]" 
     end 
    end 
    end 

給出了這樣的輸出:

Failure/Error: <%= form_for(@some_object) do |f| %> 

    ActionView::Template::Error: 
    undefined method `polymorphic_path' for #<#<Class:0x005606c04fff98>:0x005606c04ffb60> 

這是生成的代碼。我只更改了valid_attributes散列,這似乎是rails/rspec中的一些錯誤。你有任何解決方案

+0

請問你'配置/ routes.rb'是什麼樣子?在你的例子中,你稱爲'some_object'的東西的真正類名是什麼?這個班怎麼樣? – spickermann

+0

class SomeObject Mark

+0

您的數據庫表是否有名稱爲「type」的列? – spickermann

回答

0

問題是通過參數:更新。只需刪除PARAMS:,它會工作:

it "updates the requested" do 
    some_object = SomeObject.create! valid_attributes 
    put :update, {id: some_object.to_param, some_object: new_attributes}, session: valid_session 
    some_object.reload 
    skip("Add assertions for updated state") 
end 
相關問題