Project

General

Profile

« Previous | Next » 

Revision 630061d2

Added by Michael Moll almost 6 years ago

Fixes #19775 - Fix Layout/ExtraSpacing cop

View differences:

.rubocop_todo.yml
Layout/ClosingParenthesisIndentation:
Enabled: false
# Offense count: 55
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Enabled: false
# Offense count: 30
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
app/controllers/api/v2/hostgroups_controller.rb
param :domain_id, :number, :desc => N_('Domain ID')
param :realm_id, :number, :desc => N_('Realm ID')
param :config_group_ids, Array, :desc => N_("IDs of associated config groups")
param :group_parameters_attributes, Array, :required => false, :desc => N_("Array of parameters") do
param :group_parameters_attributes, Array, :required => false, :desc => N_("Array of parameters") do
param :name, String, :desc => N_("Name of the parameter"), :required => true
param :value, String, :desc => N_("Parameter value"), :required => true
end
app/controllers/api/v2/operatingsystems_controller.rb
param :ptable_id, String, :desc => N_("ID of partition table")
param :config_template_id, String, :desc => N_("ID of template")
param :provisioning_template_id, String, :desc => N_("ID of template")
param :os_parameters_attributes, Array, :required => false, :desc => N_("Array of parameters") do
param :os_parameters_attributes, Array, :required => false, :desc => N_("Array of parameters") do
param :name, String, :desc => N_("Name of the parameter"), :required => true
param :value, String, :desc => N_("Parameter value"), :required => true
end
app/controllers/api/v2/trends_controller.rb
end
api :POST, "/trends/", N_("Create a trend counter")
param :trendable_type, String, :required => true
param :trendable_type, String, :required => true
param :fact_name, String, :required => false
param :name, String, :required => false
def create
app/controllers/hosts_controller.rb
def cancelBuild
if @host.built(false)
process_success :success_msg => _("Canceled pending build for %s") % @host.name, :success_redirect => :back
process_success :success_msg => _("Canceled pending build for %s") % @host.name, :success_redirect => :back
else
process_error :redirect => :back, :error_msg => _("Failed to cancel pending build for %{hostname} with the following errors: %{errors}") % {:hostname => @host.name, :errors => @host.errors.full_messages.join(', ')}
end
app/helpers/application_helper.rb
update_url = options[:update_url] || url_for(object)
type = options[:type]
title = options[:title]
select_values = [true, false].include?(value) ? [_('Yes'), _('No')] : options[:select_values]
select_values = [true, false].include?(value) ? [_('Yes'), _('No')] : options[:select_values]
editable(object, property, {:type => type, :title => title, :value => value, :class => klass, :source => select_values, :url => update_url}.compact)
end
......
end
def toast_notifiations_data
selected_toast_notifiations = flash.select { |key, _| key != 'inline' }
selected_toast_notifiations = flash.select { |key, _| key != 'inline' }
selected_toast_notifiations.map do |type, notification|
notification.is_a?(Hash) ? notification : { :type => type, :message => notification }
app/helpers/home_helper.rb
authorized_menu_actions(Menu::Manager.items(menu_name).children).map do |menu|
items = authorized_menu_actions(menu.children)
render "home/vertical_menu", :menu_items => items, :menu_title => _(menu.caption), :menu_icon => menu.icon,
:menu_name => menu.name, :mobile_class => mobile ? 'visible-xs-block' : '' if items.any?
:menu_name => menu.name, :mobile_class => mobile ? 'visible-xs-block' : '' if items.any?
end.join(' ').html_safe
end
app/helpers/hosts_and_hostgroups_helper.rb
:disable_button_enabled => override && !explicit_value?(:realm_id),
:user_set => user_set?(:realm_id)
},
{ :help_inline => :indicator }
{ :help_inline => :indicator }
).html_safe
end
app/helpers/reports_helper.rb
choices += (1..7).map{|i| OpenStruct.new :name => n_("%s day ago", "%s days ago", i) % i, :value => i.days.ago }
choices += (1..3).map{|i| OpenStruct.new :name => n_("%s week ago", "%s weeks ago", i) % i, :value => i.week.ago }
choices += (1..3).map{|i| OpenStruct.new :name => n_("%s month ago", "%s months ago", i) % i, :value => i.month.ago }
choices += [OpenStruct.new(:name => _("All Reports"), :value => Report.first(:select => "created_at").created_at)]
choices += [OpenStruct.new(:name => _("All Reports"), :value => Report.first(:select => "created_at").created_at)]
builder.collection_select :reported_at_gt, choices, :value, :name, {:include_blank => _("Select a period")}
end
app/models/compute_resources/foreman/model/libvirt.rb
# Listen address cannot be updated while the guest is running
# When we update the display password, we pass the existing listen address
vm.update_display(:password => password, :listen => vm.display[:listen], :type => vm.display[:type])
WsProxy.start(:host => hypervisor.hostname, :host_port => vm.display[:port], :password => password).merge(:type => vm.display[:type], :name=> vm.name)
WsProxy.start(:host => hypervisor.hostname, :host_port => vm.display[:port], :password => password).merge(:type => vm.display[:type], :name=> vm.name)
rescue ::Libvirt::Error => e
if e.message =~ /cannot change listen address/
logger.warn e
app/models/compute_resources/foreman/model/openstack.rb
def tenants
if url =~ /\/v3\/auth\/tokens/
user_id = identity_client.current_user_id
user_id = identity_client.current_user_id
identity_client.list_user_projects(user_id).body["projects"].map { |p| Fog::Identity::OpenStack::V3::Project.new(p) }
else
client.tenants
app/models/concerns/hostext/search.rb
end
if SETTINGS[:login]
scoped_search :relation => :search_users, :on => :login, :complete_value => true, :only_explicit => true, :rename => :'user.login', :operators => ['= ', '~ '], :ext_method => :search_by_user, :aliases => [:owner]
scoped_search :relation => :search_users, :on => :login, :complete_value => true, :only_explicit => true, :rename => :'user.login', :operators => ['= ', '~ '], :ext_method => :search_by_user, :aliases => [:owner]
scoped_search :relation => :search_users, :on => :firstname, :complete_value => true, :only_explicit => true, :rename => :'user.firstname', :operators => ['= ', '~ '], :ext_method => :search_by_user
scoped_search :relation => :search_users, :on => :lastname, :complete_value => true, :only_explicit => true, :rename => :'user.lastname', :operators => ['= ', '~ '], :ext_method => :search_by_user
scoped_search :relation => :search_users, :on => :mail, :complete_value => true, :only_explicit => true, :rename => :'user.mail', :operators => ['= ', '~ '], :ext_method => :search_by_user
......
def search_by_hostgroup_and_descendants(key, operator, value)
conditions = sanitize_sql_for_conditions(["hostgroups.title #{operator} ?", value_to_sql(operator, value)])
# Only one hostgroup (first) is used to determined descendants. Future TODO - alert if result results more than one hostgroup
hostgroup = Hostgroup.unscoped.with_taxonomy_scope.find_by(conditions)
hostgroup = Hostgroup.unscoped.with_taxonomy_scope.find_by(conditions)
if hostgroup.present?
hostgroup_ids = hostgroup.subtree_ids
opts = "hosts.hostgroup_id IN (#{hostgroup_ids.join(',')})"
app/models/host/base.rb
alias_attribute :hostname, :name
validates :name, :presence => true, :uniqueness => true, :format => {:with => Net::Validations::HOST_REGEXP, :message => _(Net::Validations::HOST_REGEXP_ERR_MSG)}
validates :name, :presence => true, :uniqueness => true, :format => {:with => Net::Validations::HOST_REGEXP, :message => _(Net::Validations::HOST_REGEXP_ERR_MSG)}
validate :host_has_required_interfaces
validate :uniq_interfaces_identifiers
validate :build_managed_only
app/models/nic/base.rb
def clone
# do not copy system specific attributes
self.deep_clone(:except => [:name, :mac, :ip, :ip6, :host_id])
self.deep_clone(:except => [:name, :mac, :ip, :ip6, :host_id])
end
# if this interface does not have MAC and is attached to other interface,
app/models/setting/provisioning.rb
def self.default_global_templates
map_pxe_kind do |pxe_kind, templates|
self.set("global_#{pxe_kind}", N_("Global default %s template. This template gets deployed to all configured TFTP servers. It will not be affected by upgrades.") % pxe_kind, ProvisioningTemplate.global_default_name(pxe_kind), N_("Global default %s template") % pxe_kind, nil, { :collection => templates })
self.set("global_#{pxe_kind}", N_("Global default %s template. This template gets deployed to all configured TFTP servers. It will not be affected by upgrades.") % pxe_kind, ProvisioningTemplate.global_default_name(pxe_kind), N_("Global default %s template") % pxe_kind, nil, { :collection => templates })
end
end
app/models/trends/fact_trend.rb
class FactTrend < Trend
validates :trendable_id, :presence => true, :uniqueness => {:scope => [:trendable_type, :fact_value] }, :allow_blank => false
validates :trendable_id, :presence => true, :uniqueness => {:scope => [:trendable_type, :fact_value] }, :allow_blank => false
before_save :update_fact_name
config.ru
require 'rack'
# load Rails environment
require ::File.expand_path('../config/environment', __FILE__)
require ::File.expand_path('../config/environment', __FILE__)
# apply a prefix to the application, if one is defined
# e.g. http://some.server.com/prefix where '/prefix' is defined by env variable
map ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do
map ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do
run Foreman::Application
end
db/migrate/20180403144853_convert_vm_attrs_to_hash.rb
YML_PARAMS = /!ruby\/[\w-]+:ActionController::Parameters/
def transform_batch_columns(base, serialized_columns)
base.unscoped.select(serialized_columns + [:id]).find_each do |object|
base.unscoped.select(serialized_columns + [:id]).find_each do |object|
serialized_columns.each do |column|
attributes = object.send :read_attribute_before_type_cast, column
next if attributes.nil?
......
class FakeLookupKey < ApplicationRecord
self.table_name = 'lookup_keys'
self.inheritance_column = nil
self.inheritance_column = nil
end
end
lib/foreman/foreman_url_renderer.rb
# returns the URL for Foreman based on the required action
def foreman_url(action = 'provision')
# Get basic stuff
config = URI.parse(Setting[:unattended_url])
config = URI.parse(Setting[:unattended_url])
url_options = foreman_url_options_from_settings_or_request(config)
host = @host
lib/tasks/jenkins.rake
end
minitest_plugins = [:pre_ci, 'webpack:try_compile', 'ci:setup:minitest']
minitest_plugins << 'robottelo:setup:minitest' if ENV['GENERATE_ROBOTTELO_REPORT'] == 'true'
task :minitest => minitest_plugins
task :minitest => minitest_plugins
end
task :rubocop do
lib/tasks/plugin_apipie.rake
plugin = Foreman::Plugin.find(args[:engine])
Apipie.configuration.ignored = plugin.apipie_ignored_controllers || []
api_controllers = plugin.apipie_documented_controllers || ["#{@engine_root}/app/controllers/#{path_name}/api/*.rb"]
api_controllers = plugin.apipie_documented_controllers || ["#{@engine_root}/app/controllers/#{path_name}/api/*.rb"]
Apipie.configuration.api_controllers_matcher = api_controllers
Rake::Task['apipie:cache'].execute
lib/tasks/puppet.rake
namespace :import do
desc "
Update puppet environments and classes. Optional batch flag triggers run with no prompting\nUse proxy=<proxy name> to import from or get the first one by default"
task :puppet_classes, [:batch, :envname] => :environment do |t, args|
task :puppet_classes, [:batch, :envname] => :environment do |t, args|
User.as_anonymous_admin do
args.batch = args.batch == "true"
proxies = SmartProxy.with_features("Puppet")
lib/tasks/reports.rake
end
end
task :daily => :environment do
task :daily => :environment do
process_notifications :daily
end
test/controllers/api/v2/auth_sources_controller_test.rb
assert_response :success
auth_sources = ActiveSupport::JSON.decode(@response.body)
refute_empty auth_sources
ids = auth_sources['results'].map { |hash| hash['id'] }
ids = auth_sources['results'].map { |hash| hash['id'] }
assert_includes ids, auth_sources(:internal).id
assert_includes ids, auth_sources(:external).id
assert_includes ids, auth_sources(:one).id
test/controllers/api/v2/interfaces_controller_test.rb
def setup
@host = FactoryBot.create(:host)
@nic = FactoryBot.create(:nic_managed, :host => @host)
@bond = FactoryBot.create(:nic_bond, :host => @host)
@bond = FactoryBot.create(:nic_bond, :host => @host)
end
test "get index for specific host" do
test/controllers/api/v2/locations_controller_test.rb
test "should create location with parent" do
parent_id = Location.first.id
post :create, params: { :location => { :name => "Test Location", :parent_id => parent_id } }
post :create, params: { :location => { :name => "Test Location", :parent_id => parent_id } }
assert_response :success
show_response = ActiveSupport::JSON.decode(@response.body)
assert !show_response.empty?
test/controllers/api/v2/operatingsystems_controller_test.rb
test "should create os with name and major version only" do
os_params = minimum_required_os_params
assert_difference('Operatingsystem.count') do
post :create, params: { :operatingsystem => os_params}
post :create, params: { :operatingsystem => os_params}
end
assert_response :created
response = JSON.parse(@response.body)
test/controllers/api/v2/organizations_controller_test.rb
test "search organization" do
organization = Organization.first
get :index, params: { :search => "name = \"#{organization.name}\"", :format => 'json' }
get :index, params: { :search => "name = \"#{organization.name}\"", :format => 'json' }
assert_response :success, "search organization name: '#{organization.name}' failed with code: #{@response.code}"
response = JSON.parse(@response.body)
assert_equal response['results'].length, 1
test/controllers/api/v2/override_values_controller_test.rb
lookup_key = FactoryBot.create(:variable_lookup_key, :puppetclass => puppetclasses(:two))
refute lookup_key.override
assert_difference('LookupValue.count', 1) do
post :create, params: { :smart_variable_id => lookup_key.id, :override_value => { :match => 'os=string'} }
post :create, params: { :smart_variable_id => lookup_key.id, :override_value => { :match => 'os=string'} }
end
assert_response :success
end
......
test_attributes :pid => 'bef0e457-16be-4ca6-bc56-fa32dff55a01'
test "should not create invalid matcher for non existing attribute" do
assert_difference('LookupValue.count', 0) do
post :create, params: { :smart_class_parameter_id => lookup_keys(:one).id, :override_value => { :match => 'hostgroup=nonexistingHG', :value => RFauxFactory.gen_alpha } }
post :create, params: { :smart_class_parameter_id => lookup_keys(:one).id, :override_value => { :match => 'hostgroup=nonexistingHG', :value => RFauxFactory.gen_alpha } }
end
assert_includes JSON.parse(response.body)['error']['message'], 'Validation failed: Match hostgroup=nonexistingHG does not match an existing host group'
end
test/controllers/api/v2/ptables_controller_test.rb
test_attributes :pid => '08520746-444b-47c9-a8a3-438170147453'
test "search ptable" do
get :index, params: { :search => @ptable.name, :format => 'json' }
get :index, params: { :search => @ptable.name, :format => 'json' }
assert_response :success, "search ptable name: '#{@ptable.name}' failed with code: #{@response.code}"
response = JSON.parse(@response.body)
assert_equal response['results'].length, 1
......
org = Organization.first
@ptable.organizations = [org]
assert @ptable.save
get :index, params: {:search => @ptable.name, :organization_id => org.id, :format => 'json' }
get :index, params: {:search => @ptable.name, :organization_id => org.id, :format => 'json' }
assert_response :success, "search ptable by name and organization failed with code: #{@response.code}"
response = JSON.parse(@response.body)
assert_equal response['results'].length, 1
test/controllers/api/v2/smart_proxies_controller_test.rb
put :update, params: { :id => smart_proxies(:one).to_param, :smart_proxy => valid_attrs }
assert_response :success
response = JSON.parse(@response.body)
refute_empty response.keys.select { |key| any_needed_fields.include?(key) }
refute_empty response.keys.select { |key| any_needed_fields.include?(key) }
end
test_attributes :pid => '42d6b749-c047-4fd2-90ee-ffab7be558f9'
......
put :update, params: { :id => smart_proxies(:one).to_param, :smart_proxy => valid_attrs }
assert_response :success
response = JSON.parse(@response.body)
refute_empty response.keys.select { |key| any_needed_fields.include?(key) }
refute_empty response.keys.select { |key| any_needed_fields.include?(key) }
end
test_attributes :pid => 'f279640e-d7e9-48a3-aed8-7bf406e9d6f2'
test/controllers/environments_controller_test.rb
post :obsolete_and_new, params:
{ "changed"=>
{"obsolete" =>
{"env1" => '["a","b","c","_destroy_"]'}
{"env1" => '["a","b","c","_destroy_"]'}
}
}, session: set_session_user
assert Environment.unscoped.find_by_name("env1").hosts.count > 0
test/controllers/hostgroups_controller_test.rb
end
test 'should not escape lookup values on environment change' do
hostgroup = FactoryBot.create(:hostgroup, :environment => @environment, :puppetclass_ids => [@puppetclass.id])
hostgroup = FactoryBot.create(:hostgroup, :environment => @environment, :puppetclass_ids => [@puppetclass.id])
lookup_key = FactoryBot.create(:puppetclass_lookup_key, :as_smart_class_param, :key_type => 'array',
:default_value => ['a', 'b'], :override => true, :puppetclass => @puppetclass)
lookup_value = FactoryBot.create(:lookup_value, :lookup_key => lookup_key, :match => "hostgroup=#{hostgroup.name}", :value => ["c", "d"])
......
FactoryBot.create(:environment_class, :puppetclass => @puppetclass, :environment => @environment, :puppetclass_lookup_key => lookup_key)
# sending exactly what the host form would send which is lookup_value.value_before_type_cast
lk = {"lookup_values_attributes" => {lookup_key.id.to_s => {"value" => lookup_value.value_before_type_cast, "id" =>lookup_value.id, "lookup_key_id" => lookup_key.id, "_destroy" => false}}}
lk = {"lookup_values_attributes" => {lookup_key.id.to_s => {"value" => lookup_value.value_before_type_cast, "id" =>lookup_value.id, "lookup_key_id" => lookup_key.id, "_destroy" => false}}}
params = {
hostgroup_id: hostgroup.id,
test/controllers/hosts_controller_test.rb
end
hostgroup = hostgroups(:common)
post :update_multiple_hostgroup, params: { :host_names => host_names, :hostgroup => { :id => hostgroup.id} }, session: set_session_user
post :update_multiple_hostgroup, params: { :host_names => host_names, :hostgroup => { :id => hostgroup.id} }, session: set_session_user
assert_response :redirect
host_names.each do |name|
......
lookup_value = FactoryBot.create(:lookup_value, :lookup_key => lookup_key, :match => "fqdn=#{host.fqdn}", :value => ["c", "d"])
# sending exactly what the host form would send which is lookup_value.value_before_type_cast
lk = {"lookup_values_attributes" => {lookup_key.id.to_s => {"value" => lookup_value.value_before_type_cast, "id" =>lookup_value.id, "lookup_key_id" => lookup_key.id, "_destroy" => false}}}
lk = {"lookup_values_attributes" => {lookup_key.id.to_s => {"value" => lookup_value.value_before_type_cast, "id" =>lookup_value.id, "lookup_key_id" => lookup_key.id, "_destroy" => false}}}
params = {
host_id: host.id,
test/controllers/shared/basic_rest_response_test.rb
next if @controller.resource_name == "trend"
@request.env['HTTP_REFERER'] = root_url
get :index, params: {search: "name='A98$bcD#67Ef*g"}, session: set_session_user
assert (@response.body.include? "No entries found") || @response.body.match(/You are being.*redirected/)
assert (@response.body.include? "No entries found") || @response.body.match(/You are being.*redirected/)
end
teardown do
test/controllers/ssh_keys_controller_test.rb
class SshKeysControllerTest < ActionController::TestCase
let(:key) { 'ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIhRoL6PfBRs9YwW3r2/pYeLrxRzEZSUO3Go8JivxMsguEKjJ3byHDPvPpMHhKKSZD/HJY/A+2Ndqp0ElB+t2qs= foreman@example.com' }
let(:ssh_key) { FactoryBot.create(:ssh_key) }
let(:ssh_key) { FactoryBot.create(:ssh_key) }
let(:user) { ssh_key.user }
test 'new' do
test/mailers/application_mailer_test.rb
class TestMailer < ::ApplicationMailer
def test(to, subject)
mail(:to => to, :subject => subject) do |format|
format.html { render :plain => html_mail }
format.html { render :plain => html_mail }
end
end
test/models/lookup_value_test.rb
end
test "should create override value for smart variable with list validator and matching value" do
values_list = [ 'test', 'example', 30 ]
values_list = [ 'test', 'example', 30 ]
validator_type = 'list'
validator_rule = values_list.join(', ')
smart_variable = FactoryBot.create(
test/models/organization_test.rb
test "update with multi names" do
organization = FactoryBot.create(:organization)
valid_org_name_list.each do |new_name|
organization.name = new_name
organization.name = new_name
assert organization.valid?, "Validation failed for update with valid name: '#{new_name}' length: #{new_name.length})"
assert_equal organization.name, new_name
end
test/models/template_test.rb
template = Minitest::Mock.new
template.expect(:ignore_locking, true)
Template.expects(:import_without_save => template)
Template.import!('test', '', { :force => true })
Template.import!('test', '', { :force => true })
template.verify
end
end
test/models/user_test.rb
class UserTest < ActiveSupport::TestCase
def setup
User.current = users :admin
@user = User.create :auth_source => auth_sources(:one), :login => "foo", :mail => "foo@bar.com"
@user = User.create :auth_source => auth_sources(:one), :login => "foo", :mail => "foo@bar.com"
end
# Presence
......
end
test "user should login case insensitively" do
user = User.new :auth_source => auth_sources(:internal), :login => "user", :mail => "foo1@bar.com", :password => "foo"
user = User.new :auth_source => auth_sources(:internal), :login => "user", :mail => "foo1@bar.com", :password => "foo"
assert user.save!
assert_equal user, User.try_to_login("USER", "foo")
end
test "user login should be case aware" do
user = User.new :auth_source => auth_sources(:one), :login => "User", :mail => "foo1@bar.com", :password => "foo"
user = User.new :auth_source => auth_sources(:one), :login => "User", :mail => "foo1@bar.com", :password => "foo"
assert user.save
assert_equal user.login, "User"
assert_equal user.lower_login, "user"
......
test "new internal user gets welcome mail" do
ActionMailer::Base.deliveries = []
Setting[:send_welcome_email] = true
User.create :auth_source => auth_sources(:internal), :login => "welcome", :mail => "foo@example.com", :password => "qux", :mail_enabled => true
User.create :auth_source => auth_sources(:internal), :login => "welcome", :mail => "foo@example.com", :password => "qux", :mail_enabled => true
mail = ActionMailer::Base.deliveries.detect { |delivery| delivery.subject =~ /Welcome to Foreman/ }
assert mail
assert_match /Username/, mail.body.encoded
......
test "other auth sources don't get welcome mail" do
Setting[:send_welcome_email] = true
assert_no_difference "ActionMailer::Base.deliveries.size" do
User.create :auth_source => auth_sources(:one), :login => "welcome", :mail => "foo@bar.com", :password => "qux"
User.create :auth_source => auth_sources(:one), :login => "welcome", :mail => "foo@bar.com", :password => "qux"
end
end
test/unit/menu_mapper_test.rb
test 'deleting all items' do
# Exposed by deleting :last items
Menu::Manager.map :test_menu do |menu|
menu.item :not_last, :url_hash=> { :controller => 'hosts', :action => 'index'}
menu.item :not_last, :url_hash=> { :controller => 'hosts', :action => 'index'}
menu.item :administration, :url_hash=> { :controller => 'hosts', :action => 'show'}, :last => true
menu.item :help, :url_hash => { :controller => 'help', :action => 'show'}, :last => true
end

Also available in: Unified diff