Refactor #16557

Move tests into test/models, controllers, helpers dirs.

Added by Dominic Cleal 6 months ago. Updated 5 months ago.

Status:Closed
Priority:Normal
Assigned To:Dominic Cleal
Category:Tests
Target version:-
Difficulty: Bugzilla link:
Found in release: Pull request:https://github.com/theforeman/foreman/pull/3888, https://github.com/theforeman/foreman/pull/3843
Story points-
Velocity based estimate-
Release1.14.0Release relationshipAuto

Description

Rails 4 recommends using test/models/, test/controllers/, test/mailers/ and test/helpers/ to match the app/ layout for tests rather than having test/unit/ contain model and general unit/service object tests.

This is also important under Rails 5 which fails to run rake test when these directories don't exist:

$ rake test:units
rake aborted!
LoadError: cannot load such file -- /home/dcleal/code/foreman/foreman/test/models
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/railties-5.0.0/lib/rails/test_unit/test_requirer.rb:11:in `block in require_files'
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/railties-5.0.0/lib/rails/test_unit/test_requirer.rb:10:in `each'
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/railties-5.0.0/lib/rails/test_unit/test_requirer.rb:10:in `require_files'
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/railties-5.0.0/lib/rails/test_unit/minitest_plugin.rb:76:in `plugin_rails_init'
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/minitest-5.1.0/lib/minitest.rb:73:in `block in init_plugins'
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/minitest-5.1.0/lib/minitest.rb:71:in `each'
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/minitest-5.1.0/lib/minitest.rb:71:in `init_plugins'
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/minitest-5.1.0/lib/minitest.rb:122:in `run'
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/railties-5.0.0/lib/rails/test_unit/minitest_plugin.rb:64:in `rake_run'
/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/railties-5.0.0/lib/rails/test_unit/testing.rake:43:in `block (2 levels) in <top (required)>'

Moving models into test/models/ and using test/unit/ for other objects would also allow test/lib/ to be rolled into test/unit/ in a more logical way, which allows us to remove the custom test:lib rake task.

(http://guides.rubyonrails.org/testing.html#rails-sets-up-for-testing-from-the-word-go and https://github.com/rails/rails/blob/4-2-stable/railties/lib/rails/test_unit/testing.rake show possible directories)


Related issues

Related to Foreman - Bug #16700: Intermittent AboutIntegrationTest.test_0001_about page in... Closed 09/27/2016
Related to Foreman - Bug #16821: AccessPermissionsTest does not pick up plugin permissions Closed 10/06/2016

Associated revisions

Revision ea98080f
Added by Dominic Cleal 5 months ago

fixes #16557 - move tests into modern Rails layout

Models, controllers, mailers and helpers are now in test/ subdirs
matching app/ subdirs. Service, miscellaneous and old test/lib/ tests
are now in test/unit/ separated from models, which obsoletes the custom
test:lib rake task.

Removing the rake task also removed an entire second Rails environment
load from `rake test` which was writing to the Rails cache to initialise
settings. The reset_setting_cache test helper is now more robust against
the cache being missing on clean checkouts.

JSON fixtures are moved to the same test/static_fixtures/ directory so
they can be accessed uniformly from all tests.

Revision 7743d017
Added by Dominic Cleal 5 months ago

refs #16557 - move templates helper test to correct dir

History

#1 Updated by The Foreman Bot 6 months ago

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

#2 Updated by Dominic Cleal 5 months ago

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

#3 Updated by The Foreman Bot 5 months ago

  • Pull request https://github.com/theforeman/foreman/pull/3888 added

#4 Updated by Dominic Cleal 5 months ago

  • Release set to 1.14.0

#5 Updated by Dominic Cleal 5 months ago

  • Related to Bug #16700: Intermittent AboutIntegrationTest.test_0001_about page integration test failures added

#6 Updated by Dominic Cleal 5 months ago

  • Related to Bug #16821: AccessPermissionsTest does not pick up plugin permissions added

Also available in: Atom PDF