Project

General

Profile

« Previous | Next » 

Revision 52258efc

Added by Daniel Lobato Garcia over 6 years ago

Fixes #22430 - Plugin permissions are cleared on tests

- Some tests are removing all plugins (plugin_test, rabl_test,
belongs_to_proxy_test) from the registry. This has, among others,
one important consequence: the plugin permissions are removed.

- Take an example. Foreman Ansible overrides the Host#form with a
list of 'Ansible Roles' to choose.

- When the view for this Host#form is rendered (e.g: a
HostController or HostJSTest), the list of 'Ansible Roles' has
also to be rendered.

- Since a previous test removed the plugin from the
`Foreman::Plugin.all` registry, but the plugin is still installed
as a Rails Engine, the overrides by deface still apply.

- Some tests that render the Host form fail to run as rendering is
impossible without the 'ansible_roles' permission. These
permissions are only loaded in tests if the plugin is registered
in Foreman::Plugin*

View differences:

test/models/concerns/belongs_to_proxies_test.rb
include BelongsToProxies
end
setup do
Foreman::Plugin.clear
end
teardown do
Foreman::Plugin.clear
end
setup :clear_plugins
teardown :restore_plugins
test '#registered_smart_proxies has default value' do
assert_equal({}, EmptySampleModel.registered_smart_proxies)
test/test_helper.rb
Webpack::Rails::Manifest.stubs(:asset_paths).returns([])
end
end
def clear_plugins
@klass = Foreman::Plugin
@plugins_backup = @klass.registered_plugins
@klass.clear
end
def restore_plugins
@klass.clear
@klass.instance_variable_set('@registered_plugins', @plugins_backup)
end
test/unit/plugin_test.rb
end
end
def setup
@klass = Foreman::Plugin
# In case some real plugins are installed
@klass.clear
end
def teardown
@klass.clear
end
setup :clear_plugins
teardown :restore_plugins
def test_register
@klass.register :foo do
test/unit/rabl_test.rb
end
context 'with plugin' do
setup do
@klass = Foreman::Plugin
@klass.clear
end
teardown do
@klass.clear
end
setup :clear_plugins
teardown :restore_plugins
test 'render of extended plugin template' do
Foreman::Plugin.register :test_extend_rabl_template do

Also available in: Unified diff