commit d7c6774617b7dbefe81c3ac9984803d52c67ce17
Author: Michael Moll <kvedulv@kvedulv.de>
Date:   Wed Jun 20 09:20:30 2018 +0200

    Fixes #19873 - Fix Style/MultilineIfModifier cop (#5705)
    
    * Refs #20891 - fix for new rubocop rules
    
    * Fixes #19873 - Fix Style/MultilineIfModifier cop

diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index d1280a24c..9190917e8 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -439,11 +439,6 @@ Style/MethodCallWithoutArgsParentheses:
 Style/MixinUsage:
   Enabled: false
 
-# Offense count: 37
-# Cop supports --auto-correct.
-Style/MultilineIfModifier:
-  Enabled: false
-
 # Offense count: 3
 Style/MultipleComparison:
   Enabled: false
diff --git a/app/controllers/operatingsystems_controller.rb b/app/controllers/operatingsystems_controller.rb
index 9e339fef2..3c0a760e5 100644
--- a/app/controllers/operatingsystems_controller.rb
+++ b/app/controllers/operatingsystems_controller.rb
@@ -23,11 +23,13 @@ class OperatingsystemsController < ApplicationController
 
   def edit
     # Generates default OS template entries
-    @operatingsystem.provisioning_templates.map(&:template_kind_id).uniq.each do |kind|
-      if @operatingsystem.os_default_templates.where(:template_kind_id => kind).blank?
-        @operatingsystem.os_default_templates.build(:template_kind_id => kind)
+    if SETTINGS[:unattended]
+      @operatingsystem.provisioning_templates.map(&:template_kind_id).uniq.each do |kind|
+        if @operatingsystem.os_default_templates.where(:template_kind_id => kind).blank?
+          @operatingsystem.os_default_templates.build(:template_kind_id => kind)
+        end
       end
-    end if SETTINGS[:unattended]
+    end
   end
 
   def update
diff --git a/app/helpers/audits_helper.rb b/app/helpers/audits_helper.rb
index 7f20d48c4..cc05ae119 100644
--- a/app/helpers/audits_helper.rb
+++ b/app/helpers/audits_helper.rb
@@ -133,16 +133,18 @@ module AuditsHelper
 
   def audited_icon(audit)
     style = 'label-info'
-    style = case audit.action
-              when 'create'
-                'label-success'
-              when 'update'
-                'label-info'
-              when 'destroy'
-                'label-danger'
-              else
-                ''
-            end if main_object? audit
+    if main_object? audit
+      style = case audit.action
+                when 'create'
+                  'label-success'
+                when 'update'
+                  'label-info'
+                when 'destroy'
+                  'label-danger'
+                else
+                  ''
+              end
+    end
     style += " label"
 
     type   = audited_type(audit)
diff --git a/app/helpers/compute_resources_vms_helper.rb b/app/helpers/compute_resources_vms_helper.rb
index 8dec406c1..e0b7fb97e 100644
--- a/app/helpers/compute_resources_vms_helper.rb
+++ b/app/helpers/compute_resources_vms_helper.rb
@@ -53,12 +53,14 @@ module ComputeResourcesVmsHelper
       :port     => console[:proxy_port],
       :password => console[:password]
     }
-    options.merge!(
-      :address     => console[:address],
-      :secure_port => console[:secure_port],
-      :subject     => console[:subject],
-      :title       => _("%s - Press Shift-F12 to release the cursor.") % console[:name]
-    ) if supports_spice_xpi?
+    if supports_spice_xpi?
+      options.merge!(
+        :address     => console[:address],
+        :secure_port => console[:secure_port],
+        :subject     => console[:subject],
+        :title       => _("%s - Press Shift-F12 to release the cursor.") % console[:name]
+      )
+    end
     options[:ca_cert] = URI.escape(console[:ca_cert]) if console[:ca_cert].present?
     options
   end
diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb
index 9b2b57dfb..a76a66f51 100644
--- a/app/helpers/home_helper.rb
+++ b/app/helpers/home_helper.rb
@@ -2,8 +2,10 @@ module HomeHelper
   def render_vertical_menu(menu_name, mobile = false)
     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?
+      if items.any?
+        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' : ''
+      end
     end.join(' ').html_safe
   end
 
diff --git a/app/helpers/hosts_helper.rb b/app/helpers/hosts_helper.rb
index 5b1420a23..e9f13d0ea 100644
--- a/app/helpers/hosts_helper.rb
+++ b/app/helpers/hosts_helper.rb
@@ -499,8 +499,10 @@ module HostsHelper
   end
 
   def randomize_mac_link
