Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration to surpress active_record checks #2266

Merged
merged 4 commits into from Mar 13, 2020

Conversation

JonRowe
Copy link
Member

@JonRowe JonRowe commented Jan 21, 2020

Alternative to #2038 fixes #1876.

I'm currently missing a reliable test for this, the approach in #2038 is one I do not want to take, we've never configured a database and our specs have worked, so if this switch is required when no database is present there has to be a way to trigger that error without configuring a database?

Backtrace from stackoverflow:

 ActiveRecord::ConnectionNotEstablished:
   No connection pool with id primary found.
 # activerecord-5.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `retrieve_connection'
 # activerecord-5.0.1/lib/active_record/connection_handling.rb:128:in `retrieve_connection'
 # activerecord-5.0.1/lib/active_record/connection_handling.rb:91:in `connection'
 # activerecord-5.0.1/lib/active_record/fixtures.rb:516:in `create_fixtures'
 # activerecord-5.0.1/lib/active_record/fixtures.rb:1015:in `load_fixtures'
 # activerecord-5.0.1/lib/active_record/fixtures.rb:988:in `setup_fixtures'
 # activerecord-5.0.1/lib/active_record/fixtures.rb:852:in `before_setup'
 # rspec-rails-3.6.1/lib/rspec/rails/adapters.rb:126:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
 # rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'

@pirj
Copy link
Member

pirj commented Mar 4, 2020

@JonRowe this seems trivial and mostly working, I can take it from here if you like.

@JonRowe
Copy link
Member Author

JonRowe commented Mar 4, 2020

@pirj Happy for you to take it from here, I might have more time to work on it later.

@pirj
Copy link
Member

pirj commented Mar 4, 2020

Sounds good 👍

Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's so tempting to remove this.

@pirj
Copy link
Member

pirj commented Mar 6, 2020

What tests did you have in mind to cover this change, @JonRowe ?

@pirj pirj marked this pull request as ready for review March 6, 2020 08:01
@JonRowe
Copy link
Member Author

JonRowe commented Mar 6, 2020

It's so tempting to remove this.

I mean I guess we could, but maybe in rspec-rails 5 is better, and we deprecate it for now...

What tests did you have in mind to cover this change, @JonRowe ?

We need to disable the db and check that it still works

@pirj pirj self-assigned this Mar 9, 2020
@benoittgt
Copy link
Member

I mean I guess we could, but maybe in rspec-rails 5 is better, and we deprecate it for now...

+1

@JonRowe
Copy link
Member Author

JonRowe commented Mar 12, 2020

This passes the build now, for tests I think the best step is to add something to the no_active_record smoke app that tests that nothing happens with fixtures when this is turned off

@pirj
Copy link
Member

pirj commented Mar 12, 2020

That's what I'm on right now. Trying to reproduce the original failure from this app to mimic it properly in the test.

end
end
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's like that since the original problem was that active_record was defined, just wasn't used and DB wasn't set up.

I've double-checked that this test does blow up if config.use_active_record = true inside no_active_record app.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried hard, but couldn't make this example repo work to reproduce the original issue. Mostly due to bundler 1/2 problem, and then dependencies hell with Rails version which I had to update to 5.2, and in the end with missing rake-test's methods, probably due to version mismatch.

@@ -44,6 +44,7 @@ def setup_tasks

def final_tasks
copy_file 'spec/verify_no_active_record_spec.rb'
copy_file 'spec/verify_no_fixture_setup_spec.rb'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added another spec to the smoke app. Should it be done differently?

Copy link
Member Author

@JonRowe JonRowe Mar 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry no, I read this as being identical several times, must be getting late 😂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused as well when I've finished typing its name 😆

@JonRowe
Copy link
Member Author

JonRowe commented Mar 13, 2020

Fixes #1876

@JonRowe
Copy link
Member Author

JonRowe commented Mar 13, 2020

@pirj I rewrote the commits for this and re-pushed, once green I'm going to merge if you're happy?

Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@pirj
Copy link
Member

pirj commented Mar 13, 2020

@Jack12816 @mrgordon @JoostVanAverbeke does this work for you?

@JonRowe JonRowe merged commit 148f7ce into master Mar 13, 2020
@JonRowe JonRowe deleted the configure-active-record branch March 13, 2020 10:21
@mrgordon
Copy link

Thanks!

JonRowe added a commit that referenced this pull request Mar 13, 2020
Add configuration to surpress active_record checks
bilbof pushed a commit to alphagov/govuk-coronavirus-business-volunteer-form that referenced this pull request Apr 14, 2020
This new environment will be used for smoke testing only.
E.g. RAILS_ENV=smoke_test TEST_URL=... bundle exec rake spec:features

A new environment is required since RSpec requires a DB to be running
and connected to in order to run the tests. We could delete the constant
ActiveRecord e.g. Object.send(:remove_const, :ActiveRecord), but I decided
to use a new env that doesn't load it instead.

Alternative approaches:
- We could use https://github.com/nulldb/nulldb rather than not requiring
  ActiveRecord
- There might be a way to use rspec/rspec-rails#2266
  but I don't think it helps our situations, since we do need ActiveRecord.
bilbof pushed a commit to alphagov/govuk-coronavirus-business-volunteer-form that referenced this pull request Apr 14, 2020
This new environment will be used for smoke testing only.
E.g. RAILS_ENV=smoke_test TEST_URL=... bundle exec rake spec:features

A new environment is required since RSpec requires a DB to be running
and connected to in order to run the tests. We could delete the constant
ActiveRecord e.g. Object.send(:remove_const, :ActiveRecord), but I decided
to use a new env that doesn't load it instead.

Alternative approaches:
- We could use https://github.com/nulldb/nulldb rather than not requiring
  ActiveRecord
- There might be a way to use rspec/rspec-rails#2266
  but I don't think it helps our situations, since we do need ActiveRecord.
bilbof pushed a commit to alphagov/govuk-coronavirus-business-volunteer-form that referenced this pull request Apr 14, 2020
This new environment will be used for smoke testing only.
E.g. RAILS_ENV=smoke_test TEST_URL=... bundle exec rake spec:features

A new environment is required since RSpec requires a DB to be running
and connected to in order to run the tests. We could delete the constant
ActiveRecord e.g. Object.send(:remove_const, :ActiveRecord), but I decided
to use a new env that doesn't load it instead.

Alternative approaches:
- We could use https://github.com/nulldb/nulldb rather than not requiring
  ActiveRecord
- There might be a way to use rspec/rspec-rails#2266
  but I don't think it helps our situations, since we do need ActiveRecord.
bilbof pushed a commit to alphagov/govuk-coronavirus-business-volunteer-form that referenced this pull request Apr 14, 2020
This new environment will be used for smoke testing only.
E.g. RAILS_ENV=smoke_test TEST_URL=... bundle exec rake spec:features

A new environment is required since RSpec requires a DB to be running
and connected to in order to run the tests. We could delete the constant
ActiveRecord e.g. Object.send(:remove_const, :ActiveRecord), but I decided
to use a new env that doesn't load it instead.

Alternative approaches:
- We could use https://github.com/nulldb/nulldb rather than not requiring
  ActiveRecord
- There might be a way to use rspec/rspec-rails#2266
  but I don't think it helps our situations, since we do need ActiveRecord.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a global switch for ActiveRecord
5 participants