From d0bc93e2c559d9a362674dacba6b1f024b07f020 Mon Sep 17 00:00:00 2001 From: Aleksandar Ivanov Date: Thu, 2 Apr 2020 16:16:07 +0300 Subject: [PATCH 1/2] Test bug in rails 5 db:create / assets:precompile When running db:create or assets:precompile the gem does a db connection for no reason in rails 5.x. In rails 4 it is not doing it. The bug happens here: https://github.com/rails/rails/blob/v5.2.6/activerecord/lib/active_record/type.rb#L41 ``` def lookup(*args, adapter: current_adapter_name, **kwargs) # :nodoc: ``` `current_adapter_name` for some reason does a db connection. --- .circleci/config.yml | 2 - .gitignore | 1 + Appraisals | 25 ++-- CHANGELOG.md | 4 + gemfiles/rails_4.2.gemfile | 1 + gemfiles/rails_4.2.gemfile.lock | 149 ------------------- gemfiles/rails_5.0.gemfile.lock | 155 -------------------- gemfiles/rails_5.1.gemfile.lock | 155 -------------------- gemfiles/rails_5.2.gemfile.lock | 163 --------------------- gemfiles/rails_6.gemfile.lock | 179 ----------------------- lib/vault/latest/encrypted_model.rb | 1 + lib/vault/rails/version.rb | 2 +- spec/dummy/config/database.yml | 4 +- spec/dummy/config/initializers/vault.rb | 4 +- spec/integration/rails_db_create_spec.rb | 24 +++ spec/integration/rails_spec.rb | 20 +-- spec/spec_helper.rb | 14 +- 17 files changed, 74 insertions(+), 829 deletions(-) delete mode 100644 gemfiles/rails_4.2.gemfile.lock delete mode 100644 gemfiles/rails_5.0.gemfile.lock delete mode 100644 gemfiles/rails_5.1.gemfile.lock delete mode 100644 gemfiles/rails_5.2.gemfile.lock delete mode 100644 gemfiles/rails_6.gemfile.lock create mode 100644 spec/integration/rails_db_create_spec.rb diff --git a/.circleci/config.yml b/.circleci/config.yml index 9795e92d..85f67ef3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,9 +4,7 @@ aliases: environment: &environment RACK_ENV: test VAULT_VERSION: 0.10.4 - BUNDLER_VERSION: 2.1.4 command: &ruby-command | - gem install bundler:$BUNDLER_VERSION bundle check --path=vendor/bundle || bundle install --binstubs --jobs 4 --path=vendor/bundle --retry 3 bundle exec rake app:db:create bundle exec rake app:db:schema:load diff --git a/.gitignore b/.gitignore index f94de97f..f21a75c9 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ build/ Gemfile.lock .ruby-version .ruby-gemset +gemfiles/*.gemfile.lock # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc diff --git a/Appraisals b/Appraisals index 6b25703f..3d03c8ac 100644 --- a/Appraisals +++ b/Appraisals @@ -1,20 +1,25 @@ -appraise "rails-4.2" do - gem "rails", "~> 4.2.0" +appraise 'rails-4.2' do + gem 'rails', '~> 4.2.0' gem 'sqlite3', '~> 1.3.13' + gem 'bundler', '~> 1.17.3' end -appraise "rails-5.0" do - gem "rails", "~> 5.0.0" + +appraise 'rails-5.0' do + gem 'rails', '~> 5.0.0' gem 'sqlite3', '~> 1.3.13' end -appraise "rails-5.1" do - gem "rails", "~> 5.1.0" + +appraise 'rails-5.1' do + gem 'rails', '~> 5.1.0' gem 'sqlite3', '~> 1.3.13' end -appraise "rails-5.2" do - gem "rails", "~> 5.2.0" + +appraise 'rails-5.2' do + gem 'rails', '~> 5.2.0' gem 'sqlite3', '~> 1.3.13' end -appraise "rails-6" do - gem "rails", "~> 6" + +appraise 'rails-6' do + gem 'rails', '~> 6' gem 'sqlite3', '~> 1.4' end diff --git a/CHANGELOG.md b/CHANGELOG.md index 6837f84b..298dd33a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Vault Rails Changelog +## 2.1.0 (January 11, 2022) + +Prevent db queries on boot -> so that db:create / assets:precompile work + ## 2.0.5 (October 19, 2020) - Fix compatibility with `#with_lock` / `#lock!` - on initialization the `#changes` is no longer polluted. Fixed error: diff --git a/gemfiles/rails_4.2.gemfile b/gemfiles/rails_4.2.gemfile index 07b883b7..510b3205 100644 --- a/gemfiles/rails_4.2.gemfile +++ b/gemfiles/rails_4.2.gemfile @@ -4,5 +4,6 @@ source "https://rubygems.org" gem "rails", "~> 4.2.0" gem "sqlite3", "~> 1.3.13" +gem "bundler", "~> 1.17.3" gemspec path: "../" diff --git a/gemfiles/rails_4.2.gemfile.lock b/gemfiles/rails_4.2.gemfile.lock deleted file mode 100644 index 3095d47c..00000000 --- a/gemfiles/rails_4.2.gemfile.lock +++ /dev/null @@ -1,149 +0,0 @@ -PATH - remote: .. - specs: - fc-vault-rails (2.0.5) - activerecord (>= 4.2) - vault (~> 0.7) - -GEM - remote: https://rubygems.org/ - specs: - actionmailer (4.2.11.1) - actionpack (= 4.2.11.1) - actionview (= 4.2.11.1) - activejob (= 4.2.11.1) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.11.1) - actionview (= 4.2.11.1) - activesupport (= 4.2.11.1) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.11.1) - activesupport (= 4.2.11.1) - builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (4.2.11.1) - activesupport (= 4.2.11.1) - globalid (>= 0.3.0) - activemodel (4.2.11.1) - activesupport (= 4.2.11.1) - builder (~> 3.1) - activerecord (4.2.11.1) - activemodel (= 4.2.11.1) - activesupport (= 4.2.11.1) - arel (~> 6.0) - activesupport (4.2.11.1) - i18n (~> 0.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - appraisal (2.2.0) - bundler - rake - thor (>= 0.14.0) - arel (6.0.4) - aws-eventstream (1.0.3) - aws-sigv4 (1.1.0) - aws-eventstream (~> 1.0, >= 1.0.2) - builder (3.2.3) - byebug (11.0.1) - coderay (1.1.2) - concurrent-ruby (1.1.5) - crass (1.0.4) - diff-lcs (1.3) - erubis (2.7.0) - globalid (0.4.2) - activesupport (>= 4.2.0) - i18n (0.9.5) - concurrent-ruby (~> 1.0) - loofah (2.2.3) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) - mini_mime (>= 0.1.1) - method_source (0.9.2) - mini_mime (1.0.1) - mini_portile2 (2.4.0) - minitest (5.11.3) - nokogiri (1.10.2) - mini_portile2 (~> 2.4.0) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - rack (1.6.11) - rack-test (0.6.3) - rack (>= 1.0) - rails (4.2.11.1) - actionmailer (= 4.2.11.1) - actionpack (= 4.2.11.1) - actionview (= 4.2.11.1) - activejob (= 4.2.11.1) - activemodel (= 4.2.11.1) - activerecord (= 4.2.11.1) - activesupport (= 4.2.11.1) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.11.1) - sprockets-rails - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.9) - activesupport (>= 4.2.0, < 5.0) - nokogiri (~> 1.6) - rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) - railties (4.2.11.1) - actionpack (= 4.2.11.1) - activesupport (= 4.2.11.1) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (10.5.0) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) - sprockets (3.7.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) - sqlite3 (1.3.13) - thor (0.20.3) - thread_safe (0.3.6) - tzinfo (1.2.5) - thread_safe (~> 0.1) - vault (0.13.0) - aws-sigv4 - -PLATFORMS - ruby - -DEPENDENCIES - appraisal (~> 2.1) - bundler - byebug - fc-vault-rails! - pry - rails (~> 4.2.0) - rake - rspec (~> 3.2) - sqlite3 (~> 1.3.13) - -BUNDLED WITH - 2.1.2 diff --git a/gemfiles/rails_5.0.gemfile.lock b/gemfiles/rails_5.0.gemfile.lock deleted file mode 100644 index e72770ba..00000000 --- a/gemfiles/rails_5.0.gemfile.lock +++ /dev/null @@ -1,155 +0,0 @@ -PATH - remote: .. - specs: - fc-vault-rails (2.0.5) - activerecord (>= 4.2) - vault (~> 0.7) - -GEM - remote: https://rubygems.org/ - specs: - actioncable (5.0.7.1) - actionpack (= 5.0.7.1) - nio4r (>= 1.2, < 3.0) - websocket-driver (~> 0.6.1) - actionmailer (5.0.7.1) - actionpack (= 5.0.7.1) - actionview (= 5.0.7.1) - activejob (= 5.0.7.1) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (5.0.7.1) - actionview (= 5.0.7.1) - activesupport (= 5.0.7.1) - rack (~> 2.0) - rack-test (~> 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.7.1) - activesupport (= 5.0.7.1) - builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.0.7.1) - activesupport (= 5.0.7.1) - globalid (>= 0.3.6) - activemodel (5.0.7.1) - activesupport (= 5.0.7.1) - activerecord (5.0.7.1) - activemodel (= 5.0.7.1) - activesupport (= 5.0.7.1) - arel (~> 7.0) - activesupport (5.0.7.1) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - appraisal (2.2.0) - bundler - rake - thor (>= 0.14.0) - arel (7.1.4) - aws-eventstream (1.0.3) - aws-sigv4 (1.1.0) - aws-eventstream (~> 1.0, >= 1.0.2) - builder (3.2.3) - byebug (11.0.0) - coderay (1.1.2) - concurrent-ruby (1.1.4) - crass (1.0.4) - diff-lcs (1.3) - erubis (2.7.0) - globalid (0.4.2) - activesupport (>= 4.2.0) - i18n (1.5.3) - concurrent-ruby (~> 1.0) - loofah (2.2.3) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) - mini_mime (>= 0.1.1) - method_source (0.9.2) - mini_mime (1.0.1) - mini_portile2 (2.4.0) - minitest (5.11.3) - nio4r (2.3.1) - nokogiri (1.10.1) - mini_portile2 (~> 2.4.0) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - rack (2.0.6) - rack-test (0.6.3) - rack (>= 1.0) - rails (5.0.7.1) - actioncable (= 5.0.7.1) - actionmailer (= 5.0.7.1) - actionpack (= 5.0.7.1) - actionview (= 5.0.7.1) - activejob (= 5.0.7.1) - activemodel (= 5.0.7.1) - activerecord (= 5.0.7.1) - activesupport (= 5.0.7.1) - bundler (>= 1.3.0) - railties (= 5.0.7.1) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) - railties (5.0.7.1) - actionpack (= 5.0.7.1) - activesupport (= 5.0.7.1) - method_source - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (10.5.0) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) - sprockets (3.7.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) - sqlite3 (1.3.13) - thor (0.20.3) - thread_safe (0.3.6) - tzinfo (1.2.5) - thread_safe (~> 0.1) - vault (0.13.0) - aws-sigv4 - websocket-driver (0.6.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) - -PLATFORMS - ruby - -DEPENDENCIES - appraisal (~> 2.1) - bundler - byebug - fc-vault-rails! - pry - rails (~> 5.0.0) - rake - rspec (~> 3.2) - sqlite3 (~> 1.3.13) - -BUNDLED WITH - 2.1.2 diff --git a/gemfiles/rails_5.1.gemfile.lock b/gemfiles/rails_5.1.gemfile.lock deleted file mode 100644 index c631f523..00000000 --- a/gemfiles/rails_5.1.gemfile.lock +++ /dev/null @@ -1,155 +0,0 @@ -PATH - remote: .. - specs: - fc-vault-rails (2.0.5) - activerecord (>= 4.2) - vault (~> 0.7) - -GEM - remote: https://rubygems.org/ - specs: - actioncable (5.1.6.1) - actionpack (= 5.1.6.1) - nio4r (~> 2.0) - websocket-driver (~> 0.6.1) - actionmailer (5.1.6.1) - actionpack (= 5.1.6.1) - actionview (= 5.1.6.1) - activejob (= 5.1.6.1) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (5.1.6.1) - actionview (= 5.1.6.1) - activesupport (= 5.1.6.1) - rack (~> 2.0) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.6.1) - activesupport (= 5.1.6.1) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.1.6.1) - activesupport (= 5.1.6.1) - globalid (>= 0.3.6) - activemodel (5.1.6.1) - activesupport (= 5.1.6.1) - activerecord (5.1.6.1) - activemodel (= 5.1.6.1) - activesupport (= 5.1.6.1) - arel (~> 8.0) - activesupport (5.1.6.1) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - appraisal (2.2.0) - bundler - rake - thor (>= 0.14.0) - arel (8.0.0) - aws-eventstream (1.0.3) - aws-sigv4 (1.1.0) - aws-eventstream (~> 1.0, >= 1.0.2) - builder (3.2.3) - byebug (11.0.0) - coderay (1.1.2) - concurrent-ruby (1.1.4) - crass (1.0.4) - diff-lcs (1.3) - erubi (1.8.0) - globalid (0.4.2) - activesupport (>= 4.2.0) - i18n (1.5.3) - concurrent-ruby (~> 1.0) - loofah (2.2.3) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) - mini_mime (>= 0.1.1) - method_source (0.9.2) - mini_mime (1.0.1) - mini_portile2 (2.4.0) - minitest (5.11.3) - nio4r (2.3.1) - nokogiri (1.10.1) - mini_portile2 (~> 2.4.0) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - rack (2.0.6) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (5.1.6.1) - actioncable (= 5.1.6.1) - actionmailer (= 5.1.6.1) - actionpack (= 5.1.6.1) - actionview (= 5.1.6.1) - activejob (= 5.1.6.1) - activemodel (= 5.1.6.1) - activerecord (= 5.1.6.1) - activesupport (= 5.1.6.1) - bundler (>= 1.3.0) - railties (= 5.1.6.1) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) - railties (5.1.6.1) - actionpack (= 5.1.6.1) - activesupport (= 5.1.6.1) - method_source - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (10.5.0) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) - sprockets (3.7.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) - sqlite3 (1.3.13) - thor (0.20.3) - thread_safe (0.3.6) - tzinfo (1.2.5) - thread_safe (~> 0.1) - vault (0.13.0) - aws-sigv4 - websocket-driver (0.6.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) - -PLATFORMS - ruby - -DEPENDENCIES - appraisal (~> 2.1) - bundler - byebug - fc-vault-rails! - pry - rails (~> 5.1.0) - rake - rspec (~> 3.2) - sqlite3 (~> 1.3.13) - -BUNDLED WITH - 2.1.2 diff --git a/gemfiles/rails_5.2.gemfile.lock b/gemfiles/rails_5.2.gemfile.lock deleted file mode 100644 index 8214692d..00000000 --- a/gemfiles/rails_5.2.gemfile.lock +++ /dev/null @@ -1,163 +0,0 @@ -PATH - remote: .. - specs: - fc-vault-rails (2.0.5) - activerecord (>= 4.2) - vault (~> 0.7) - -GEM - remote: https://rubygems.org/ - specs: - actioncable (5.2.2) - actionpack (= 5.2.2) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailer (5.2.2) - actionpack (= 5.2.2) - actionview (= 5.2.2) - activejob (= 5.2.2) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (5.2.2) - actionview (= 5.2.2) - activesupport (= 5.2.2) - rack (~> 2.0) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.2) - activesupport (= 5.2.2) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.2) - activesupport (= 5.2.2) - globalid (>= 0.3.6) - activemodel (5.2.2) - activesupport (= 5.2.2) - activerecord (5.2.2) - activemodel (= 5.2.2) - activesupport (= 5.2.2) - arel (>= 9.0) - activestorage (5.2.2) - actionpack (= 5.2.2) - activerecord (= 5.2.2) - marcel (~> 0.3.1) - activesupport (5.2.2) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - appraisal (2.2.0) - bundler - rake - thor (>= 0.14.0) - arel (9.0.0) - aws-eventstream (1.0.3) - aws-sigv4 (1.1.0) - aws-eventstream (~> 1.0, >= 1.0.2) - builder (3.2.3) - byebug (11.0.0) - coderay (1.1.2) - concurrent-ruby (1.1.4) - crass (1.0.4) - diff-lcs (1.3) - erubi (1.8.0) - globalid (0.4.2) - activesupport (>= 4.2.0) - i18n (1.5.3) - concurrent-ruby (~> 1.0) - loofah (2.2.3) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) - mini_mime (>= 0.1.1) - marcel (0.3.3) - mimemagic (~> 0.3.2) - method_source (0.9.2) - mimemagic (0.3.3) - mini_mime (1.0.1) - mini_portile2 (2.4.0) - minitest (5.11.3) - nio4r (2.3.1) - nokogiri (1.10.1) - mini_portile2 (~> 2.4.0) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - rack (2.0.6) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (5.2.2) - actioncable (= 5.2.2) - actionmailer (= 5.2.2) - actionpack (= 5.2.2) - actionview (= 5.2.2) - activejob (= 5.2.2) - activemodel (= 5.2.2) - activerecord (= 5.2.2) - activestorage (= 5.2.2) - activesupport (= 5.2.2) - bundler (>= 1.3.0) - railties (= 5.2.2) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) - railties (5.2.2) - actionpack (= 5.2.2) - activesupport (= 5.2.2) - method_source - rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) - rake (10.5.0) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) - sprockets (3.7.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) - sqlite3 (1.3.13) - thor (0.20.3) - thread_safe (0.3.6) - tzinfo (1.2.5) - thread_safe (~> 0.1) - vault (0.13.0) - aws-sigv4 - websocket-driver (0.7.0) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) - -PLATFORMS - ruby - -DEPENDENCIES - appraisal (~> 2.1) - bundler - byebug - fc-vault-rails! - pry - rails (~> 5.2.0) - rake - rspec (~> 3.2) - sqlite3 (~> 1.3.13) - -BUNDLED WITH - 2.1.2 diff --git a/gemfiles/rails_6.gemfile.lock b/gemfiles/rails_6.gemfile.lock deleted file mode 100644 index ce3750f3..00000000 --- a/gemfiles/rails_6.gemfile.lock +++ /dev/null @@ -1,179 +0,0 @@ -PATH - remote: .. - specs: - fc-vault-rails (2.0.5) - activerecord (>= 4.2) - vault (~> 0.7) - -GEM - remote: https://rubygems.org/ - specs: - actioncable (6.0.1) - actionpack (= 6.0.1) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailbox (6.0.1) - actionpack (= 6.0.1) - activejob (= 6.0.1) - activerecord (= 6.0.1) - activestorage (= 6.0.1) - activesupport (= 6.0.1) - mail (>= 2.7.1) - actionmailer (6.0.1) - actionpack (= 6.0.1) - actionview (= 6.0.1) - activejob (= 6.0.1) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (6.0.1) - actionview (= 6.0.1) - activesupport (= 6.0.1) - rack (~> 2.0) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.0.1) - actionpack (= 6.0.1) - activerecord (= 6.0.1) - activestorage (= 6.0.1) - activesupport (= 6.0.1) - nokogiri (>= 1.8.5) - actionview (6.0.1) - activesupport (= 6.0.1) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.0.1) - activesupport (= 6.0.1) - globalid (>= 0.3.6) - activemodel (6.0.1) - activesupport (= 6.0.1) - activerecord (6.0.1) - activemodel (= 6.0.1) - activesupport (= 6.0.1) - activestorage (6.0.1) - actionpack (= 6.0.1) - activejob (= 6.0.1) - activerecord (= 6.0.1) - marcel (~> 0.3.1) - activesupport (6.0.1) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2) - appraisal (2.2.0) - bundler - rake - thor (>= 0.14.0) - aws-eventstream (1.0.3) - aws-sigv4 (1.1.0) - aws-eventstream (~> 1.0, >= 1.0.2) - builder (3.2.3) - byebug (11.0.1) - coderay (1.1.2) - concurrent-ruby (1.1.5) - crass (1.0.5) - diff-lcs (1.3) - erubi (1.9.0) - globalid (0.4.2) - activesupport (>= 4.2.0) - i18n (1.7.0) - concurrent-ruby (~> 1.0) - loofah (2.4.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) - mini_mime (>= 0.1.1) - marcel (0.3.3) - mimemagic (~> 0.3.2) - method_source (0.9.2) - mimemagic (0.3.3) - mini_mime (1.0.2) - mini_portile2 (2.4.0) - minitest (5.13.0) - nio4r (2.5.2) - nokogiri (1.10.5) - mini_portile2 (~> 2.4.0) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - rack (2.0.7) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (6.0.1) - actioncable (= 6.0.1) - actionmailbox (= 6.0.1) - actionmailer (= 6.0.1) - actionpack (= 6.0.1) - actiontext (= 6.0.1) - actionview (= 6.0.1) - activejob (= 6.0.1) - activemodel (= 6.0.1) - activerecord (= 6.0.1) - activestorage (= 6.0.1) - activesupport (= 6.0.1) - bundler (>= 1.3.0) - railties (= 6.0.1) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.3.0) - loofah (~> 2.3) - railties (6.0.1) - actionpack (= 6.0.1) - activesupport (= 6.0.1) - method_source - rake (>= 0.8.7) - thor (>= 0.20.3, < 2.0) - rake (13.0.1) - rspec (3.9.0) - rspec-core (~> 3.9.0) - rspec-expectations (~> 3.9.0) - rspec-mocks (~> 3.9.0) - rspec-core (3.9.0) - rspec-support (~> 3.9.0) - rspec-expectations (3.9.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-mocks (3.9.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-support (3.9.0) - sprockets (4.0.0) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) - sqlite3 (1.4.1) - thor (0.20.3) - thread_safe (0.3.6) - tzinfo (1.2.5) - thread_safe (~> 0.1) - vault (0.13.0) - aws-sigv4 - websocket-driver (0.7.1) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.4) - zeitwerk (2.2.2) - -PLATFORMS - ruby - -DEPENDENCIES - appraisal (~> 2.1) - bundler - byebug - fc-vault-rails! - pry - rails (~> 6) - rake - rspec (~> 3.2) - sqlite3 (~> 1.4) - -BUNDLED WITH - 2.1.2 diff --git a/lib/vault/latest/encrypted_model.rb b/lib/vault/latest/encrypted_model.rb index 40b22fd1..cc4b8b50 100644 --- a/lib/vault/latest/encrypted_model.rb +++ b/lib/vault/latest/encrypted_model.rb @@ -164,6 +164,7 @@ def _vault_validate_options!(options) end def _vault_fetch_attribute_type(options) + puts "Attribute Type: ; #{options.inspect}" attribute_type = options.fetch(:type, ActiveRecord::Type::Value.new) if attribute_type.is_a?(Symbol) diff --git a/lib/vault/rails/version.rb b/lib/vault/rails/version.rb index 0fd157dc..8ccd1eba 100644 --- a/lib/vault/rails/version.rb +++ b/lib/vault/rails/version.rb @@ -1,6 +1,6 @@ module Vault module Rails - VERSION = "2.0.5" + VERSION = "2.1.0" def self.latest? ActiveRecord.version >= Gem::Version.new('5.0.0') diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml index 0b956764..99a96a21 100644 --- a/spec/dummy/config/database.yml +++ b/spec/dummy/config/database.yml @@ -5,8 +5,8 @@ default: &default development: <<: *default - database: db/development.sqlite3 + database: <%= ENV['FC_VAULT_RAILS_DUMMY_DATABASE_PATH'] || 'db/development.sqlite3' %> test: <<: *default - database: db/test.sqlite3 + database: 'db/test.sqlite3' diff --git a/spec/dummy/config/initializers/vault.rb b/spec/dummy/config/initializers/vault.rb index 2f4b66bb..ff7867ff 100644 --- a/spec/dummy/config/initializers/vault.rb +++ b/spec/dummy/config/initializers/vault.rb @@ -5,7 +5,7 @@ Vault::Rails.configure do |vault| vault.application = "dummy" - vault.address = RSpec::VaultServer.address - vault.token = RSpec::VaultServer.token + vault.address = ENV['FC_VAULT_RAILS_DUMMY_VAULT_SERVER'] || RSpec::VaultServer.address + vault.token = ENV['FC_VAULT_RAILS_DUMMY_VAULT_TOKEN'] || RSpec::VaultServer.token vault.enabled = true end diff --git a/spec/integration/rails_db_create_spec.rb b/spec/integration/rails_db_create_spec.rb new file mode 100644 index 00000000..1e8eb7fe --- /dev/null +++ b/spec/integration/rails_db_create_spec.rb @@ -0,0 +1,24 @@ +# encoding: utf-8 + +require "spec_helper" + +RSpec.describe './bin/rake db:create' do + it "works == the code doesn't need a database to load" do + db_file = File.join(dummy_root, 'db/rails_db_create_spec.sqlite3') + + File.delete(db_file) if File.exist?(db_file) + + command = [ + 'RAILS_ENV=development', + 'FC_VAULT_RAILS_DUMMY_DATABASE_PATH="db/rails_db_create_spec.sqlite3"', + "FC_VAULT_RAILS_DUMMY_VAULT_SERVER='#{RSpec::VaultServer.address}'", + "FC_VAULT_RAILS_DUMMY_VAULT_TOKEN='#{RSpec::VaultServer.token}'", + "#{dummy_root}/bin/rails runner 'puts TypedPerson.class'" + ] + + `#{command.join(' ')}` + + # If the file exists it means that rails tried to connect to the database + expect(File.exist?(db_file)).to eq(false) + end +end diff --git a/spec/integration/rails_spec.rb b/spec/integration/rails_spec.rb index 8c5eeebd..e1d63c8e 100644 --- a/spec/integration/rails_spec.rb +++ b/spec/integration/rails_spec.rb @@ -48,7 +48,7 @@ it "allows attributes to be updated with nil values" do person = Person.create!(ssn: "123-45-6789") - person.update_attributes!(ssn: nil) + person.update!(ssn: nil) person.reload expect(person.ssn).to be(nil) @@ -69,7 +69,7 @@ it "allows attributes to be unset after reload" do person = Person.create!(ssn: "123-45-6789") person.reload - person.update_attributes!(ssn: nil) + person.update!(ssn: nil) person.reload expect(person.ssn).to be(nil) @@ -77,7 +77,7 @@ it "allows attributes to be blank" do person = Person.create!(ssn: "123-45-6789") - person.update_attributes!(ssn: "") + person.update!(ssn: "") person.reload expect(person.ssn).to eq("") @@ -192,7 +192,7 @@ it "allows attributes to be unset" do person = LazyPerson.create!(ssn: "123-45-6789") - person.update_attributes!(ssn: nil) + person.update!(ssn: nil) person.reload expect(person.ssn).to be(nil) @@ -207,7 +207,7 @@ it "allows attributes to be unset after reload" do person = LazyPerson.create!(ssn: "123-45-6789") person.reload - person.update_attributes!(ssn: nil) + person.update!(ssn: nil) person.reload expect(person.ssn).to be(nil) @@ -221,7 +221,7 @@ it "allows attributes to be blank" do person = LazyPerson.create!(ssn: "123-45-6789") - person.update_attributes!(ssn: "") + person.update!(ssn: "") person.reload expect(person.ssn).to eq("") @@ -287,7 +287,7 @@ it "allows attributes to be unset" do person = Person.create!(credit_card: "1234567890111213") - person.update_attributes!(credit_card: nil) + person.update!(credit_card: nil) person.reload expect(person.credit_card).to be(nil) @@ -295,7 +295,7 @@ it "allows attributes to be blank" do person = Person.create!(credit_card: "1234567890111213") - person.update_attributes!(credit_card: "") + person.update!(credit_card: "") person.reload expect(person.credit_card).to eq("") @@ -337,7 +337,7 @@ it "allows attributes to be unset" do person = Person.create!(non_ascii: "dás ümlaut") - person.update_attributes!(non_ascii: nil) + person.update!(non_ascii: nil) person.reload expect(person.non_ascii).to be(nil) @@ -345,7 +345,7 @@ it "allows attributes to be blank" do person = Person.create!(non_ascii: "dás ümlaut") - person.update_attributes!(non_ascii: "") + person.update!(non_ascii: "") person.reload expect(person.non_ascii).to eq("") diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2f9dfdaf..891d2196 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,21 @@ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) -require "vault/rails" +require "vault/rails" require "rspec" +module PathHelpers + def project_root + @project_root ||= File.expand_path('../..', __FILE__) + end + + def dummy_root + File.join(project_root, 'spec', 'dummy') + end +end + RSpec.configure do |config| + config.include PathHelpers + # Prohibit using the should syntax config.expect_with :rspec do |spec| spec.syntax = :expect From 006f61cf000f0a55aa6623582118b680f09afe9a Mon Sep 17 00:00:00 2001 From: Aleksandar Ivanov Date: Tue, 11 Jan 2022 14:48:22 +0200 Subject: [PATCH 2/2] Prevent db connection on boot The lookup call tries to establish connection to the database when the application code is loading. This bugs rake tasks like db:create / assets:precompile https://github.com/rails/rails/blob/v5.2.6/activerecord/lib/active_record/type.rb#L41 ``` def lookup(*args, adapter: current_adapter_name, **kwargs) # :nodoc: ``` The `current_adapter_name` for some reason does a db connection. The code is change to getting the current adapter with `ActiveRecord::Base.connection_config[:adapter]`, which is not making a db connection. --- lib/vault/latest/encrypted_model.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/vault/latest/encrypted_model.rb b/lib/vault/latest/encrypted_model.rb index cc4b8b50..1bdd12ab 100644 --- a/lib/vault/latest/encrypted_model.rb +++ b/lib/vault/latest/encrypted_model.rb @@ -164,11 +164,14 @@ def _vault_validate_options!(options) end def _vault_fetch_attribute_type(options) - puts "Attribute Type: ; #{options.inspect}" attribute_type = options.fetch(:type, ActiveRecord::Type::Value.new) if attribute_type.is_a?(Symbol) - ActiveRecord::Type.lookup(attribute_type) + if ActiveRecord::Base.connection_config[:adapter] + ActiveRecord::Type.lookup(attribute_type, adapter: ActiveRecord::Base.connection_config[:adapter]) + else + ActiveRecord::Type.lookup(attribute_type) # This call does a db connection, best find a way to configure `ActiveRecord::Base.connection_config[:adapter]` + end else ActiveModel::Type::Value.new end