gpt4 book ai didi

ruby-on-rails - Cucumber:Factory Girl 不修改数据库——使用 .create 创建对象但之后数据库表仍然为空

转载 作者:行者123 更新时间:2023-12-03 12:18:41 26 4
gpt4 key购买 nike

  p = Factory(:model) 

ap Model.find(:all) #output to prove that it's getting created

所以......打印显示对象的ID正在上升......但是当我不断刷新MySQL工作台上的 View 时数据库仍然为空 - 所以我的 cucumber 测试失败,因为 Controller 从数据库中提取东西...但数据库中什么都没有! =(

我的 Gem 文件:测试
group :test do
gem "cucumber", "~>0.10.3"
gem "cucumber-rails", "0.3.2"
gem "launchy"
gem "hpricot"
gem "gherkin", "~>2.4.0"

gem "capybara", "0.4.1.2"
gem "rspec", "1.3.2"
gem "rspec-rails", "1.3.2"
gem "rspec-core"
gem "rspec-expectations"

gem "webrat", "0.7.0"
gem "database_cleaner"

gem "factory_girl", "1.2.4"
gem "shoulda", :require => nil
gem "shoulda-matchers", :git => "https://github.com/thoughtbot/shoulda-matchers"
gem "awesome_print"
gem "cobravsmongoose"
end

我对 env.rb 的要求( cucumber env)
ENV["RAILS_ENV"] = 'test'
ENV["RACK_ENV"] = 'test'

BASE_DOMAIN = "myapp.dev" #using POW

require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')

require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
require 'cucumber/rails/world'
require 'cucumber/rails/active_record'
require 'cucumber/web/tableish'
require 'cucumber/rails/rspec'
require 'rake'

require 'shoulda'
require 'factory_girl'
require 'factory_girl/step_definitions'
require 'awesome_print'


require 'capybara/rails'
require 'capybara/cucumber'
require 'capybara/session'

在 envs/test.rb
Bundler.require(:test) #just in case I forgot something

编辑:

一些控制台输出
工厂(:模型)。错误=>
#<ActiveRecord::Errors:0x10c5a6498 @base=#<ModelName id: 1, name: "Ready or not", status: 0, account_id: 2, user_id: 1, created_at: "2011-09-08 15:09:05", updated_at: "2011-09-08 15:09:05", description: "Things are not as they used to be", value: #<BigDecimal:10cb2c188,'0.12345E5',9(18)>, category_id: nil, allow_downloads: true, visibility: 1, locked: nil>, @errors=#<OrderedHash {}>>

并在运行时查看控制台,该对象在 INSERT INTO 命令中很明确……但是有这个:
RELEASE SAVEPOINT active_record_1
SQL (1.3ms) ROLLBACK

我觉得这可能是导致问题的原因......某种先发制人的回滚。

最佳答案

然后试试这个:

在 env.rb

require 'database_cleaner'
require 'database_cleaner/cucumber'
DatabaseCleaner.strategy = nil

关于ruby-on-rails - Cucumber:Factory Girl 不修改数据库——使用 .create 创建对象但之后数据库表仍然为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7352818/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com