-    link_to_function(icon_text('random'), 'randomizeName()', :class => 'btn btn-default',
-      :title => _('Generate new random name. Visit Settings to disable this feature.')) if NameGenerator.random_based?
+    if NameGenerator.random_based?
+      link_to_function(icon_text('random'), 'randomizeName()', :class => 'btn btn-default',
+        :title => _('Generate new random name. Visit Settings to disable this feature.'))
+    end
   end
 
   def power_status_visible?
diff --git a/app/helpers/lookup_keys_helper.rb b/app/helpers/lookup_keys_helper.rb
index f2e1a7d52..a9430736e 100644
--- a/app/helpers/lookup_keys_helper.rb
+++ b/app/helpers/lookup_keys_helper.rb
@@ -18,15 +18,17 @@ module LookupKeysHelper
   def show_puppet_class(f)
     # In case of a new smart-var inside a puppetclass (REST nesting only), or a class parameter:
     # Show the parent puppetclass as a context, but permit no change.
-    if params["puppetclass_id"]
-      select_f f, :puppetclass_id, [Puppetclass.find(params["puppetclass_id"])], :id, :to_label, {}, {:label => _("Puppet class"), :disabled => true}
-    elsif f.object.puppet? && f.object.param_class
-      text_f(f, :puppetclass_id, :label => _('Puppet Class'), :value => f.object.param_class, :disabled => true)
-    else # new smart-var with no particular context
-      # Give a select for choosing the parent puppetclass
-      puppetclasses = accessible_resource(f.object, :puppetclass)
-      select_f(f, :puppetclass_id, puppetclasses, :id, :to_label, { :include_blank => true }, {:label => _("Puppet class")})
-    end unless @puppetclass # nested smart-vars form in a tab of puppetclass/_form: no edition allowed, and the puppetclass is already visible as a context
+    unless @puppetclass
+      if params["puppetclass_id"]
+        select_f f, :puppetclass_id, [Puppetclass.find(params["puppetclass_id"])], :id, :to_label, {}, {:label => _("Puppet class"), :disabled => true}
+      elsif f.object.puppet? && f.object.param_class
+        text_f(f, :puppetclass_id, :label => _('Puppet Class'), :value => f.object.param_class, :disabled => true)
+      else # new smart-var with no particular context
+        # Give a select for choosing the parent puppetclass
+        puppetclasses = accessible_resource(f.object, :puppetclass)
+        select_f(f, :puppetclass_id, puppetclasses, :id, :to_label, { :include_blank => true }, {:label => _("Puppet class")})
+      end
+    end # nested smart-vars form in a tab of puppetclass/_form: no edition allowed, and the puppetclass is already visible as a context
   end
 
   def param_type_selector(f, options = {})
diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb
index 88ea98044..f484cacde 100644
--- a/app/helpers/settings_helper.rb
+++ b/app/helpers/settings_helper.rb
@@ -1,10 +1,14 @@
 module SettingsHelper
   def value(setting)
-    return readonly_field(setting, :value,
-      {:title => _("This setting is defined in the configuration file '%{filename}' and is read-only.") % {:filename => setting.class.config_file}, :helper => :show_value}) if setting.readonly?
+    if setting.readonly?
+      return readonly_field(setting, :value,
+        {:title => _("This setting is defined in the configuration file '%{filename}' and is read-only.") % {:filename => setting.class.config_file}, :helper => :show_value})
+    end
 
-    return edit_select(setting, :value,
-      {:title => setting.full_name_with_default, :select_values => self.send("#{setting.name}_collection") }) if self.respond_to? "#{setting.name}_collection"
+    if self.respond_to? "#{setting.name}_collection"
+      return edit_select(setting, :value,
+        {:title => setting.full_name_with_default, :select_values => self.send("#{setting.name}_collection") })
+    end
 
     return edit_textarea(setting, :value, {:title => setting.full_name_with_default, :helper => :show_value}) if setting.settings_type == 'array'
     edit_textfield(setting, :value, {:title => setting.full_name_with_default, :helper => :show_value})
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index e068351de..631a66cac 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -19,10 +19,12 @@ module UsersHelper
   end
 
   def user_taxonomies_html_options(user)
