2014-02-05 21 views
0

我目前使用Spree電子商務。我寫我自己的分機,實際上我能夠在控制檯中調用這個:rspec中的ActiveRecord :: UnknownAttributeError,但不在控制檯中

hash = 
    {:email=>"[email protected]", 
     :password=>"123123123", 
     :password_confirmation=>"123123123", 
     :profile_attributes=> 
      {:first_name=>"zdziski", 
      :last_name=>"fdfdi", 
      :position=>"dev", 
      :address_attributes=> 
      {"firstname"=>"Pal", 
      "lastname"=>"Zdzski", 
      "address1"=>"Kakaka", 
      "address2"=>"", 
      "city"=>"Bszcz", 
      "country_id"=>"72", 
      "zipcode"=>"323232", 
      "phone"=>"633336594"}}} 

然後

u = Spree::User.create(hash) 

,並有獨到之處響應!真棒!但是,當我打電話這在我的RSpec在CONSOL

attributes = { email: "[email protected]", password: "123123123", password_confirmation: "123123123", profile_attributes: { first_name:"pawel",last_name:"zmudzinski", position:"lol", address_attributes: {"firstname"=>"Pawel", "lastname"=>"Zmudzinski", "address1"=>"Kakaka", "address2"=>"", "city"=>"Bydgoszcz", "country_id"=>"72", "zipcode"=>"323232", "phone"=>"323432432"} }} 

然後

expect { Spree::User.create(attributes)}.to change { Spree::Address.count }.by(1)

user = FactoryGirl.build(:user,profile_attributes: { first_name:"pawel",last_name:"zmudzinski", position:"lol", address_attributes: {"firstname"=>"Pawel", "lastname"=>"Zmudzinski", "address1"=>"Kakaka", "address2"=>"", "city"=>"Bydgoszcz", "country_id"=>"72", "zipcode"=>"323232", "phone"=>"1234325432"} }) 

響應出現的問題是:

Failure/Error: expect { Spree::User.create(attributes)}.to change { Spree::Address }.by(1) 
ActiveRecord::UnknownAttributeError: 
    unknown attribute: user_profile_id 

現在是什麼?爲什麼它在軌道控制檯中工作,但不在規範中?

回答

1

profile_attributes是你的擴展的一部分 - 因爲你的控制檯的東西不能證明你的代碼可以創建一個地址,只是一個用戶。你的擴展是在Github上的某個地方給我們嘗試的嗎?

+0

不幸的是我無法分享它的源代碼......實際上這個控制檯代碼創建所有的用戶,配置文件和地址模型(所有都與相互關聯) – user2160738

+0

在錯誤中沒有行號發生錯誤的地方? –

相關問題