工厂女孩在我的开发数据库中保存记录

发布于 2024-12-01 12:18:58 字数 1311 浏览 1 评论 0原文

我有一个非常奇怪的问题,我不知道应该去哪里找到它。我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难如初 2024-12-08 12:18:58

我想通了。在我的 Gemfile 中,我有:

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

我将工厂女孩从这个块移到了自己的生产线上,因此它只在测试组中,如下所示:

gem 'factory_girl_rails', :group => :test

不再有问题

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

No more problems

相思故 2024-12-08 12:18:58

db/Seeds.rb 也许...但我认为只在 db:reset 和 db:seed 上运行

db/Seeds.rb maybe...but I think that only runs on db:reset and db:seed

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文