-    {
-      :location     => { :onchange => 'tfm.users.taxonomyAdded(this, "location")'},
-      :organization => { :onchange => 'tfm.users.taxonomyAdded(this, "organization")'}
-    } unless user.admin?
+    unless user.admin?
+      {
+        :location     => { :onchange => 'tfm.users.taxonomyAdded(this, "location")'},
+        :organization => { :onchange => 'tfm.users.taxonomyAdded(this, "organization")'}
+      }
+    end
   end
 
   def mail_notification_query_builder(mail_notification, f)
diff --git a/app/models/compute_resources/foreman/model/openstack.rb b/app/models/compute_resources/foreman/model/openstack.rb
index dd36e8eac..a916c79b0 100644
--- a/app/models/compute_resources/foreman/model/openstack.rb
+++ b/app/models/compute_resources/foreman/model/openstack.rb
@@ -242,8 +242,10 @@ module Foreman::Model
         :openstack_user_domain       => domain,
         :openstack_endpoint_type     => "publicURL"
       }.tap do |h|
-        h.merge!(:openstack_domain_name  => domain,
-                 :openstack_project_name => tenant) if tenant
+        if tenant
+          h.merge!(:openstack_domain_name  => domain,
+                   :openstack_project_name => tenant)
+        end
       end
     end
 
diff --git a/app/models/concerns/has_many_common.rb b/app/models/concerns/has_many_common.rb
index 39e20d6db..e0161d005 100644
--- a/app/models/concerns/has_many_common.rb
+++ b/app/models/concerns/has_many_common.rb
@@ -83,8 +83,10 @@ module HasManyCommon
       # SETTER _name= method
       define_method "#{assoc_name}=" do |name_value|
         assoc_id = assoc_klass(association).send("find_by_#{assoc_klass(association).attribute_name}", name_value).try(:id)
-        raise Foreman::AssociationNotFound
-                .new(_("Could not find %{association} with name: %{name}") % { name: name_value, association: association }) unless assoc_id
+        unless assoc_id
+          raise Foreman::AssociationNotFound
+                  .new(_("Could not find %{association} with name: %{name}") % { name: name_value, association: association })
+        end
         self.send("#{assoc}_id=", assoc_id)
       end
 
diff --git a/app/models/concerns/orchestration/compute.rb b/app/models/concerns/orchestration/compute.rb
index 13dced2f9..582986dc9 100644
--- a/app/models/concerns/orchestration/compute.rb
+++ b/app/models/concerns/orchestration/compute.rb
@@ -43,18 +43,26 @@ module Orchestration::Compute
   end
 
   def queue_compute_create
-    queue.create(:name   => _("Render user data template for %s") % self, :priority => 1,
-                 :action => [self, :setUserData]) if find_image.try(:user_data)
+    if find_image.try(:user_data)
+      queue.create(:name   => _("Render user data template for %s") % self, :priority => 1,
+                   :action => [self, :setUserData])
+    end
     queue.create(:name   => _("Set up compute instance %s") % self, :priority => 2,
                  :action => [self, :setCompute])
-    queue.create(:name   => _("Acquire IP addresses for %s") % self, :priority => 3,
-                 :action => [self, :setComputeIP]) if compute_provides?(:ip) || compute_provides?(:ip6)
+    if compute_provides?(:ip) || compute_provides?(:ip6)
+      queue.create(:name   => _("Acquire IP addresses for %s") % self, :priority => 3,
+                   :action => [self, :setComputeIP])
+    end
     queue.create(:name   => _("Query instance details for %s") % self, :priority => 4,
                  :action => [self, :setComputeDetails])
-    queue.create(:name   => _("Set IP addresses for %s") % self, :priority => 5,
-                 :action => [self, :setComputeIPAM]) if compute_provides?(:mac) && (mac_based_ipam?(:subnet) || mac_based_ipam?(:subnet6))
-    queue.create(:name   => _("Power up compute instance %s") % self, :priority => 1000,
-                 :action => [self, :setComputePowerUp]) if compute_attributes && compute_attributes[:start] == '1'
+    if compute_provides?(:mac) && (mac_based_ipam?(:subnet) || mac_based_ipam?(:subnet6))
+      queue.create(:name   => _("Set IP addresses for %s") % self, :priority => 5,
+                   :action => [self, :setComputeIPAM])
+    end
+    if compute_attributes && compute_attributes[:start] == '1'
+      queue.create(:name   => _("Power up compute instance %s") % self, :priority => 1000,
+                   :action => [self, :setComputePowerUp])
+    end
   end
 
   def queue_compute_update
