Factory girl saving records in my development database

夙愿已清 提交于 2019-12-31 07:23:28

问题


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

回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/7208358/factory-girl-saving-records-in-my-development-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!