Skip to content

Commit

Permalink
Refs #22285 - Fix host instegration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrisker committed Jan 24, 2018
1 parent 673a8f0 commit b713bec
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 39 deletions.
3 changes: 2 additions & 1 deletion app/controllers/hosts_controller.rb
Expand Up @@ -175,8 +175,9 @@ def interfaces
end

def current_parameters
host = refresh_host
Taxonomy.as_taxonomy @organization, @location do
render :partial => "common_parameters/inherited_parameters", :locals => {:inherited_parameters => refresh_host.inherited_params_hash, :parameters => refresh_host.host_parameters}
render :partial => "common_parameters/inherited_parameters", :locals => {:inherited_parameters => host.inherited_params_hash, :parameters => host.host_parameters}
end
end

Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Expand Up @@ -142,7 +142,7 @@ class Application < Rails::Application
config.action_controller.always_permitted_parameters = %w(
controller action format locale utf8 _method authenticity_token commit redirect
page per_page paginate search order sort sort_by sort_order
_ie_support fakepassword apiv id organization_id location_id user_id
_ _ie_support fakepassword apiv id organization_id location_id user_id
)

# Use SQL instead of Active Record's schema dumper when creating the database.
Expand Down
37 changes: 37 additions & 0 deletions test/integration/host_js_test.rb
Expand Up @@ -321,6 +321,43 @@ class HostJSTest < IntegrationTestWithJavascript
assert_equal env1.name, host.environment.name
end

test 'user without edit_params permission can save host with params' do
host = FactoryBot.create(:host, :with_puppetclass)
FactoryBot.create(:puppetclass_lookup_key, :as_smart_class_param,
:with_override, :key_type => 'string',
:default_value => 'string1', :path => "fqdn\ncomment",
:puppetclass => host.puppetclasses.first,
:overrides => { host.lookup_value_matcher => 'string2' })
user = FactoryBot.create(:user, :with_mail)
user.update_attribute(:roles, roles(:viewer, :edit_hosts))
refute user.can? 'edit_params'
set_request_user(user)
visit edit_host_path(host)
assert page.has_link?('Parameters', :href => '#params')
click_link 'Parameters'
assert class_params.find('textarea').disabled?
assert_equal 2, class_params.all('input:disabled', :visible => :all).count
assert_equal 0, class_params.all('input\:not[disabled]', :visible => :all).count
click_button('Submit')
assert page.has_link?('Edit')
end

test 'shows errors on invalid lookup values' do
host = FactoryBot.create(:host, :with_puppetclass)
lookup_key = FactoryBot.create(:puppetclass_lookup_key, :as_smart_class_param, :with_override,
:key_type => 'real', :default_value => true, :path => "fqdn\ncomment",
:puppetclass => host.puppetclasses.first, :overrides => {host.lookup_value_matcher => false})

visit edit_host_path(host)
assert page.has_link?('Parameters', :href => '#params')
click_link 'Parameters'
assert page.has_no_selector?('#params td.has-error')

fill_in "host_lookup_values_attributes_#{lookup_key.id}_value", :with => 'invalid'
click_button('Submit')
assert page.has_selector?('#params td.has-error')
end

test 'choosing a hostgroup does not override other host attributes' do
original_hostgroup = FactoryBot.
create(:hostgroup, :environment => FactoryBot.create(:environment),
Expand Down
37 changes: 0 additions & 37 deletions test/integration/host_test.rb
Expand Up @@ -71,43 +71,6 @@ class HostIntegrationTest < ActionDispatch::IntegrationTest
click_link 'Parameters'
assert_equal class_params.find("textarea").value, "a: c\n"
end

test 'user without edit_params permission can save host with params' do
host = FactoryBot.create(:host, :with_puppetclass)
FactoryBot.create(:puppetclass_lookup_key, :as_smart_class_param,
:with_override, :key_type => 'string',
:default_value => 'string1', :path => "fqdn\ncomment",
:puppetclass => host.puppetclasses.first,
:overrides => { host.lookup_value_matcher => 'string2' })
user = FactoryBot.create(:user, :with_mail)
user.update_attribute(:roles, roles(:viewer, :edit_hosts))
refute user.can? 'edit_params'
set_request_user(user)
visit edit_host_path(host)
assert page.has_link?('Parameters', :href => '#params')
click_link 'Parameters'
assert class_params.find('textarea').disabled?
assert_equal 2, class_params.all('input:disabled', :visible => :all).count
assert_equal 0, class_params.all('input:not[disabled]', :visible => :all).count
click_button('Submit')
assert page.has_link?('Edit')
end

test 'shows errors on invalid lookup values' do
host = FactoryBot.create(:host, :with_puppetclass)
lookup_key = FactoryBot.create(:puppetclass_lookup_key, :as_smart_class_param, :with_override,
:key_type => 'real', :default_value => true, :path => "fqdn\ncomment",
:puppetclass => host.puppetclasses.first, :overrides => {host.lookup_value_matcher => false})

visit edit_host_path(host)
assert page.has_link?('Parameters', :href => '#params')
click_link 'Parameters'
assert page.has_no_selector?('#params td.has-error')

fill_in "host_lookup_values_attributes_#{lookup_key.id}_value", :with => 'invalid'
click_button('Submit')
assert page.has_selector?('#params td.has-error')
end
end

describe 'clone page' do
Expand Down

0 comments on commit b713bec

Please sign in to comment.