Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Database cleaner with multiple DBs

未关闭
#3 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
ruby
领域
databases, testing

调研方向

从提供的 spec helper 中的 DatabaseCleaner[:sequel] 配置以及 CameraActivity 的 Sequel 模型连接开始,然后让两个数据库 URL 都指向同一个数据库,以重现该故障。检查现有测试套件,以确定如何发现和配置多个活动的 Sequel 数据库;当测试设置能够清理预期的数据库连接且不再出现运行时错误时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

I have been using DB cleaner with my only db but now I have 2 of them, and I am getting this error in testing mode as

RuntimeError:
  As you have more than one active sequel database you have to specify the one to use manually!

At first my whole sequel models were using only one db but now i have connected my one model with a separate Db as

class CameraActivity < Sequel::Model(Sequel.connect(ENV['SNAPSHOT_DATABASE_URL'])[:camera_activities])

and in spec helper I have these configurations

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] = 'test'
ENV["DATABASE_URL"] = "postgres://localhost/evercam_tst"
ENV["RACK_ENV"]  = ENV["RAILS_ENV"]
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'webmock/rspec'
require 'factory_girl'
require 'rack_session_access/capybara'
require "simplecov"
SimpleCov.start

Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

require 'database_cleaner'
require 'capybara/poltergeist'
require 'simplecov'

SimpleCov.start 'rails'

#Capybara.server_port = 3001
#Capybara.app_host = "http://local.evercam.io:3001"
Capybara.javascript_driver = :poltergeist

RSpec.configure do |config|
  config.infer_spec_type_from_file_location!

  config.filter_run :focus => true
  config.run_all_when_everything_filtered = true

  # Configure factory girl stuff.
  config.include FactoryGirl::Syntax::Methods

  # Configure database cleaner.
  config.before(:suite) do
    WebMock.allow_net_connect!
    DatabaseCleaner[:sequel].strategy = :truncation, {except: %w[spatial_ref_sys]}
    DatabaseCleaner[:sequel].clean_with(:truncation, except: %w[spatial_ref_sys])
  end

  config.before(:each) do
    DatabaseCleaner[:sequel].start
  end

  config.after(:each) do
    DatabaseCleaner[:sequel].clean
  end
end

# Load up factories.
FactoryGirl.find_definitions
```


my other DB is `ENV['SNAPSHOT_DATABASE_URL']` But for testing purposes both DB URLs are directed to one database. How is that possible to tell DB Cleaner to handle that case?
主要语言
Ruby
星标
19
派生
11
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

DatabaseCleaner/database_cleaner-sequel 的其他 Issue

查看 DatabaseCleaner/database_cleaner-sequel 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。