Rails、Cucumber:创建对象及其关联
我正在使用 mongoid,机械师 2 和 pickle。但我认为,这个问题更常见。
我有一个帐户模型:
class Account
include Mongoid::Document
include Mongoid::Timestamps
referenced_in :user
end
和用户:
class User
include Mongoid::Document
include Mongoid::Timestamps
references_one :account
end
我有以下场景(我设置了reference_one关联):
Scenario: Client views his account
Given a user with id: "4ceede9b5e6f991aef000007"
And the following accounts exist:
| user_id |
| 4ceede9b5e6f991aef000007 |
.....
我认为这样使用ids并不是一个好主意。创建具有关联的对象的最佳实践是什么?如果泡菜的话我会很好。例如,可以提供帮助。
I'm using mongoid, machinist 2 and pickle. But I think, that question is more common.
I have an Account model:
class Account
include Mongoid::Document
include Mongoid::Timestamps
referenced_in :user
end
and User:
class User
include Mongoid::Document
include Mongoid::Timestamps
references_one :account
end
I have the following scenario(I set reference_one association):
Scenario: Client views his account
Given a user with id: "4ceede9b5e6f991aef000007"
And the following accounts exist:
| user_id |
| 4ceede9b5e6f991aef000007 |
.....
I think this is not so good idea use ids such way. What is the best practice of creating object with associations? I would be nice if pickle. for example, could help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样设置蓝图:
在 cucumber 内部:
如果 pickle 不处理上面的步骤,您可以创建自己的步骤定义,如下所示:
You can set up blueprints like this:
And inside cucumber:
If pickle doesn't handle the step above, you can create your own step definition like this: