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
現在是什麼?爲什麼它在軌道控制檯中工作,但不在規範中?
不幸的是我無法分享它的源代碼......實際上這個控制檯代碼創建所有的用戶,配置文件和地址模型(所有都與相互關聯) – user2160738
在錯誤中沒有行號發生錯誤的地方? –