工厂女孩黄瓜步骤定义的问题
我正在使用工厂女孩提供的黄瓜步骤定义,但我无法在这里工作。
首先,这里是涉及的工厂:
Factory.define :user do |u|
u.name {|n| "User#{n}" }
u.first_name {|n| "FirstName#{n}"}
u.last_name {|n| "LastName#{n}"}
u.password 'please'
u.password_confirmation 'please'
end
Factory.define :lecture do |l|
l.name {|n| "Lecture#{n}"}
l.abbreviation {|n| "lec#{n}"}
l.association :admin, factory: :user
end
这是我试图执行的步骤:
And the following Lecture exists:
| Name | Abbreviation |
| Informatik A - Algorithmen und Datenstrukturen | ainf |
我收到此错误消息,并且完全不知道它来自哪里:
User(#42819220) expected, got User(#43753000) (ActiveRecord::AssociationTypeMismatch)
features/lectures/ui.feature:11:in `And the following Lecture exists:'
这是我的模型定义:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :rememberable, :trackable
# Setup accessible (or protected) attributes for your model
attr_accessible :name, :password, :password_confirmation, :remember_me, :first_name, :last_name
validates_uniqueness_of :name
has_many :administrated_lectures, class_name: "Lecture", foreign_key: "admin_id", dependent: :nullify
end
class Lecture < ActiveRecord::Base
validates_uniqueness_of :name
validates_uniqueness_of :abbreviation
scope :ordered, order("name")
belongs_to :admin, class_name: "User"
end
顺便说一句,我将其与 spork 一起使用。
亲切的问候,
尼尔斯
I am using the cucumber step definitons provided by factory girl and I can not get something to work here.
First of all, here are the involved factories:
Factory.define :user do |u|
u.name {|n| "User#{n}" }
u.first_name {|n| "FirstName#{n}"}
u.last_name {|n| "LastName#{n}"}
u.password 'please'
u.password_confirmation 'please'
end
Factory.define :lecture do |l|
l.name {|n| "Lecture#{n}"}
l.abbreviation {|n| "lec#{n}"}
l.association :admin, factory: :user
end
Here is the step I am trying to execute:
And the following Lecture exists:
| Name | Abbreviation |
| Informatik A - Algorithmen und Datenstrukturen | ainf |
I am getting this error message and have absolutely NO idea where it comes from:
User(#42819220) expected, got User(#43753000) (ActiveRecord::AssociationTypeMismatch)
features/lectures/ui.feature:11:in `And the following Lecture exists:'
And here are my model definitions:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :rememberable, :trackable
# Setup accessible (or protected) attributes for your model
attr_accessible :name, :password, :password_confirmation, :remember_me, :first_name, :last_name
validates_uniqueness_of :name
has_many :administrated_lectures, class_name: "Lecture", foreign_key: "admin_id", dependent: :nullify
end
class Lecture < ActiveRecord::Base
validates_uniqueness_of :name
validates_uniqueness_of :abbreviation
scope :ordered, order("name")
belongs_to :admin, class_name: "User"
end
I am using this with spork btw.
Kind regards,
Nils
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
哦,该死。知道了。我在过去的某个地方将
cache_classes
设置为false
,因为由于某种原因,正确的类重新加载不起作用。刚刚再次使其变为 true,现在它可以工作了。 :/Oh, damn. Got it. I set
cache_classes
tofalse
somewhere in the past because proper class reloading did not work for some reason. Just made ittrue
again, and now it works. :/这很可能是因为 Spork。
该错误是因为在某个时刻,
User
常量正在重新加载,但FactoryGirl
仍在引用旧常量。这是因为您可以像这样卸载常量:请参阅此类中的行:
您可以通过以下方式查看发生此错误的位置断点或只是检查这两个地方周围的某个地方:
我的猜测是某些内容正在重新加载
ActiveRecord
类,但不重新加载FactoryGirl
。解决这个问题的一种方法可能是重置FactoryGirl
定义:希望有帮助,Lance。
This is most likely because of Spork.
The error is because at some point the
User
constant is being reloaded, butFactoryGirl
is still referencing the old constant. This is because you can unload constants like this:See the line in this class:
You can see where this error occurs by breakpointing or just inspecting somewhere around these 2 places:
My guess is that something is reloading
ActiveRecord
classes, but not reloadingFactoryGirl
. One way around this might be to reset theFactoryGirl
definitions:Hope that helps, Lance.