工厂女孩在我的开发数据库中保存记录
我有一个非常奇怪的问题,我不知道应该去哪里找到它。我正在使用 rspec 和 Factory Girl 开发一个 Rails 3 应用程序进行测试。由于某种原因,每当我运行任何rails命令(例如,rake数据库、启动开发服务器等)时,都会创建一个工厂用户并将其存储在我的开发数据库中。最糟糕的是,它总是具有相同的电子邮件,我正在验证应用程序中的唯一性,因此在我手动删除记录之前,命令不会运行。
我已经查看了我的工厂文件,我不认为我在那里做了任何奇怪的事情,并且建议我还能在哪里找到执行此操作的代码?
编辑:这是我的数据库.yml
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: ATBTracking_development
pool: 5
username: [NOT TELLING]
password: [NOT TELLING]
socket: /var/run/mysqld/mysqld.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: ATBTracking_test
pool: 5
username: [NOT TELLING]
password: [NOT TELLING]
socket: /var/run/mysqld/mysqld.sock
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: ATBTracking_production
pool: 5
username: [NOT TELLING]
password: [NOT TELLING]
socket: /var/run/mysqld/mysqld.sock
I have a very strange problem and I don't know where I should look to find it. I am developing a rails 3 app using rspec and factory girl for testing. For some reason, whenever I run any rails commands (eg to rake the db, start the dev server etc) one factory user is created and stored in my development database. The worst part is, it always has the same email, which I am validating the uniqueness of in my app, so the commands won't run until I go in manually delete the record.
I have looked all through my factories file and I don't think I am doing anything strange there, and suggestions where else I might for the code that is doing this?
EDIT: HERE IS MY database.yml
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: ATBTracking_development
pool: 5
username: [NOT TELLING]
password: [NOT TELLING]
socket: /var/run/mysqld/mysqld.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: ATBTracking_test
pool: 5
username: [NOT TELLING]
password: [NOT TELLING]
socket: /var/run/mysqld/mysqld.sock
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: ATBTracking_production
pool: 5
username: [NOT TELLING]
password: [NOT TELLING]
socket: /var/run/mysqld/mysqld.sock
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想通了。在我的 Gemfile 中,我有:
我将工厂女孩从这个块移到了自己的生产线上,因此它只在测试组中,如下所示:
不再有问题
I figured it out. In my Gemfile, I had:
I moved factory girl out of this block onto its own line so it is in the test group only like this:
No more problems
db/Seeds.rb 也许...但我认为只在 db:reset 和 db:seed 上运行
db/Seeds.rb maybe...but I think that only runs on db:reset and db:seed