Project

General

Profile

Refactor #13409

Remove maintain_test_schema! Rails initializer

Added by Dominic Cleal over 3 years ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Rails
Target version:
Difficulty:
Triaged:
Bugzilla link:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

The config/initializers/0_maintain_test_schema.rb initializer added in #7230 can potentially be removed with some further fixes.

It exists to initialise the test database before the main Rails app and models are initialised, fixing a couple of bugs where loading the model requires the table to already be available. If the table isn't available then validators etc. aren't set up correctly and tests may fail. Removing the initialiser and the test DB, then running rake test shows the issue. More info in #12873.

#13039 fixed one issue, but I think two further fixes are required:

1) validates_lengths_from_database needs to avoid reading DB information to set up its validators. https://github.com/rubiety/validates_lengths_from_database/pull/12 fixes this.

2) Our own validate_inclusion_in_families validator should not check for the attribute's existence - this check can probably be removed.


Related issues

Related to Foreman - Feature #7230: Upgrade Ruby on Rails to 4.1Closed2014-08-22
Related to Foreman - Refactor #13039: Remove DB queries from class of UnattendedControllerClosed2016-01-07
Related to Foreman - Feature #12873: Update Rails to 4.1.latestClosed2015-12-18
Blocked by Foreman - Bug #13574: Plugins with Setting subclasses raise super: no superclass method `load_defaults' errorClosed2016-02-05

Associated revisions

Revision f20c2a1a (diff)
Added by Dominic Cleal over 3 years ago

fixes #13409 - remove early initialisation of test DB

All models etc. referenced within the Rails environment startup,
including in initialisers should load without making any reference to
the database. This ensures when running `rake test` without a test DB
set up already that the Rails env can be loaded first by Rails before
it prepares the test DB from db/schema.rb (itself created by a
db:migrate in dev/prod envs).

The table_name for Ptable needed to be overridden, matching
ProvisioningTemplate as it defaulted to 'ptables' rather than
'templates' when the `attribute_names` call was removed from
validate_inclusion_in_families.

References to attribute_names in API controller wrapping overrides
were replaced by reusing the protected_attribute lists, which don't use
the database and are also more consistent than the existing lists.

Revision 56b90b51 (diff)
Added by Dominic Cleal over 3 years ago

refs #13409 - min version of validates_lengths_from_database

History

#1 Updated by Dominic Cleal over 3 years ago

#2 Updated by Dominic Cleal over 3 years ago

  • Related to Refactor #13039: Remove DB queries from class of UnattendedController added

#3 Updated by Dominic Cleal over 3 years ago

#4 Updated by Dominic Cleal over 3 years ago

  • Blocked by Bug #13574: Plugins with Setting subclasses raise super: no superclass method `load_defaults' error added

#5 Updated by Dominic Cleal over 3 years ago

  • Status changed from New to Assigned
  • Assignee set to Dominic Cleal

#6 Updated by The Foreman Bot over 3 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/3182 added

#7 Updated by Dominic Cleal over 3 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#8 Updated by Dominic Cleal over 3 years ago

  • Legacy Backlogs Release (now unused) set to 71

Also available in: Atom PDF