diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a3e48b..f134afe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,84 +1,35 @@ -name: CI -on: [push, pull_request] -env: - RAILS_ENV: test - DATABASE_URL: postgresql://postgres:@localhost/test - DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: true +name: Ruby test + +on: + pull_request: + push: + branches: + - master + +concurrency: + group: ${{ github.ref_name }}-${{ github.workflow }} + cancel-in-progress: true + jobs: rubocop: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: 2.7 - - name: Setup - run: | - gem install bundler - bundle install --jobs=3 --retry=3 - - name: Run rubocop - run: bundle exec rubocop + uses: theforeman/actions/.github/workflows/rubocop.yml@v0 + with: + command: bundle exec rubocop --parallel --format github + test: - runs-on: ubuntu-latest + name: Ruby needs: rubocop - services: - postgres: - image: postgres:12.1 - ports: ["5432:5432"] - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 strategy: fail-fast: false matrix: - foreman-core-branch: [3.0-stable, 3.1-stable, 3.2-stable, develop] - ruby-version: [2.7] - node-version: [12] - steps: - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y build-essential libcurl4-openssl-dev libvirt-dev ruby-libvirt zlib1g-dev libpq-dev - - uses: actions/checkout@v2 - with: - clean: false - repository: theforeman/foreman - ref: ${{ matrix.foreman-core-branch }} - fetch-depth: 0 - - uses: actions/checkout@v2 - with: - clean: false - path: foreman_dlm - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby-version }} - - name: Setup Node - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - name: Setup Plugin - run: | - echo "gem 'foreman_dlm', path: './foreman_dlm'" > bundler.d/foreman_dlm.local.rb - gem install bundler - bundle config set without journald development console sqlite - bundle install --jobs=3 --retry=3 - bundle exec rake db:create - bundle exec rake db:migrate - npm install - bundle exec rake webpack:compile - - name: Run plugin tests - uses: nick-fields/retry@v2 - with: - max_attempts: 5 - timeout_minutes: 30 - command: | - bundle exec rake --trace test:foreman_dlm - bundle exec rake test TEST="test/unit/foreman/access_permissions_test.rb" - - name: Precompile plugin assets - run: | - bundle exec rake db:create - bundle exec rake db:migrate - bundle exec rake 'plugin:assets:precompile[foreman_dlm]' - env: - DATABASE_URL: postgresql://postgres:@localhost/production - RAILS_ENV: production + foreman: + - "develop" + - "3.10-stable" + - "3.9-stable" + uses: theforeman/actions/.github/workflows/foreman_plugin.yml@v0 + with: + plugin: foreman_dlm + foreman_version: ${{ matrix.foreman }} + environment_variables: | + FOREMAN_VERSION=${{ matrix.foreman }} + DEBUG_JS_TEST=1 diff --git a/.rubocop.yml b/.rubocop.yml index 8e7214a..80a96e0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,22 +1,6 @@ -inherit_from: .rubocop_todo.yml - -require: - - rubocop-rails - - rubocop-performance - -AllCops: - TargetRubyVersion: 2.7 - TargetRailsVersion: 5.1 - NewCops: enable - Exclude: - - '*.spec' - - 'Rakefile' - - 'extras/**/*' - - 'locale/**/*' - - 'node_modules/**/*' - - 'vendor/bundle/**/*' -Rails: - Enabled: true +inherit_gem: + theforeman-rubocop: + - default.yml # Don't enforce documentation Style/Documentation: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index 165ca06..0000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,48 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2022-02-25 13:30:04 UTC using RuboCop version 1.25.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -# Configuration parameters: Include. -# Include: **/*.gemspec -Gemspec/RequiredRubyVersion: - Exclude: - - 'foreman_dlm.gemspec' - -# Offense count: 1 -# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to -Naming/MethodParameterName: - Exclude: - - 'app/models/foreman_dlm/dlmlock.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Performance/StringInclude: - Exclude: - - 'test/controllers/hosts_controller_test.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Rails/ActiveRecordAliases: - Exclude: - - 'app/controllers/api/v2/dlmlocks_controller.rb' - -# Offense count: 1 -# Cop supports --auto-correct-all. -# Configuration parameters: Include. -# Include: **/Rakefile, **/*.rake -Rails/RakeEnvironment: - Exclude: - - 'lib/tasks/foreman_dlm_tasks.rake' - -# Offense count: 66 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: always, always_true, never -Style/FrozenStringLiteralComment: - Enabled: false diff --git a/Gemfile b/Gemfile index fa75df1..7f4f5e9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 index 7c6f0a1..a579d88 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,6 @@ #!/usr/bin/env rake +# frozen_string_literal: true + begin require 'bundler/setup' rescue LoadError @@ -20,7 +22,7 @@ RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_files.include('lib/**/*.rb') end -APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__) +APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__) Bundler::GemHelper.install_tasks @@ -38,7 +40,7 @@ task default: :test begin require 'rubocop/rake_task' RuboCop::RakeTask.new -rescue => _ +rescue StandardError puts 'Rubocop not loaded.' end diff --git a/app/controllers/api/v2/dlmlock_events_controller.rb b/app/controllers/api/v2/dlmlock_events_controller.rb index 93b6a87..011c007 100644 --- a/app/controllers/api/v2/dlmlock_events_controller.rb +++ b/app/controllers/api/v2/dlmlock_events_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Api module V2 class DlmlockEventsController < V2::BaseController diff --git a/app/controllers/api/v2/dlmlocks_controller.rb b/app/controllers/api/v2/dlmlocks_controller.rb index 713d77e..6799452 100644 --- a/app/controllers/api/v2/dlmlocks_controller.rb +++ b/app/controllers/api/v2/dlmlocks_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Api module V2 class DlmlocksController < V2::BaseController @@ -37,7 +39,8 @@ def index error 404, 'Lock could not be found.' param :id, String, :required => true, :desc => N_('Id or name of the DLM lock') - def show; end + def show + end api :POST, '/dlmlocks', N_('Create a DLM lock') param_group :dlmlock, :as => :create @@ -52,7 +55,7 @@ def create param_group :dlmlock def update - process_response @dlmlock.update_attributes(dlmlocks_params) + process_response @dlmlock.update(dlmlocks_params) end api :DELETE, '/dlmlocks/:id/', N_('Delete a DLM lock') @@ -133,16 +136,16 @@ def find_host logger.info 'Denying access because no host could be detected.' if User.current render_error 'access_denied', - :status => :forbidden, - :locals => { - :details => 'You need to authenticate with a valid client cert. The DN has to match a known host.' - } + :status => :forbidden, + :locals => { + :details => 'You need to authenticate with a valid client cert. The DN has to match a known host.', + } else render_error 'unauthorized', - :status => :unauthorized, - :locals => { - :user_login => get_client_cert_hostname - } + :status => :unauthorized, + :locals => { + :user_login => get_client_cert_hostname, + } end end true @@ -163,7 +166,7 @@ def process_lock_resource_error(options = {}) deny_access else render_error 'precondition_failed', :status => :precondition_failed, :locals => { - :message => 'Precondition failed. Lock is in invalid state for this operation.' + :message => 'Precondition failed. Lock is in invalid state for this operation.', } end end diff --git a/app/controllers/concerns/foreman/controller/parameters/dlmlocks.rb b/app/controllers/concerns/foreman/controller/parameters/dlmlocks.rb index 65b516b..25227bf 100644 --- a/app/controllers/concerns/foreman/controller/parameters/dlmlocks.rb +++ b/app/controllers/concerns/foreman/controller/parameters/dlmlocks.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Foreman::Controller::Parameters::Dlmlocks extend ActiveSupport::Concern diff --git a/app/controllers/concerns/foreman_dlm/find_host_by_client_cert.rb b/app/controllers/concerns/foreman_dlm/find_host_by_client_cert.rb index d797c0e..3376857 100644 --- a/app/controllers/concerns/foreman_dlm/find_host_by_client_cert.rb +++ b/app/controllers/concerns/foreman_dlm/find_host_by_client_cert.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm module FindHostByClientCert extend ActiveSupport::Concern diff --git a/app/controllers/concerns/foreman_dlm/find_host_by_ip.rb b/app/controllers/concerns/foreman_dlm/find_host_by_ip.rb index 234a279..ffe8b1b 100644 --- a/app/controllers/concerns/foreman_dlm/find_host_by_ip.rb +++ b/app/controllers/concerns/foreman_dlm/find_host_by_ip.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm module FindHostByIp extend ActiveSupport::Concern diff --git a/app/controllers/concerns/foreman_dlm/update_checkin_time.rb b/app/controllers/concerns/foreman_dlm/update_checkin_time.rb index 44d9254..7fc0833 100644 --- a/app/controllers/concerns/foreman_dlm/update_checkin_time.rb +++ b/app/controllers/concerns/foreman_dlm/update_checkin_time.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm module UpdateCheckinTime extend ActiveSupport::Concern diff --git a/app/controllers/foreman_dlm/application_controller.rb b/app/controllers/foreman_dlm/application_controller.rb index 43e4abd..2b749d1 100644 --- a/app/controllers/foreman_dlm/application_controller.rb +++ b/app/controllers/foreman_dlm/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm class ApplicationController < ::ApplicationController def resource_class diff --git a/app/controllers/foreman_dlm/dlmlocks_controller.rb b/app/controllers/foreman_dlm/dlmlocks_controller.rb index 55a385d..d2eba43 100644 --- a/app/controllers/foreman_dlm/dlmlocks_controller.rb +++ b/app/controllers/foreman_dlm/dlmlocks_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm class DlmlocksController < ::ForemanDlm::ApplicationController include ::Foreman::Controller::AutoCompleteSearch @@ -9,7 +11,8 @@ def index @dlmlocks = resource_base_search_and_page(:host) end - def show; end + def show + end def destroy if @dlmlock.destroy @@ -59,15 +62,6 @@ def model_of_controller ForemanDlm::Dlmlock end - # see https://projects.theforeman.org/issues/25976 - # can be removed for Foreman 1.22+ - def auto_complete_controller_name - current_version = Gem::Version.new(Foreman::Version.new.notag) - return '/foreman_dlm/dlmlocks' if current_version >= Gem::Version.new('1.20') && current_version < Gem::Version.new('1.22') - - controller_name - end - private def action_permission diff --git a/app/helpers/foreman_dlm/dlmlock_helper.rb b/app/helpers/foreman_dlm/dlmlock_helper.rb index 79780cb..fa6216c 100644 --- a/app/helpers/foreman_dlm/dlmlock_helper.rb +++ b/app/helpers/foreman_dlm/dlmlock_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm module DlmlockHelper def dlmlock_status_icon_class(lock) diff --git a/app/jobs/foreman_dlm/refresh_dlmlock_status.rb b/app/jobs/foreman_dlm/refresh_dlmlock_status.rb index 307b29a..736407c 100644 --- a/app/jobs/foreman_dlm/refresh_dlmlock_status.rb +++ b/app/jobs/foreman_dlm/refresh_dlmlock_status.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm class RefreshDlmlockStatus < ApplicationJob queue_as :refresh_dlmlock_status_queue diff --git a/app/models/concerns/foreman_dlm/dlm_facet_host_extensions.rb b/app/models/concerns/foreman_dlm/dlm_facet_host_extensions.rb index 0c95e40..7aa6958 100644 --- a/app/models/concerns/foreman_dlm/dlm_facet_host_extensions.rb +++ b/app/models/concerns/foreman_dlm/dlm_facet_host_extensions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm module DlmFacetHostExtensions extend ActiveSupport::Concern diff --git a/app/models/concerns/foreman_dlm/expirable.rb b/app/models/concerns/foreman_dlm/expirable.rb index d8d2759..3e4138c 100644 --- a/app/models/concerns/foreman_dlm/expirable.rb +++ b/app/models/concerns/foreman_dlm/expirable.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm module Expirable extend ActiveSupport::Concern diff --git a/app/models/concerns/foreman_dlm/host_extensions.rb b/app/models/concerns/foreman_dlm/host_extensions.rb index 3165ca0..fd3ee04 100644 --- a/app/models/concerns/foreman_dlm/host_extensions.rb +++ b/app/models/concerns/foreman_dlm/host_extensions.rb @@ -1,19 +1,21 @@ +# frozen_string_literal: true + module ForemanDlm module HostExtensions extend ActiveSupport::Concern included do has_many :dlmlocks, - class_name: 'ForemanDlm::Dlmlock', - foreign_key: 'host_id', - dependent: :nullify, - inverse_of: :host + class_name: 'ForemanDlm::Dlmlock', + foreign_key: 'host_id', + dependent: :nullify, + inverse_of: :host has_many :dlmlock_events, - class_name: 'ForemanDlm::DlmlockEvent', - foreign_key: 'host_id', - dependent: :destroy, - inverse_of: :host + class_name: 'ForemanDlm::DlmlockEvent', + foreign_key: 'host_id', + dependent: :destroy, + inverse_of: :host define_model_callbacks :lock, :only => :after define_model_callbacks :unlock, :only => :after diff --git a/app/models/concerns/foreman_dlm/host_monitoring_extensions.rb b/app/models/concerns/foreman_dlm/host_monitoring_extensions.rb index 2eae840..57780df 100644 --- a/app/models/concerns/foreman_dlm/host_monitoring_extensions.rb +++ b/app/models/concerns/foreman_dlm/host_monitoring_extensions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm module HostMonitoringExtensions extend ActiveSupport::Concern @@ -31,7 +33,7 @@ def lock_monitoring_downtime_options { comment: _('Host acquired lock.'), start_time: Time.current.to_i, - end_time: Time.current.advance(:minutes => 180).to_i + end_time: Time.current.advance(:minutes => 180).to_i, } end end diff --git a/app/models/concerns/foreman_dlm/user_extensions.rb b/app/models/concerns/foreman_dlm/user_extensions.rb index ee0cb3e..e9f5942 100644 --- a/app/models/concerns/foreman_dlm/user_extensions.rb +++ b/app/models/concerns/foreman_dlm/user_extensions.rb @@ -1,13 +1,15 @@ +# frozen_string_literal: true + module ForemanDlm module UserExtensions extend ActiveSupport::Concern included do has_many :dlmlock_events, - class_name: 'ForemanDlm::DlmlockEvent', - foreign_key: 'user_id', - dependent: :nullify, - inverse_of: :user + class_name: 'ForemanDlm::DlmlockEvent', + foreign_key: 'user_id', + dependent: :nullify, + inverse_of: :user end end end diff --git a/app/models/foreman_dlm/dlm_facet.rb b/app/models/foreman_dlm/dlm_facet.rb index f6907bd..7e0002b 100644 --- a/app/models/foreman_dlm/dlm_facet.rb +++ b/app/models/foreman_dlm/dlm_facet.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm class DlmFacet < ApplicationRecord include Facets::Base diff --git a/app/models/foreman_dlm/dlmlock.rb b/app/models/foreman_dlm/dlmlock.rb index 568f873..1da53be 100644 --- a/app/models/foreman_dlm/dlmlock.rb +++ b/app/models/foreman_dlm/dlmlock.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm class Dlmlock < ApplicationRecord include Authorizable @@ -13,9 +15,9 @@ def self.dlm_stale_time belongs_to_host has_many :dlmlock_events, - class_name: '::ForemanDlm::DlmlockEvent', - dependent: :destroy, - inverse_of: :dlmlock + class_name: '::ForemanDlm::DlmlockEvent', + dependent: :destroy, + inverse_of: :dlmlock validates :name, presence: true, uniqueness: true @@ -67,7 +69,7 @@ def disable! def locked_by?(host) self.host == host end - alias acquired_by? locked_by? + alias_method :acquired_by?, :locked_by? def disabled? !enabled? @@ -76,7 +78,7 @@ def disabled? def locked? host.present? end - alias taken? locked? + alias_method :taken?, :locked? def humanized_type _('Generic Lock') @@ -91,7 +93,7 @@ def atomic_update(old_host, new_host) query = { id: id, host_id: [new_host.try(:id), old_host.try(:id)], - enabled: true + enabled: true, } updated = self.class.where(query).update(changes.merge(updated_at: Time.now.utc)) @@ -127,9 +129,9 @@ def log_event(host, event_type) ) end - def run_callback(h, callback) - h.run_callbacks callback do - logger.debug { "custom hook after_#{callback} on #{h} will be executed if defined." } + def run_callback(host, callback) + host.run_callbacks callback do + logger.debug { "custom hook after_#{callback} on #{host} will be executed if defined." } true end end diff --git a/app/models/foreman_dlm/dlmlock/update.rb b/app/models/foreman_dlm/dlmlock/update.rb index 06b7b43..64dd128 100644 --- a/app/models/foreman_dlm/dlmlock/update.rb +++ b/app/models/foreman_dlm/dlmlock/update.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm class Dlmlock class Update < Dlmlock diff --git a/app/models/foreman_dlm/dlmlock_event.rb b/app/models/foreman_dlm/dlmlock_event.rb index 81d8aca..09511e5 100644 --- a/app/models/foreman_dlm/dlmlock_event.rb +++ b/app/models/foreman_dlm/dlmlock_event.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm class DlmlockEvent < ApplicationRecord include Authorizable diff --git a/app/models/host_status/dlmlock_status.rb b/app/models/host_status/dlmlock_status.rb index e59cc92..866dde7 100644 --- a/app/models/host_status/dlmlock_status.rb +++ b/app/models/host_status/dlmlock_status.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module HostStatus class DlmlockStatus < Status OK = 0 diff --git a/app/views/api/v2/dlmlock_events/index.json.rabl b/app/views/api/v2/dlmlock_events/index.json.rabl index 6a2dd12..d105fbc 100644 --- a/app/views/api/v2/dlmlock_events/index.json.rabl +++ b/app/views/api/v2/dlmlock_events/index.json.rabl @@ -1,2 +1,4 @@ +# frozen_string_literal: true + collection @events attributes :id, :event_type, :created_at, :updated_at diff --git a/app/views/api/v2/dlmlocks/acquire.json.rabl b/app/views/api/v2/dlmlocks/acquire.json.rabl index 447ec24..e87222a 100644 --- a/app/views/api/v2/dlmlocks/acquire.json.rabl +++ b/app/views/api/v2/dlmlocks/acquire.json.rabl @@ -1,3 +1,5 @@ +# frozen_string_literal: true + object @dlmlock extends 'api/v2/dlmlocks/main' diff --git a/app/views/api/v2/dlmlocks/base.json.rabl b/app/views/api/v2/dlmlocks/base.json.rabl index 6f692c6..0226471 100644 --- a/app/views/api/v2/dlmlocks/base.json.rabl +++ b/app/views/api/v2/dlmlocks/base.json.rabl @@ -1,3 +1,5 @@ +# frozen_string_literal: true + object @dlmlock attributes :id, :host_id, :name, :enabled, :type diff --git a/app/views/api/v2/dlmlocks/create.json.rabl b/app/views/api/v2/dlmlocks/create.json.rabl index ebcb8db..797dee7 100644 --- a/app/views/api/v2/dlmlocks/create.json.rabl +++ b/app/views/api/v2/dlmlocks/create.json.rabl @@ -1,3 +1,5 @@ +# frozen_string_literal: true + object @dlmlock extends 'api/v2/dlmlocks/show' diff --git a/app/views/api/v2/dlmlocks/index.json.rabl b/app/views/api/v2/dlmlocks/index.json.rabl index 9f82493..9a24e2d 100644 --- a/app/views/api/v2/dlmlocks/index.json.rabl +++ b/app/views/api/v2/dlmlocks/index.json.rabl @@ -1,3 +1,5 @@ +# frozen_string_literal: true + collection @dlmlocks extends 'api/v2/dlmlocks/main' diff --git a/app/views/api/v2/dlmlocks/main.json.rabl b/app/views/api/v2/dlmlocks/main.json.rabl index 8812e37..a5c5c58 100644 --- a/app/views/api/v2/dlmlocks/main.json.rabl +++ b/app/views/api/v2/dlmlocks/main.json.rabl @@ -1,3 +1,5 @@ +# frozen_string_literal: true + object @dlmlock extends 'api/v2/dlmlocks/base' diff --git a/app/views/api/v2/dlmlocks/release.json.rabl b/app/views/api/v2/dlmlocks/release.json.rabl index 447ec24..e87222a 100644 --- a/app/views/api/v2/dlmlocks/release.json.rabl +++ b/app/views/api/v2/dlmlocks/release.json.rabl @@ -1,3 +1,5 @@ +# frozen_string_literal: true + object @dlmlock extends 'api/v2/dlmlocks/main' diff --git a/app/views/api/v2/dlmlocks/show.json.rabl b/app/views/api/v2/dlmlocks/show.json.rabl index 3eff76a..256cd9f 100644 --- a/app/views/api/v2/dlmlocks/show.json.rabl +++ b/app/views/api/v2/dlmlocks/show.json.rabl @@ -1,3 +1,5 @@ +# frozen_string_literal: true + object @dlmlock extends 'api/v2/dlmlocks/main' diff --git a/app/views/api/v2/dlmlocks/update.json.rabl b/app/views/api/v2/dlmlocks/update.json.rabl index ebcb8db..797dee7 100644 --- a/app/views/api/v2/dlmlocks/update.json.rabl +++ b/app/views/api/v2/dlmlocks/update.json.rabl @@ -1,3 +1,5 @@ +# frozen_string_literal: true + object @dlmlock extends 'api/v2/dlmlocks/show' diff --git a/app/views/api/v2/errors/precondition_failed.json.rabl b/app/views/api/v2/errors/precondition_failed.json.rabl index e1cd111..8b7929e 100644 --- a/app/views/api/v2/errors/precondition_failed.json.rabl +++ b/app/views/api/v2/errors/precondition_failed.json.rabl @@ -1,3 +1,5 @@ +# frozen_string_literal: true + object controller.get_resource attributes :id diff --git a/app/views/foreman_dlm/api/v2/dlm_facets/base.json.rabl b/app/views/foreman_dlm/api/v2/dlm_facets/base.json.rabl index f277c8a..75e78fa 100644 --- a/app/views/foreman_dlm/api/v2/dlm_facets/base.json.rabl +++ b/app/views/foreman_dlm/api/v2/dlm_facets/base.json.rabl @@ -1 +1,3 @@ +# frozen_string_literal: true + attributes :id, :last_checkin_at diff --git a/app/views/foreman_dlm/api/v2/dlm_facets/base_with_root.json.rabl b/app/views/foreman_dlm/api/v2/dlm_facets/base_with_root.json.rabl index 8eb2835..57a437a 100644 --- a/app/views/foreman_dlm/api/v2/dlm_facets/base_with_root.json.rabl +++ b/app/views/foreman_dlm/api/v2/dlm_facets/base_with_root.json.rabl @@ -1,3 +1,5 @@ +# frozen_string_literal: true + child :dlm_facet => :dlm_facet_attributes do |_dlm_facet| extends 'foreman_dlm/api/v2/dlm_facets/base' end diff --git a/app/views/foreman_dlm/api/v2/dlm_facets/show.json.rabl b/app/views/foreman_dlm/api/v2/dlm_facets/show.json.rabl index 9731a60..a73b8cc 100644 --- a/app/views/foreman_dlm/api/v2/dlm_facets/show.json.rabl +++ b/app/views/foreman_dlm/api/v2/dlm_facets/show.json.rabl @@ -1,3 +1,5 @@ +# frozen_string_literal: true + child :dlm_facet => :dlm_facet_attributes do extends 'foreman_dlm/api/v2/dlm_facets/base' end diff --git a/config/routes.rb b/config/routes.rb index 07b4b3c..0ef4600 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.routes.draw do namespace :api, :defaults => { :format => 'json' } do scope '(:apiv)', :module => :v2, diff --git a/db/migrate/20170824084100_add_dlmlock.foreman_dlm.rb b/db/migrate/20170824084100_add_dlmlock.foreman_dlm.rb index af1dda4..16465f5 100644 --- a/db/migrate/20170824084100_add_dlmlock.foreman_dlm.rb +++ b/db/migrate/20170824084100_add_dlmlock.foreman_dlm.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddDlmlock < ActiveRecord::Migration[4.2] def change create_table :dlmlocks do |t| diff --git a/db/migrate/20180627150003_rename_dlmlock_sti_models.rb b/db/migrate/20180627150003_rename_dlmlock_sti_models.rb index fe1e72c..342017f 100644 --- a/db/migrate/20180627150003_rename_dlmlock_sti_models.rb +++ b/db/migrate/20180627150003_rename_dlmlock_sti_models.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RenameDlmlockStiModels < ActiveRecord::Migration[5.1] def up execute "UPDATE dlmlocks set type='ForemanDlm::Dlmlock::Update' where type='Dlmlock::Update';" diff --git a/db/migrate/20180704162345_add_dlmlock_events.rb b/db/migrate/20180704162345_add_dlmlock_events.rb index 5fa5d50..12cb5ff 100644 --- a/db/migrate/20180704162345_add_dlmlock_events.rb +++ b/db/migrate/20180704162345_add_dlmlock_events.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddDlmlockEvents < ActiveRecord::Migration[5.1] def change create_table :dlmlock_events do |t| diff --git a/db/migrate/20180711090022_add_hosts_fk_to_dlmlocks.rb b/db/migrate/20180711090022_add_hosts_fk_to_dlmlocks.rb index 2857cf6..bc410c0 100644 --- a/db/migrate/20180711090022_add_hosts_fk_to_dlmlocks.rb +++ b/db/migrate/20180711090022_add_hosts_fk_to_dlmlocks.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddHostsFkToDlmlocks < ActiveRecord::Migration[5.1] def change add_foreign_key :dlmlocks, :hosts diff --git a/db/migrate/20180711111903_create_dlm_facets.foreman_dlm.rb b/db/migrate/20180711111903_create_dlm_facets.foreman_dlm.rb index 95b25fe..4aefeee 100644 --- a/db/migrate/20180711111903_create_dlm_facets.foreman_dlm.rb +++ b/db/migrate/20180711111903_create_dlm_facets.foreman_dlm.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateDlmFacets < ActiveRecord::Migration[5.1] def change create_table :dlm_facets do |t| diff --git a/db/migrate/20180713113208_update_permissions_for_scoped_models.rb b/db/migrate/20180713113208_update_permissions_for_scoped_models.rb index cf0f262..27f9ab5 100644 --- a/db/migrate/20180713113208_update_permissions_for_scoped_models.rb +++ b/db/migrate/20180713113208_update_permissions_for_scoped_models.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class UpdatePermissionsForScopedModels < ActiveRecord::Migration[5.1] class FakePermission < ApplicationRecord self.table_name = 'permissions' diff --git a/foreman_dlm.gemspec b/foreman_dlm.gemspec index aef9dd4..2d1fb8f 100644 --- a/foreman_dlm.gemspec +++ b/foreman_dlm.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path('lib/foreman_dlm/version', __dir__) Gem::Specification.new do |s| @@ -11,16 +13,16 @@ Gem::Specification.new do |s| # also update locale/gemspec.rb s.description = 'Adds a Distributed Lock Manager to Foreman. This enables painless system updates for clusters.' + s.required_ruby_version = '>= 2.5', '< 4' + s.files = Dir['{app,config,db,lib,locale}/**/*', 'contrib/systemd/*'] + ['LICENSE', 'Rakefile', 'README.md'] s.test_files = Dir['test/**/*'] s.metadata = { 'rubygems_mfa_required' => 'true', - 'is_foreman_plugin' => 'true' + 'is_foreman_plugin' => 'true', } s.add_development_dependency 'rdoc' - s.add_development_dependency 'rubocop', '~> 1.25.0' - s.add_development_dependency 'rubocop-performance', '~> 1.13.0' - s.add_development_dependency 'rubocop-rails', '~> 2.9.1' + s.add_development_dependency 'theforeman-rubocop', '~> 0.1.2' end diff --git a/lib/foreman_dlm.rb b/lib/foreman_dlm.rb index a432fab..d2ad755 100644 --- a/lib/foreman_dlm.rb +++ b/lib/foreman_dlm.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'foreman_dlm/engine' module ForemanDlm diff --git a/lib/foreman_dlm/engine.rb b/lib/foreman_dlm/engine.rb index 54ec75b..a223f85 100644 --- a/lib/foreman_dlm/engine.rb +++ b/lib/foreman_dlm/engine.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm class Engine < ::Rails::Engine engine_name 'foreman_dlm' @@ -22,11 +24,11 @@ class Engine < ::Rails::Engine settings do category(:general) do setting('dlm_stale_time', - type: :integer, - default: 4, - description: N_('Number of hours after which locked Distributed Lock is stale'), - full_name: N_('Distributed Lock stale time'), - validate: { numericality: { greater_than: 0 } }) + type: :integer, + default: 4, + description: N_('Number of hours after which locked Distributed Lock is stale'), + full_name: N_('Distributed Lock stale time'), + validate: { numericality: { greater_than: 0 } }) end end @@ -34,25 +36,25 @@ class Engine < ::Rails::Engine security_block :foreman_dlm do permission :view_dlmlocks, { :'foreman_dlm/dlmlocks' => [:index, :show, :auto_complete_search], - :'api/v2/dlmlocks' => [:index, :show] + :'api/v2/dlmlocks' => [:index, :show], }, :resource_type => 'ForemanDlm::Dlmlock' permission :create_dlmlocks, { - :'api/v2/dlmlocks' => [:create] + :'api/v2/dlmlocks' => [:create], }, :resource_type => 'ForemanDlm::Dlmlock' permission :edit_dlmlocks, { :'foreman_dlm/dlmlocks' => [:release, :enable, :disable], - :'api/v2/dlmlocks' => [:update, :acquire, :release] + :'api/v2/dlmlocks' => [:update, :acquire, :release], }, :resource_type => 'ForemanDlm::Dlmlock' permission :destroy_dlmlocks, { :'foreman_dlm/dlmlocks' => [:destroy], - :'api/v2/dlmlocks' => [:destroy] + :'api/v2/dlmlocks' => [:destroy], }, :resource_type => 'ForemanDlm::Dlmlock' permission :view_dlmlock_events, { - :'api/v2/dlmlock_events' => [:index] + :'api/v2/dlmlock_events' => [:index], }, :resource_type => 'ForemanDlm::DlmlockEvent' end @@ -62,14 +64,14 @@ class Engine < ::Rails::Engine :edit_dlmlocks, :destroy_dlmlocks, :view_dlmlock_events], - 'Role granting full access permissions to distributed locks' + 'Role granting full access permissions to distributed locks' # add menu entry menu :top_menu, :foreman_dlm_dlmlocks, - url_hash: { controller: :'foreman_dlm/dlmlocks', action: :index }, - caption: N_('Distributed Locks'), - parent: :monitor_menu, - after: :audits + url_hash: { controller: :'foreman_dlm/dlmlocks', action: :index }, + caption: N_('Distributed Locks'), + parent: :monitor_menu, + after: :audits # Dlm Facet register_facet(ForemanDlm::DlmFacet, :dlm_facet) do @@ -81,9 +83,9 @@ class Engine < ::Rails::Engine # extend host show page extend_page('hosts/show') do |context| context.add_pagelet :main_tabs, - :name => N_('Locks'), - :partial => 'hosts/dlmlocks_tab', - :onlyif => proc { |host| host.dlm_facet } + :name => N_('Locks'), + :partial => 'hosts/dlmlocks_tab', + :onlyif => proc { |host| host.dlm_facet } end end end diff --git a/lib/foreman_dlm/version.rb b/lib/foreman_dlm/version.rb index ca7ed17..ed5e1c7 100644 --- a/lib/foreman_dlm/version.rb +++ b/lib/foreman_dlm/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ForemanDlm - VERSION = '2.0.0'.freeze + VERSION = '2.0.0' end diff --git a/lib/tasks/dlmlock_events.rake b/lib/tasks/dlmlock_events.rake index ed2d020..acd1676 100644 --- a/lib/tasks/dlmlock_events.rake +++ b/lib/tasks/dlmlock_events.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + desc <<-TASK_DESCRIPTION Expire lock events automatically diff --git a/lib/tasks/foreman_dlm_tasks.rake b/lib/tasks/foreman_dlm_tasks.rake index 6137c0b..f48e930 100644 --- a/lib/tasks/foreman_dlm_tasks.rake +++ b/lib/tasks/foreman_dlm_tasks.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rake/testtask' # Tests @@ -12,24 +14,4 @@ namespace :test do end end -namespace :foreman_dlm do - task :rubocop do - begin - require 'rubocop/rake_task' - RuboCop::RakeTask.new(:rubocop_foreman_dlm) do |task| - task.patterns = ["#{ForemanDlm::Engine.root}/app/**/*.rb", - "#{ForemanDlm::Engine.root}/lib/**/*.rb", - "#{ForemanDlm::Engine.root}/test/**/*.rb"] - end - rescue StandardError - puts 'Rubocop not loaded.' - end - - Rake::Task['rubocop_foreman_dlm'].invoke - end -end - Rake::Task[:test].enhance ['test:foreman_dlm'] - -load 'tasks/jenkins.rake' -Rake::Task['jenkins:unit'].enhance ['test:foreman_dlm', 'foreman_dlm:rubocop'] if Rake::Task.task_defined?(:'jenkins:unit') diff --git a/locale/gemspec.rb b/locale/gemspec.rb index 70ffe58..bc8d01f 100644 --- a/locale/gemspec.rb +++ b/locale/gemspec.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + # Matches foreman_dlm.gemspec -_('TODO: Description of ForemanDlm.') +_('Adds a Distributed Lock Manager to Foreman. This enables painless system updates for clusters.') diff --git a/test/controllers/api/v2/dlmlocks_controller_test.rb b/test/controllers/api/v2/dlmlocks_controller_test.rb index 1acba69..730d915 100644 --- a/test/controllers/api/v2/dlmlocks_controller_test.rb +++ b/test/controllers/api/v2/dlmlocks_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_plugin_helper' class Api::V2::DlmlocksControllerTest < ActionController::TestCase @@ -33,7 +35,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase assert dlmlock assert_equal valid_attrs['name'], dlmlock.name assert_equal valid_attrs['type'], dlmlock.type - assert_equal true, dlmlock.enabled + assert dlmlock.enabled assert_nil dlmlock.host end end @@ -47,7 +49,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase assert_not_empty body assert_equal dlmlock.name, body['name'] assert_equal dlmlock.type, body['type'] - assert_equal true, body['enabled'] + assert body['enabled'] assert_equal host1.id, body['host_id'] end @@ -59,7 +61,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase assert_not_empty body assert_equal dlmlock.name, body['name'] assert_equal dlmlock.type, body['type'] - assert_equal false, body['enabled'] + assert_not body['enabled'] assert_nil body['host_id'] end @@ -91,7 +93,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase dlmlock.reload assert_equal valid_attrs['name'], dlmlock.name assert_equal valid_attrs['type'], dlmlock.type - assert_equal false, dlmlock.enabled + assert_not dlmlock.enabled assert_equal host1.id, dlmlock.host_id end end @@ -181,7 +183,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase assert_not_empty body assert_equal dlmlock.name, body['name'] assert_equal dlmlock.type, body['type'] - assert_equal true, body['enabled'] + assert body['enabled'] assert_nil body['host_id'] assert_nil body['host'] end @@ -194,12 +196,12 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase assert_not_empty body assert_equal dlmlock.name, body['name'] assert_equal dlmlock.type, body['type'] - assert_equal true, body['enabled'] + assert body['enabled'] assert_equal host1.id, body['host_id'] host = body['host'] assert host assert_equal host1.name, host['name'] - assert_equal true, host['self'] + assert host['self'] end test 'should show individual acquired lock by other' do @@ -210,12 +212,12 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase assert_not_empty body assert_equal dlmlock.name, body['name'] assert_equal dlmlock.type, body['type'] - assert_equal true, body['enabled'] + assert body['enabled'] assert_equal host2.id, body['host_id'] host = body['host'] assert host assert_equal host2.name, host['name'] - assert_equal false, host['self'] + assert_not host['self'] end test 'should update checkin time' do @@ -378,7 +380,7 @@ class Api::V2::DlmlocksControllerTest < ActionController::TestCase def valid_attrs { 'name' => 'testlock', - 'type' => 'ForemanDlm::Dlmlock::Update' + 'type' => 'ForemanDlm::Dlmlock::Update', } end diff --git a/test/controllers/api/v2/dlmlocks_dlmlock_events_controller_test.rb b/test/controllers/api/v2/dlmlocks_dlmlock_events_controller_test.rb index acf406a..ad1b8eb 100644 --- a/test/controllers/api/v2/dlmlocks_dlmlock_events_controller_test.rb +++ b/test/controllers/api/v2/dlmlocks_dlmlock_events_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_plugin_helper' class Api::V2::DlmlockEventsControllerTest < ActionController::TestCase diff --git a/test/controllers/api/v2/hosts_controller_test.rb b/test/controllers/api/v2/hosts_controller_test.rb index 957f699..173677b 100644 --- a/test/controllers/api/v2/hosts_controller_test.rb +++ b/test/controllers/api/v2/hosts_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_plugin_helper' class Api::V2::HostsControllerTest < ActionController::TestCase diff --git a/test/controllers/find_host_by_client_cert_test.rb b/test/controllers/find_host_by_client_cert_test.rb index d808e81..dbfe73e 100644 --- a/test/controllers/find_host_by_client_cert_test.rb +++ b/test/controllers/find_host_by_client_cert_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_plugin_helper' class FindHostByClientCertTest < ActionController::TestCase @@ -62,7 +64,7 @@ def described_class get :index - assert_equal false, @controller.send(:require_client_cert_or_login) + assert_not @controller.send(:require_client_cert_or_login) assert_nil @controller.detected_host end @@ -73,7 +75,7 @@ def described_class get :index - assert_equal false, @controller.send(:require_client_cert_or_login) + assert_not @controller.send(:require_client_cert_or_login) assert_nil @controller.detected_host end @@ -83,7 +85,7 @@ def described_class get :index - assert_equal false, @controller.send(:require_client_cert_or_login) + assert_not @controller.send(:require_client_cert_or_login) assert_nil @controller.detected_host end end diff --git a/test/controllers/foreman_dlm/dlmlocks_test.rb b/test/controllers/foreman_dlm/dlmlocks_test.rb index 1b67a1a..4272b9a 100644 --- a/test/controllers/foreman_dlm/dlmlocks_test.rb +++ b/test/controllers/foreman_dlm/dlmlocks_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_plugin_helper' module ForemanDlm diff --git a/test/controllers/hosts_controller_test.rb b/test/controllers/hosts_controller_test.rb index 36f361e..df4335e 100644 --- a/test/controllers/hosts_controller_test.rb +++ b/test/controllers/hosts_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_plugin_helper' class HostsControllerTest < ActionController::TestCase @@ -7,6 +9,6 @@ class HostsControllerTest < ActionController::TestCase FactoryBot.create_list(:dlmlock, 2, host: host) get :show, params: { :id => host.to_param }, session: set_session_user assert_response :success - assert @response.body.match(/id='pagelet-id-locks'/) + assert_match(/id='pagelet-id-locks'/, @response.body) end end diff --git a/test/factories/dlm_facets.rb b/test/factories/dlm_facets.rb index cd6dece..852077c 100644 --- a/test/factories/dlm_facets.rb +++ b/test/factories/dlm_facets.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :dlm_facet, class: 'ForemanDlm::DlmFacet' do sequence(:last_checkin_at) { |n| n.minutes.ago } diff --git a/test/factories/dlmlock.rb b/test/factories/dlmlock.rb index 3fa155d..b2d9810 100644 --- a/test/factories/dlmlock.rb +++ b/test/factories/dlmlock.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :dlmlock, class: ::ForemanDlm::Dlmlock::Update do sequence(:name) { |n| "Lock #{n}" } diff --git a/test/factories/dlmlock_events.rb b/test/factories/dlmlock_events.rb index 1f0cff0..d6f52cb 100644 --- a/test/factories/dlmlock_events.rb +++ b/test/factories/dlmlock_events.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :dlmlock_event, class: ::ForemanDlm::DlmlockEvent do dlmlock diff --git a/test/factories/host.rb b/test/factories/host.rb index 0a20601..ed16966 100644 --- a/test/factories/host.rb +++ b/test/factories/host.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.modify do factory :host do trait :with_dlm_facet do diff --git a/test/integration/foreman_dlm/dlmlocks_test.rb b/test/integration/foreman_dlm/dlmlocks_test.rb index 041ffef..bd091c4 100644 --- a/test/integration/foreman_dlm/dlmlocks_test.rb +++ b/test/integration/foreman_dlm/dlmlocks_test.rb @@ -2,6 +2,7 @@ require 'test_plugin_helper' require 'integration_test_helper' +require 'integration_test_plugin_helper' class DlmlocksTest < IntegrationTestWithJavascript setup do @@ -14,15 +15,16 @@ class DlmlocksTest < IntegrationTestWithJavascript end test 'the search bar has autocomplete' do - skip if Gem::Version.new(Foreman::Version.new.notag) < Gem::Version.new('1.20') FactoryBot.create_list(:dlmlock, 10) visit foreman_dlm_dlmlocks_path - search_bar = page.first('#search-bar') + search_bar = page.first('.foreman-search-bar') search_bar.first('input').set('ho') - list = search_bar.find_all('a.dropdown-item').map(&:text) + autocomplete_list = page.first('div[data-ouia-component-id="search-autocomplete-menu"]') + list = autocomplete_list.find_all('span.pf-c-menu__item-text').map(&:text) + assert_includes list, 'host' end end diff --git a/test/integration_test_plugin_helper.rb b/test/integration_test_plugin_helper.rb new file mode 100644 index 0000000..8f2bc08 --- /dev/null +++ b/test/integration_test_plugin_helper.rb @@ -0,0 +1,11 @@ +# Custom Selenium test config +# see https://github.com/SeleniumHQ/selenium/issues/12841 +Capybara.register_driver :selenium_chrome do |app| + options = Selenium::WebDriver::Chrome::Options.new + options.args << '--disable-gpu' + options.args << '--no-sandbox' + options.args << '--window-size=1024,768' + options.args << '--remote-debugging-pipe' + options.args << '--headless' unless ENV['DEBUG_JS_TEST'] == '1' + Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) +end diff --git a/test/jobs/refresh_dlmlock_status_test.rb b/test/jobs/refresh_dlmlock_status_test.rb index e74ce6d..1b927c2 100644 --- a/test/jobs/refresh_dlmlock_status_test.rb +++ b/test/jobs/refresh_dlmlock_status_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_plugin_helper' class RefreshDlmlockStatusTest < ActiveJob::TestCase diff --git a/test/models/foreman_dlm/dlm_facet_test.rb b/test/models/foreman_dlm/dlm_facet_test.rb index aa0208b..f1f5963 100644 --- a/test/models/foreman_dlm/dlm_facet_test.rb +++ b/test/models/foreman_dlm/dlm_facet_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_plugin_helper' module ForemanDlm diff --git a/test/models/foreman_dlm/dlmlock_event_test.rb b/test/models/foreman_dlm/dlmlock_event_test.rb index eff992a..3db9f49 100644 --- a/test/models/foreman_dlm/dlmlock_event_test.rb +++ b/test/models/foreman_dlm/dlmlock_event_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_plugin_helper' module ForemanDlm diff --git a/test/models/foreman_dlm/dlmlock_test.rb b/test/models/foreman_dlm/dlmlock_test.rb index 1634655..ed2a59b 100644 --- a/test/models/foreman_dlm/dlmlock_test.rb +++ b/test/models/foreman_dlm/dlmlock_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_plugin_helper' module ForemanDlm @@ -45,10 +47,10 @@ def callback2 let(:dlmlock) { FactoryBot.create(:dlmlock) } test 'should be enabled and unlocked' do - assert_equal true, dlmlock.enabled? - assert_equal false, dlmlock.disabled? - assert_equal false, dlmlock.locked? - assert_equal false, dlmlock.taken? + assert dlmlock.enabled? + assert_not dlmlock.disabled? + assert_not dlmlock.locked? + assert_not dlmlock.taken? end test 'can be acquired' do @@ -100,21 +102,21 @@ def callback2 let(:dlmlock) { FactoryBot.create(:dlmlock, :enabled => false) } test 'should be disabled and unlocked' do - assert_equal false, dlmlock.enabled? - assert_equal true, dlmlock.disabled? - assert_equal false, dlmlock.locked? - assert_equal false, dlmlock.taken? + assert_not dlmlock.enabled? + assert dlmlock.disabled? + assert_not dlmlock.locked? + assert_not dlmlock.taken? end test 'can not be acquired' do assert_nil dlmlock.host - assert_equal false, dlmlock.acquire!(host1) + assert_not dlmlock.acquire!(host1) assert_nil dlmlock.reload.host end test 'can not be released' do assert_nil dlmlock.host - assert_equal false, dlmlock.release!(host1) + assert_not dlmlock.release!(host1) assert_nil dlmlock.reload.host end @@ -122,8 +124,8 @@ def callback2 host = HostWithCallbacks.new host.name = 'test.example.com' host.save - assert_equal false, dlmlock.release!(host) - assert_equal [], host.callbacks + assert_not dlmlock.release!(host) + assert_empty host.callbacks end end @@ -131,12 +133,12 @@ def callback2 let(:dlmlock) { FactoryBot.create(:dlmlock, :host => host1) } test 'should be enabled and locked' do - assert_equal true, dlmlock.enabled? - assert_equal false, dlmlock.disabled? - assert_equal true, dlmlock.locked? - assert_equal true, dlmlock.taken? - assert_equal true, dlmlock.locked_by?(host1) - assert_equal true, dlmlock.acquired_by?(host1) + assert dlmlock.enabled? + assert_not dlmlock.disabled? + assert dlmlock.locked? + assert dlmlock.taken? + assert dlmlock.locked_by?(host1) + assert dlmlock.acquired_by?(host1) end test 'can be acquired by owner' do @@ -147,7 +149,7 @@ def callback2 test 'can not be acquired by other host' do assert_equal host1, dlmlock.host - assert_equal false, dlmlock.acquire!(host2) + assert_not dlmlock.acquire!(host2) assert_equal host1, dlmlock.reload.host end @@ -159,7 +161,7 @@ def callback2 test 'can not be released by other host' do assert_equal host1, dlmlock.host - assert_equal false, dlmlock.release!(host2) + assert_not dlmlock.release!(host2) assert_equal host1, dlmlock.reload.host end @@ -196,16 +198,16 @@ def callback2 assert host1_with_callbacks assert host2_with_callbacks dlmlock.update(:host => host1_with_callbacks) - assert_equal false, dlmlock.release!(host2_with_callbacks) - assert_equal [], host1_with_callbacks.callbacks - assert_equal [], host2_with_callbacks.callbacks + assert_not dlmlock.release!(host2_with_callbacks) + assert_empty host1_with_callbacks.callbacks + assert_empty host2_with_callbacks.callbacks end test 'triggers no callbacks on acquiry attempt by owner' do assert host1_with_callbacks dlmlock.update(:host => host1_with_callbacks) assert dlmlock.acquire!(host1_with_callbacks) - assert_equal [], host1_with_callbacks.callbacks + assert_empty host1_with_callbacks.callbacks end end diff --git a/test/models/host_managed_test.rb b/test/models/host_managed_test.rb index 5814c50..bfeafba 100644 --- a/test/models/host_managed_test.rb +++ b/test/models/host_managed_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_plugin_helper' module Host diff --git a/test/models/host_monitoring_test.rb b/test/models/host_monitoring_test.rb index 8dcf80a..f2a2a53 100644 --- a/test/models/host_monitoring_test.rb +++ b/test/models/host_monitoring_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_plugin_helper' class HostMonitoringTest < ActiveSupport::TestCase diff --git a/test/models/host_status/dlmlock_status_test.rb b/test/models/host_status/dlmlock_status_test.rb index fb38b61..1db59b8 100644 --- a/test/models/host_status/dlmlock_status_test.rb +++ b/test/models/host_status/dlmlock_status_test.rb @@ -32,14 +32,14 @@ class DlmlockStatusTest < ActiveSupport::TestCase status = host.get_status(HostStatus::DlmlockStatus) assert_not_empty host.dlmlocks - assert_equal true, status.relevant? + assert status.relevant? end test 'should return false if host has no dlmlocks' do status = host.get_status(HostStatus::DlmlockStatus) assert_empty host.dlmlocks - assert_equal false, status.relevant? + assert_not status.relevant? end end end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 938d23f..ef671cd 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_plugin_helper' class UserTest < ActiveSupport::TestCase diff --git a/test/test_plugin_helper.rb b/test/test_plugin_helper.rb index 67beb9e..73fddc4 100644 --- a/test/test_plugin_helper.rb +++ b/test/test_plugin_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This calls the main test_helper in Foreman-core require 'test_helper' diff --git a/test/unit/foreman_dlm/access_permissions_test.rb b/test/unit/foreman_dlm/access_permissions_test.rb new file mode 100644 index 0000000..95c1d4f --- /dev/null +++ b/test/unit/foreman_dlm/access_permissions_test.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'test_plugin_helper' +require 'unit/shared/access_permissions_test_base' + +# Permissions are added in AccessPermissions with lists of controllers and +# actions that they enable access to. For non-admin users, we need to test +# that there are permissions available that cover every controller action, else +# it can't be delegated and this will lead to parts of the application that +# aren't functional for non-admin users. +# +# In particular, it's important that actions for AJAX requests are added to +# an appropriate permission so views using those requests function. +class AccessPermissionsTest < ActiveSupport::TestCase + include AccessPermissionsTestBase + + check_routes(ForemanDlm::Engine.routes, []) +end