工厂女孩将记录保存在我的开发数据库中 [英] Factory girl saving records in my development database

查看:63
本文介绍了工厂女孩将记录保存在我的开发数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常奇怪的问题,我不知道该去哪里找.我正在开发使用rspec和factory girl进行测试的Rails 3应用程序.由于某种原因,每当我运行任何rails命令(例如,耙数据库,启动开发服务器等)时,都会创建一个工厂用户并将其存储在我的开发数据库中.最糟糕的是,它始终具有相同的电子邮件,我正在验证我的应用程序中的唯一性,因此,直到我手动删除记录后,命令才会运行.

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?

这是我的数据库.yml

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

推荐答案

我知道了.在我的Gemfile中,我有:

I figured it out. In my Gemfile, I had:

group :development, :test do
  gem 'capybara'
  gem "rspec-rails"
  gem "guard-rspec"
  gem "factory_girl_rails"
  ...
end

我将工厂女工从这个街区移到了自己的行上,因此它仅在测试组中是这样的:

I moved factory girl out of this block onto its own line so it is in the test group only like this:

gem 'factory_girl_rails', :group => :test

没有其他问题

这篇关于工厂女孩将记录保存在我的开发数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