Repository navigation
Open
Description
I run my specs on Gitlab CI. When I try to run bundle exec rspec I get:
-----> Running test: bundle exec rspec
An error occurred while loading ./spec/auth/authenticate_user_spec.rb.
Failure/Error: require 'database_cleaner'
NameError:
uninitialized constant ActiveRecord::DatabaseConfigurations::ConnectionUrlResolver::URI
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/database_configurations/connection_url_resolver.rb:47:in `uri_parser'
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/database_configurations/connection_url_resolver.rb:25:in `initialize'
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/database_configurations/url_config.rb:48:in `new'
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/database_configurations/url_config.rb:48:in `build_url_hash'
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/database_configurations/url_config.rb:38:in `initialize'
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/database_configurations.rb:262:in `new'
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/database_configurations.rb:262:in `environment_url_config'
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/database_configurations.rb:177:in `build_configs'
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/database_configurations.rb:19:in `initialize'
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/core.rb:64:in `new'
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/core.rb:64:in `configurations='
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/core.rb:66:in `block in <module:Core>'
# ./vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.3.1/lib/active_support/concern.rb:136:in `class_eval'
# ./vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.3.1/lib/active_support/concern.rb:136:in `append_features'
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/base.rb:282:in `include'
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/base.rb:282:in `<class:Base>'
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/base.rb:265:in `<module:ActiveRecord>'
# ./vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.3.1/lib/active_record/base.rb:15:in `<top (required)>'
# ./vendor/bundle/ruby/2.7.0/gems/database_cleaner-active_record-2.0.0/lib/database_cleaner/active_record/truncation.rb:2:in `require'
# ./vendor/bundle/ruby/2.7.0/gems/database_cleaner-active_record-2.0.0/lib/database_cleaner/active_record/truncation.rb:2:in `<top (required)>'
# ./vendor/bundle/ruby/2.7.0/gems/database_cleaner-active_record-2.0.0/lib/database_cleaner/active_record.rb:4:in `require'
# ./vendor/bundle/ruby/2.7.0/gems/database_cleaner-active_record-2.0.0/lib/database_cleaner/active_record.rb:4:in `<top (required)>'
# ./vendor/bundle/ruby/2.7.0/gems/database_cleaner-2.0.1/lib/database_cleaner.rb:1:in `require'
# ./vendor/bundle/ruby/2.7.0/gems/database_cleaner-2.0.1/lib/database_cleaner.rb:1:in `<top (required)>'
# ./spec/rails_helper.rb:3:in `require'
# ./spec/rails_helper.rb:3:in `<top (required)>'
# ./spec/auth/authenticate_user_spec.rb:1:in `require'
# ./spec/auth/authenticate_user_spec.rb:1:in `<top (required)>'
Rails V: 6.1.3.1 - test
ruby '2.7.2'
Gemfile:
group :development, :test do
gem 'database_cleaner'
endGemfile.lock
database_cleaner (2.0.1)
database_cleaner-active_record (~> 2.0.0)
database_cleaner-active_record (2.0.0)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
On my internet research I found this:
https://blog.code-fabrik.ch/2021/03/31/sinatra-databaseconfiguration-url.html
Reacted by Mario Rogic
Reacted by Maurizio De Magnis and Checkmate Team
Metadata
Metadata
Assignees
Labels
No labels
Activity
olistik commentedon Jan 28, 2022
I think I found a workaround.
It's not pretty but at least I can now restore tests in my Gitlab CI. 😅
First of all, the issue with
URI's name resolution is likely fixable by applying this patch to activerecord (v6.1.4.4 in my case):As far as I know there's not this kind of fix on 6.x, yet so the question is how to fix it in the meanwhile.
I created a testing repository of activerecord v6.1.4.4 here: https://github.com/olistik/activerecord-test/
It contains the abovementioned patch.
Then I put this conditional require in my Gemfile and updated my
.gitlab-ci.ymlaccordingly:Gemfile:
.gitlab-ci.yml:
Hope to be helpful for someone in a similar situation. <3
Feel free to propose better solutions. 🎩
olistik commentedon Jun 7, 2022
I upgraded Rails to 6.1.6 and the problem somehow disappeared from my pipeline.
I did a quick scan of Rails' changelog but couldn't find a direct fix so 🤷🏻♂️ 😅