Bug #18235

PageletsHelperTest doesn't entirely isolate Pagelet::Manager state

Added by Dominic Cleal about 1 year ago. Updated about 1 year 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/4226
Story points-
Velocity based estimate-
Release1.15.0Release relationshipAuto

Description

Running these tests in sequence causes failures in the integration test:

  1. test/controllers/smart_proxies_controller_test.rb
  2. test/helpers/pagelets_helper_test.rb
  3. test/integration/smart_proxy_test.rb
  1) Error:
SmartProxyIntegrationTest#test_0003_edit page:
ActionView::Template::Error: Missing partial smart_proxies/_test, application/_test with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :rabl]}. Searched in:
  * "/home/dcleal/code/foreman/foreman/app/views" 
  * "/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/foreman-tasks-0.8.6/app/views" 
  * "/home/dcleal/.rvm/gems/ruby-2.3.0@foreman/gems/apipie-rails-0.3.7/app/views" 

    app/helpers/pagelets_helper.rb:43:in `render_pagelet'
    app/helpers/pagelets_helper.rb:26:in `block in render_tab_content_for'
    app/helpers/pagelets_helper.rb:23:in `each'
    app/helpers/pagelets_helper.rb:23:in `render_tab_content_for'
    app/views/smart_proxies/show.html.erb:116:in `_app_views_smart_proxies_show_html_erb___2994894796435701335_115606720'
    app/controllers/concerns/application_shared.rb:14:in `set_timezone'
    app/models/concerns/foreman/thread_session.rb:32:in `clear_thread'
    lib/middleware/catch_json_parse_errors.rb:8:in `call'
    lib/middleware/tagged_logging.rb:18:in `call'
    test/integration/smart_proxy_test.rb:25:in `block in <class:SmartProxyIntegrationTest>'

(plus a few other tests in the same integration test case)

The attempt to save/restore state in PageletsHelperTest is insufficient, as it uses Hash#clone to take a copy of Pagelet::Manager's @pagelets variable. This creates a copy of the top-level hash, but the inner hash references remain the same.

When PageletsHelperTest adds to the "smart_proxies/show" inner hash to register a test pagelet, the pagelet stays registered even after the original state is restored as both the original @pagelets hash and restored @pagelets hash refer to the same inner "smart_proxies/show" hash which was modified. The inner hash isn't saved/restored.


Related issues

Related to Foreman - Refactor #15405: Move puppet related helpers to a separate helper class. Closed 06/14/2016

Associated revisions

Revision 36483d66
Added by Dominic Cleal about 1 year ago

fixes #18233, #18235 - isolate pagelets state between tests

Moves pagelets state into instances of Pagelets::Manager with clearer
dup semantics, and allows the instance to be backed up and restored
around tests using the PageletsIsolation test case mixin.

History

#1 Updated by Dominic Cleal about 1 year ago

  • Related to Refactor #15405: Move puppet related helpers to a separate helper class. added

#2 Updated by The Foreman Bot about 1 year ago

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

#3 Updated by Dominic Cleal about 1 year ago

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

#4 Updated by Dominic Cleal about 1 year ago

  • Release set to 1.15.0

Also available in: Atom PDF