我现在正在使用Spree电子商务。我已经编写了自己的扩展程序,实际上我可以在控制台中调用它:
hash =
{:email=>"test@2.pl",
: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中调用它时会出现问题
attributes = { email: "test@2.pl", 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
现在怎么样?为什么它在rails控制台中有效但在规范中不起作用?
答案 0 :(得分:1)
profile_attributes是扩展程序的一部分 - 因为您的控制台内容并不能证明您的代码可以创建一个地址,而只是一个用户。你的扩展是在Github的某个地方让我们试试吗?