diff --git a/app/models/concerns/orchestration/dns.rb b/app/models/concerns/orchestration/dns.rb
index afe5fecb2..216256999 100644
--- a/app/models/concerns/orchestration/dns.rb
+++ b/app/models/concerns/orchestration/dns.rb
@@ -63,16 +63,20 @@ module Orchestration::DNS
   def queue_dns_create
     logger.debug "Scheduling new DNS entries"
     DnsInterface::RECORD_TYPES.each do |record_type|
-      queue.create(:name   => _("Create %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 10,
-                   :action => [self, :set_dns_record, record_type]) if dns_feasible?(record_type)
+      if dns_feasible?(record_type)
+        queue.create(:name   => _("Create %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 10,
+                     :action => [self, :set_dns_record, record_type])
+      end
     end
   end
 
   def queue_dns_update
     return unless pending_dns_record_changes?
     DnsInterface::RECORD_TYPES.each do |record_type|
-      queue.create(:name   => _("Remove %{type} for %{host}") % {:host => old, :type => dns_class(record_type).human }, :priority => 9,
-                   :action => [old, :del_dns_record, record_type]) if old.dns_feasible?(record_type)
+      if old.dns_feasible?(record_type)
+        queue.create(:name   => _("Remove %{type} for %{host}") % {:host => old, :type => dns_class(record_type).human }, :priority => 9,
+                     :action => [old, :del_dns_record, record_type])
+      end
     end
     queue_dns_create
   end
@@ -80,8 +84,10 @@ module Orchestration::DNS
   def queue_dns_destroy
     return unless errors.empty?
     DnsInterface::RECORD_TYPES.each do |record_type|
-      queue.create(:name   => _("Remove %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 1,
-                   :action => [self, :del_dns_record, record_type]) if dns_feasible?(record_type)
+      if dns_feasible?(record_type)
+        queue.create(:name   => _("Remove %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 1,
+                     :action => [self, :del_dns_record, record_type])
+      end
     end
   end
 
@@ -90,8 +96,10 @@ module Orchestration::DNS
     return unless overwrite?
     logger.debug "Scheduling DNS conflict removal"
     DnsInterface::RECORD_TYPES.each do |record_type|
-      queue.create(:name   => _("Remove conflicting %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 0,
-                   :action => [self, :del_conflicting_dns_record, record_type]) if dns_feasible?(record_type) && dns_record(record_type) && dns_record(record_type).conflicting?
+      if dns_feasible?(record_type) && dns_record(record_type) && dns_record(record_type).conflicting?
+        queue.create(:name   => _("Remove conflicting %{type} for %{host}") % {:host => self, :type => dns_class(record_type).human}, :priority => 0,
+                     :action => [self, :del_conflicting_dns_record, record_type])
+      end
     end
   end
 
diff --git a/app/models/filter.rb b/app/models/filter.rb
index ef1a7be8b..c307f389f 100644
--- a/app/models/filter.rb
+++ b/app/models/filter.rb
@@ -207,14 +207,16 @@ class Filter < ApplicationRecord
   # if we have 0 types, empty validation will set error, we can't have more than one type
   def same_resource_type_permissions
     types = self.permissions.map(&:resource_type).uniq
-    errors.add(
-      :permissions,
-      _('must be of same resource type (%s) - Role (%s)') %
-      [
-        types.join(','),
-        self.role.name
-      ]
-    ) if types.size > 1
+    if types.size > 1
+      errors.add(
+        :permissions,
+        _('must be of same resource type (%s) - Role (%s)') %
+        [
+          types.join(','),
+          self.role.name
+        ]
+      )
+    end
   end
 
   def not_empty_permissions
diff --git a/app/models/host/managed.rb b/app/models/host/managed.rb
index a60a945f4..3ff577501 100644
--- a/app/models/host/managed.rb
+++ b/app/models/host/managed.rb
@@ -694,8 +694,10 @@ class Host::Managed < Host::Base
   end
 
   def ipmi_boot(booting_device)
-    raise Foreman::Exception.new(
-      _("No BMC NIC available for host %s") % self) unless bmc_available?
+    unless bmc_available?
+      raise Foreman::Exception.new(
+        _("No BMC NIC available for host %s") % self)
+    end
     bmc_proxy.boot({:function => 'bootdevice', :device => booting_device})
   end
 
@@ -870,21 +872,25 @@ class Host::Managed < Host::Base
   # checks if the host association is a valid association for this host
   def ensure_associations
     status = true
-    %w{ptable medium architecture}.each do |e|
-      value = self.send(e.to_sym)
-      next if value.blank?
-      unless os.send(e.pluralize.to_sym).include?(value)
-        errors.add("#{e}_id".to_sym, _("%{value} does not belong to %{os} operating system") % { :value => value, :os => os })
-        status = false
+    if SETTINGS[:unattended] && managed? && os && pxe_build?
+      %w{ptable medium architecture}.each do |e|
+        value = self.send(e.to_sym)
+        next if value.blank?
+        unless os.send(e.pluralize.to_sym).include?(value)
+          errors.add("#{e}_id".to_sym, _("%{value} does not belong to %{os} operating system") % { :value => value, :os => os })
+          status = false
+        end
       end
-    end if SETTINGS[:unattended] && managed? && os && pxe_build?
+    end
 
-    puppetclasses.select("puppetclasses.id,puppetclasses.name").distinct.each do |e|
-      unless environment.puppetclasses.map(&:id).include?(e.id)
-        errors.add(:puppetclasses, _("%{e} does not belong to the %{environment} environment") % { :e => e, :environment => environment })
-        status = false
+    if environment
+      puppetclasses.select("puppetclasses.id,puppetclasses.name").distinct.each do |e|
+        unless environment.puppetclasses.map(&:id).include?(e.id)
+          errors.add(:puppetclasses, _("%{e} does not belong to the %{environment} environment") % { :e => e, :environment => environment })
+          status = false
+        end
       end
-    end if environment
+    end
     status
   end
 
diff --git a/app/models/hostgroup.rb b/app/models/hostgroup.rb
index 4c52d198f..723c5d4ae 100644
--- a/app/models/hostgroup.rb
+++ b/app/models/hostgroup.rb
@@ -137,11 +137,13 @@ class Hostgroup < ApplicationRecord
   end
 
   def inherited_lookup_value(key)
-    ancestors.reverse_each do |hg|
-      if (v = LookupValue.find_by(:lookup_key_id => key.id, :id => hg.lookup_values))
-        return v.value, hg.to_label
+    if key.path_elements.flatten.include?("hostgroup") && Setting["host_group_matchers_inheritance"]
+      ancestors.reverse_each do |hg|
+        if (v = LookupValue.find_by(:lookup_key_id => key.id, :id => hg.lookup_values))
+          return v.value, hg.to_label
+        end
       end
-    end if key.path_elements.flatten.include?("hostgroup") && Setting["host_group_matchers_inheritance"]
+    end
     [key.default_value, _("Default value")]
   end
 
@@ -244,9 +246,11 @@ class Hostgroup < ApplicationRecord
   private
 
   def nested_root_pw
-    Hostgroup.sort_by_ancestry(ancestors).reverse_each do |a|
-      return a.root_pass if a.root_pass.present?
-    end if ancestry.present?
+    if ancestry.present?
+      Hostgroup.sort_by_ancestry(ancestors).reverse_each do |a|
+        return a.root_pass if a.root_pass.present?
+      end
+    end
     nil
   end
 
diff --git a/app/models/lookup_keys/lookup_key.rb b/app/models/lookup_keys/lookup_key.rb
index 85f4bec70..456890d7f 100644
--- a/app/models/lookup_keys/lookup_key.rb
+++ b/app/models/lookup_keys/lookup_key.rb
@@ -112,13 +112,15 @@ class LookupKey < ApplicationRecord
 
   def value_before_type_cast(val)
     return val if val.nil? || val.contains_erb?
-    case key_type.to_sym
-      when :json, :array
-        val = JSON.dump(val)
-      when :yaml, :hash
-        val = YAML.dump val
-        val.sub!(/\A---\s*$\n/, '')
-    end if key_type.present?
+    if key_type.present?
+      case key_type.to_sym
+        when :json, :array
+          val = JSON.dump(val)
+        when :yaml, :hash
+          val = YAML.dump val
+          val.sub!(/\A---\s*$\n/, '')
+      end
+    end
     val
   end
 
diff --git a/app/services/classification/matches_generator.rb b/app/services/classification/matches_generator.rb
index e101137c4..3e03904fc 100644
--- a/app/services/classification/matches_generator.rb
+++ b/app/services/classification/matches_generator.rb
@@ -17,10 +17,12 @@ module Classification
         match = generate_match(rule)
         matches << match.join(LookupKey::KEY_DELM)
 
-        hostgroup_matches.each do |hostgroup_match|
-          match[match.index { |m| m =~ /hostgroup\s*=/ }] = hostgroup_match
-          matches << match.join(LookupKey::KEY_DELM)
-        end if add_hostgroup_matches?(rule)
+        if add_hostgroup_matches?(rule)
+          hostgroup_matches.each do |hostgroup_match|
+            match[match.index { |m| m =~ /hostgroup\s*=/ }] = hostgroup_match
+            matches << match.join(LookupKey::KEY_DELM)
+          end
+        end
       end
       matches
     end
diff --git a/app/services/foreman/importer_puppetclass.rb b/app/services/foreman/importer_puppetclass.rb
index eaa33d85d..ad9e0482e 100644
--- a/app/services/foreman/importer_puppetclass.rb
+++ b/app/services/foreman/importer_puppetclass.rb
@@ -25,11 +25,13 @@ class Foreman::ImporterPuppetclass
   def self.suggest_key_type(value, default = nil, detect_json_or_yaml = false)
     case value
     when String
-      begin
-        return "json" if JSON.load value
-      rescue
-        return "yaml" if YAML.load value
-      end if detect_json_or_yaml
+      if detect_json_or_yaml
+        begin
+          return "json" if JSON.load value
+        rescue
+          return "yaml" if YAML.load value
+        end
+      end
       "string"
     when TrueClass, FalseClass
       "boolean"
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 59aa6a67f..32a235e57 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -41,16 +41,18 @@ Foreman::Application.configure do
   # Raise exception on mass assignment of unfiltered parameters
   config.action_controller.action_on_unpermitted_parameters = :strict
 
-  config.after_initialize do
-    Bullet.enable = true
-    Bullet.bullet_logger = true
-    Bullet.console = true
-    Bullet.rails_logger = true
-    Bullet.add_footer = true
-    Bullet.counter_cache_enable = false
-    Bullet.add_whitelist :type => :n_plus_one_query, :class_name => "Puppetclass", :association => :environments
-    Bullet.add_whitelist :type => :n_plus_one_query, :class_name => "Puppetclass", :association => :class_params
-  end if defined?(Bullet)
+  if defined?(Bullet)
+    config.after_initialize do
+      Bullet.enable = true
+      Bullet.bullet_logger = true
+      Bullet.console = true
+      Bullet.rails_logger = true
+      Bullet.add_footer = true
+      Bullet.counter_cache_enable = false
+      Bullet.add_whitelist :type => :n_plus_one_query, :class_name => "Puppetclass", :association => :environments
+      Bullet.add_whitelist :type => :n_plus_one_query, :class_name => "Puppetclass", :association => :class_params
+    end
+  end
 
   # Allow disabling the webpack dev server from the settings
   config.webpack.dev_server.enabled = SETTINGS.fetch(:webpack_dev_server, true)
diff --git a/config/initializers/apipie.rb b/config/initializers/apipie.rb
index 7aca84cfa..0b3879c6e 100644
--- a/config/initializers/apipie.rb
+++ b/config/initializers/apipie.rb
@@ -52,10 +52,12 @@ if Apipie.configuration.use_cache
     roots << Rails.root
     roots.each do |root|
       path = "#{root}/app/controllers/api"
-      Find.find(path) do |e|
-        t = File.mtime(e)
-        max = t if t > max
-      end if File.exist?(path)
+      if File.exist?(path)
+        Find.find(path) do |e|
+          t = File.mtime(e)
+          max = t if t > max
+        end
+      end
     end
     if !$ARGV.nil? && $ARGV.first != "apipie:cache" && max > target
       puts "API controllers newer than Apipie cache! Run apipie:cache rake task to regenerate cache."
diff --git a/db/migrate/20130520152000_remove_duplicate_fact_names.rb b/db/migrate/20130520152000_remove_duplicate_fact_names.rb
index 249672a2f..f19d49431 100644
--- a/db/migrate/20130520152000_remove_duplicate_fact_names.rb
+++ b/db/migrate/20130520152000_remove_duplicate_fact_names.rb
@@ -3,17 +3,19 @@ class RemoveDuplicateFactNames < ActiveRecord::Migration[4.2]
     unique_names = FactName.group(:name).maximum(:id)
     unique_names.each do |fact_name, fact_name_id|
       duplicates = FactName.where("name=? and id<>?", fact_name, fact_name_id).select(:id)
-      ActiveRecord::Base.transaction do
-        FactValue.update_all(
-          ["fact_name_id=?", fact_name_id],
-          ["fact_name_id in (?)", duplicates]
-        )
-        UserFact.update_all(
-          ["fact_name_id=?", fact_name_id],
-          ["fact_name_id in (?)", duplicates]
-        )
-        FactName.where(["id in (?)", duplicates]).delete_all
-      end if duplicates.any?
+      if duplicates.any?
+        ActiveRecord::Base.transaction do
+          FactValue.update_all(
+            ["fact_name_id=?", fact_name_id],
+            ["fact_name_id in (?)", duplicates]
+          )
+          UserFact.update_all(
+            ["fact_name_id=?", fact_name_id],
+            ["fact_name_id in (?)", duplicates]
+          )
+          FactName.where(["id in (?)", duplicates]).delete_all
+        end
+      end
     end
   end
 
diff --git a/db/seeds.d/160-mail_notifications.rb b/db/seeds.d/160-mail_notifications.rb
index 710574310..b052a2834 100644
--- a/db/seeds.d/160-mail_notifications.rb
+++ b/db/seeds.d/160-mail_notifications.rb
@@ -70,7 +70,9 @@ notifications.each do |notification|
     mail.save! if mail.changed?
   else
     created_notification = MailNotification.create(notification)
-    raise ::Foreman::Exception.new(N_("Unable to create mail notification: %s"),
-                                   format_errors(created_notification)) if created_notification.nil? || created_notification.errors.any?
+    if created_notification.nil? || created_notification.errors.any?
+      raise ::Foreman::Exception.new(N_("Unable to create mail notification: %s"),
+                                     format_errors(created_notification))
+    end
   end
 end
diff --git a/lib/foreman/telemetry.rb b/lib/foreman/telemetry.rb
index 837421adc..8cd1239de 100644
--- a/lib/foreman/telemetry.rb
+++ b/lib/foreman/telemetry.rb
@@ -39,34 +39,40 @@ module Foreman
       :minor_gc_count => :ruby_gc_minor_count
     }
     def register_rails
-      ActiveSupport::Notifications.subscribe(/process_action.action_controller/) do |*args|
-        event = ActiveSupport::Notifications::Event.new(*args)
-        controller = event.payload[:controller].underscore
-        action = event.payload[:action].underscore
-        status = event.payload[:status]
-
-        increment_counter(:http_requests, 1, :controller => controller, :action => action, :status => status)
-        observe_histogram(:http_request_total_duration, event.duration || 0, :controller => controller, :action => action)
-        observe_histogram(:http_request_db_duration, event.payload[:db_runtime] || 0, :controller => controller, :action => action)
-        observe_histogram(:http_request_view_duration, event.payload[:view_runtime] || 0, :controller => controller, :action => action)
-
-        # measure GC stats for each request
-        before = Thread.current[:foreman_telemetry_gcstats]
-        after = GC.stat
-        GC_METRICS.each do |ruby_key, metric_name|
-          if after.include?(ruby_key)
-            count = after[ruby_key] - before[ruby_key]
-            increment_counter(metric_name, count, :controller => controller, :action => action) if count > 0
+      if enabled?
+        ActiveSupport::Notifications.subscribe(/process_action.action_controller/) do |*args|
+          event = ActiveSupport::Notifications::Event.new(*args)
+          controller = event.payload[:controller].underscore
+          action = event.payload[:action].underscore
+          status = event.payload[:status]
+
+          increment_counter(:http_requests, 1, :controller => controller, :action => action, :status => status)
+          observe_histogram(:http_request_total_duration, event.duration || 0, :controller => controller, :action => action)
+          observe_histogram(:http_request_db_duration, event.payload[:db_runtime] || 0, :controller => controller, :action => action)
+          observe_histogram(:http_request_view_duration, event.payload[:view_runtime] || 0, :controller => controller, :action => action)
+
+          # measure GC stats for each request
+          before = Thread.current[:foreman_telemetry_gcstats]
+          after = GC.stat
+          if before
+            GC_METRICS.each do |ruby_key, metric_name|
+              if after.include?(ruby_key)
+                count = after[ruby_key] - before[ruby_key]
+                increment_counter(metric_name, count, :controller => controller, :action => action) if count > 0
+              end
+            end
           end
-        end if before
-      end if enabled?
-
-      ActiveSupport::Notifications.subscribe(/instantiation.active_record/) do |*args|
-        event = ActiveSupport::Notifications::Event.new(*args)
-        class_name = event.payload[:class_name]
-        record_count = event.payload[:record_count]
-        increment_counter(:activerecord_instances, record_count, :class => class_name) if record_count > 0
-      end if enabled?
+        end
+      end
+
+      if enabled?
+        ActiveSupport::Notifications.subscribe(/instantiation.active_record/) do |*args|
+          event = ActiveSupport::Notifications::Event.new(*args)
+          class_name = event.payload[:class_name]
+          record_count = event.payload[:record_count]
+          increment_counter(:activerecord_instances, record_count, :class => class_name) if record_count > 0
+        end
+      end
     end
 
     def register_ruby
diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake
index d3025ae62..a115c377c 100644
--- a/lib/tasks/backup.rake
+++ b/lib/tasks/backup.rake
@@ -105,8 +105,10 @@ Available conditions:
 END_DESC
 
   task :import_dump => :environment do
-    puts "Run this task with a file argument with the location of your db dump,
-          'rake db:import_dump file=DBDUMPLOCATION" and return unless ENV['file']
+    unless ENV['file']
+      puts "Run this task with a file argument with the location of your db dump,
+            'rake db:import_dump file=DBDUMPLOCATION" and return
+    end
     config = Rails.configuration.database_configuration[Rails.env]
 
     puts "Your backup is going to be imported from: #{ENV['file']}"
diff --git a/test/active_support_test_case_helper.rb b/test/active_support_test_case_helper.rb
index 63b4aeb21..4b08f0f8f 100644
--- a/test/active_support_test_case_helper.rb
+++ b/test/active_support_test_case_helper.rb
@@ -194,8 +194,10 @@ class ActiveSupport::TestCase
     if field
       model_errors = model.errors.map { |a, m| model.errors.full_message(a, m) unless field == a }.compact
       assert model_errors.blank?, "#{model} contains #{model_errors}, it should not contain any"
-      assert model.errors[field].find { |e| e.match(match) }.present?,
-        "#{field} error matching #{match} not found: #{model.errors[field].inspect}" if match
+      if match
+        assert model.errors[field].find { |e| e.match(match) }.present?,
+          "#{field} error matching #{match} not found: #{model.errors[field].inspect}"
+      end
     end
   end
   alias_method :assert_not_with_errors, :refute_with_errors
diff --git a/test/controllers/api/v2/fact_values_controller_test.rb b/test/controllers/api/v2/fact_values_controller_test.rb
index 36e5ba4d2..1211af4cb 100644
--- a/test/controllers/api/v2/fact_values_controller_test.rb
+++ b/test/controllers/api/v2/fact_values_controller_test.rb
@@ -11,7 +11,7 @@ class Api::V2::FactValuesControllerTest < ActionController::TestCase
     get :index
     assert_response :success
     fact_values = ActiveSupport::JSON.decode(@response.body)['results']
-    expected_hash = {@host.name=>{"kernelversion"=>"2.6.9"}}
+    expected_hash = {@host.name => {"kernelversion" => "2.6.9"}}
     assert_equal expected_hash, fact_values
   end
 
@@ -19,7 +19,7 @@ class Api::V2::FactValuesControllerTest < ActionController::TestCase
     get :index, params: {:host_id => @host.name}
     assert_response :success
     fact_values   = ActiveSupport::JSON.decode(@response.body)['results']
-    expected_hash = {@host.name =>{"kernelversion"=>"2.6.9"}, "kernelversion"=>"2.6.9"}
+    expected_hash = {@host.name => {"kernelversion" => "2.6.9"}, "kernelversion" => "2.6.9"}
     assert_equal expected_hash, fact_values
   end
 
@@ -27,7 +27,7 @@ class Api::V2::FactValuesControllerTest < ActionController::TestCase
     get :index, params: {:host_id => @host.id}
     assert_response :success
     fact_values = ActiveSupport::JSON.decode(@response.body)['results']
-    expected_hash = {@host.name =>{"kernelversion"=>"2.6.9"}, "kernelversion"=>"2.6.9"}
+    expected_hash = {@host.name => {"kernelversion" => "2.6.9"}, "kernelversion" => "2.6.9"}
     assert_equal expected_hash, fact_values
   end
 
@@ -39,7 +39,7 @@ class Api::V2::FactValuesControllerTest < ActionController::TestCase
     end
     assert_response :success
     fact_values = ActiveSupport::JSON.decode(@response.body)['results']
-    expected_hash = {@host.name=>{"kernelversion"=>"2.6.9"}}
+    expected_hash = {@host.name => {"kernelversion" => "2.6.9"}}
     assert_equal expected_hash, fact_values
   end
 
