2012-08-23 15 views
0

我正在使用Mongoid。我有一個對象:用mongoid製作 - 錯誤的參數數

class Employee 
    include Mongoid::Document 

    field :name_first,  type: String 
    field :name_last,  type: String 
    field :name_other,  type: Array, default: [] 
    field :title,     type: String 
    field :education,   type: Hash,  default: {} 
    field :languages,   type: Array, default: [] 
    field :phone,     type: Hash,  default: {} 
    field :address,    type: Hash,  default: {} 
    field :email,     type: Array, default: [] 
    field :url,      type: Array, default: [] 
    field :history,    type: Array, default: [] 
    field :profile,    type: String 
    field :social_media, type: Hash,  default: {} 
    field :last_contact, type: Time 
    field :signed_up,   type: Date 

    belongs_to :user 
    belongs_to :practice 
end 

而且,我正嘗試使用Fabrication,並遇到問題。寶石安裝得很好。在/spec/fabricators/employee_fabricator.rb我

Fabricator :employee do 

end 

而在my_controller_spec.rb我:

describe CasesController do 

    describe "viewing cases" do 
    before(:each) do 
     Fabricate(:employee) 
    end 

    it "allows viewing the cases index page" do 
     get 'index' 
     response.should_not be_success 
    end 
    end 
end 

當我運行在終端 '的RSpec規範',我得到:

Failures: 

    1) CasesController viewing cases allows viewing the cases index page 
    Failure/Error: Fabricate(:employee) 
    ArgumentError: 
     wrong number of arguments (2 for 1) 

這是怎麼回事?我嘗試了各種排列,其中一些排除了其他錯誤,但沒有任何運行。沒有調用製造(:僱員)線,它按預期運行,但到目前爲止只有空測試...

回答

0

我在使用活動記錄時遇到同樣的問題。

我發現,製作寶石的2.6版本通過第二屬性到active_record/base.rb初始化:{:without_protection =>真}

這種變化似乎是在滑軌3.2(我在3.0 )。這個新參數在2.0.2版本中開始由Fabrication gem傳遞,所以我將我的gem文件中的製造寶石降級到2.0.1,直到我們將Rails升級到3.2

因此,基本上,我的建議是要麼降級製作寶石到2.0.1或升級Rails到3.2