diff --git a/Gemfile.lock b/Gemfile.lock index acec86151..009a13ae3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -358,7 +358,7 @@ GEM omniauth-oauth2 (>= 1.4.0) openssl (2.1.2) parallel (1.19.2) - parser (2.7.1.5) + parser (2.7.2.0) ast (~> 2.4.1) pg (0.21.0) pluginator (1.5.0) @@ -427,7 +427,7 @@ GEM rb-inotify (0.10.0) ffi (~> 1.0) rchardet (1.8.0) - regexp_parser (1.8.0) + regexp_parser (1.8.2) rest-client (2.0.2) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) @@ -452,16 +452,16 @@ GEM rspec-support (~> 3.9.0) rspec-support (3.9.3) rszr (0.5.2) - rubocop (0.92.0) + rubocop (0.93.1) parallel (~> 1.10) parser (>= 2.7.1.5) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.7) + regexp_parser (>= 1.8) rexml - rubocop-ast (>= 0.5.0) + rubocop-ast (>= 0.6.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (0.5.0) + rubocop-ast (1.0.0) parser (>= 2.7.1.5) rubocop-performance (1.8.1) rubocop (>= 0.87.0) @@ -470,8 +470,9 @@ GEM activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 0.87.0) - rubocop-rspec (1.43.2) + rubocop-rspec (1.44.1) rubocop (~> 0.87) + rubocop-ast (>= 0.7.1) ruby-progressbar (1.10.1) ruby-saml (1.10.2) nokogiri (>= 1.5.10) diff --git a/app/controllers/monitoring_controller.rb b/app/controllers/monitoring_controller.rb index 90e16311c..ddd587960 100644 --- a/app/controllers/monitoring_controller.rb +++ b/app/controllers/monitoring_controller.rb @@ -104,7 +104,7 @@ curl http://localhost/api/v1/monitoring/health_check?token=XXX handler_attempts_map = {} failed_jobs.order(:created_at).limit(10).each do |job| - job_name = if job.class.name == 'Delayed::Backend::ActiveRecord::Job'.freeze && job.payload_object.respond_to?(:job_data) + job_name = if job.instance_of?(Delayed::Backend::ActiveRecord::Job) && job.payload_object.respond_to?(:job_data) job.payload_object.job_data['job_class'] else job.name diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index a90f4baa5..0630be08f 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -80,7 +80,7 @@ class TicketsController < ApplicationController # POST /api/v1/tickets def create customer = {} - if params[:customer].class == ActionController::Parameters + if params[:customer].instance_of?(ActionController::Parameters) customer = params[:customer] params.delete(:customer) end diff --git a/app/models/avatar.rb b/app/models/avatar.rb index 4f58bce3a..562e0d4eb 100644 --- a/app/models/avatar.rb +++ b/app/models/avatar.rb @@ -105,7 +105,7 @@ add avatar by url # fetch image based on http url if data[:url].present? - if data[:url].class == Tempfile + if data[:url].instance_of?(Tempfile) logger.info "Reading image from tempfile '#{data[:url].inspect}'" content = data[:url].read filename = data[:url].path diff --git a/app/models/channel/email_build.rb b/app/models/channel/email_build.rb index f0d9a85e2..6f78de39e 100644 --- a/app/models/channel/email_build.rb +++ b/app/models/channel/email_build.rb @@ -88,7 +88,7 @@ generate email with S/MIME # place to add inline attachments related to html alternative attr[:attachments]&.each do |attachment| - next if attachment.class == Hash + next if attachment.instance_of?(Hash) next if attachment.preferences['Content-ID'].blank? attachment = Mail::Part.new do @@ -107,7 +107,7 @@ generate email with S/MIME # add attachments attr[:attachments]&.each do |attachment| - if attachment.class == Hash + if attachment.instance_of?(Hash) attachment['content-id'] = nil mail.attachments[attachment[:filename]] = attachment else diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 0a27bbc52..11908e981 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -678,11 +678,12 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again filename = file.header[:content_disposition].try(:filename) rescue begin - if file.header[:content_disposition].to_s =~ /(filename|name)(\*{0,1})="(.+?)"/i + case file.header[:content_disposition].to_s + when /(filename|name)(\*{0,1})="(.+?)"/i filename = $3 - elsif file.header[:content_disposition].to_s =~ /(filename|name)(\*{0,1})='(.+?)'/i + when /(filename|name)(\*{0,1})='(.+?)'/i filename = $3 - elsif file.header[:content_disposition].to_s =~ /(filename|name)(\*{0,1})=(.+?);/i + when /(filename|name)(\*{0,1})=(.+?);/i filename = $3 end rescue @@ -691,11 +692,12 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again end begin - if file.header[:content_disposition].to_s =~ /(filename|name)(\*{0,1})="(.+?)"/i + case file.header[:content_disposition].to_s + when /(filename|name)(\*{0,1})="(.+?)"/i filename = $3 - elsif file.header[:content_disposition].to_s =~ /(filename|name)(\*{0,1})='(.+?)'/i + when /(filename|name)(\*{0,1})='(.+?)'/i filename = $3 - elsif file.header[:content_disposition].to_s =~ /(filename|name)(\*{0,1})=(.+?);/i + when /(filename|name)(\*{0,1})=(.+?);/i filename = $3 end rescue @@ -704,11 +706,12 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again # as fallback, use raw values if filename.blank? - if headers_store['Content-Disposition'].to_s =~ /(filename|name)(\*{0,1})="(.+?)"/i + case headers_store['Content-Disposition'].to_s + when /(filename|name)(\*{0,1})="(.+?)"/i filename = $3 - elsif headers_store['Content-Disposition'].to_s =~ /(filename|name)(\*{0,1})='(.+?)'/i + when /(filename|name)(\*{0,1})='(.+?)'/i filename = $3 - elsif headers_store['Content-Disposition'].to_s =~ /(filename|name)(\*{0,1})=(.+?);/i + when /(filename|name)(\*{0,1})=(.+?);/i filename = $3 end end diff --git a/app/models/concerns/can_csv_import.rb b/app/models/concerns/can_csv_import.rb index 32e669c6f..951476354 100644 --- a/app/models/concerns/can_csv_import.rb +++ b/app/models/concerns/can_csv_import.rb @@ -247,8 +247,8 @@ returns record_attributes_with_association_names = record.attributes_with_association_names records_attributes_with_association_names.push record_attributes_with_association_names record_attributes_with_association_names.each do |key, value| - next if value.class == ActiveSupport::HashWithIndifferentAccess - next if value.class == Hash + next if value.instance_of?(ActiveSupport::HashWithIndifferentAccess) + next if value.instance_of?(Hash) next if csv_attributes_ignored&.include?(key.to_sym) next if key.end_with?('_id') next if key.end_with?('_ids') @@ -269,11 +269,11 @@ returns position = -1 header.each do |key| position += 1 - if record[key].class == ActiveSupport::TimeWithZone + if record[key].instance_of?(ActiveSupport::TimeWithZone) row.push record[key].iso8601 next end - if record[key].class == Array + if record[key].instance_of?(Array) entry_count = -2 record[key].each do |entry| entry_count += 1 diff --git a/app/models/cti/log.rb b/app/models/cti/log.rb index c7e4caca2..14cfa51d7 100644 --- a/app/models/cti/log.rb +++ b/app/models/cti/log.rb @@ -356,7 +356,7 @@ Cti::Log.process( user = params['user'] queue = params['queue'] call_id = params['callId'] || params['call_id'] - if user.class == Array + if user.instance_of?(Array) user = user.join(', ') end diff --git a/app/models/observer/sla/ticket_rebuild_escalation.rb b/app/models/observer/sla/ticket_rebuild_escalation.rb index ea323c230..07d35c4a3 100644 --- a/app/models/observer/sla/ticket_rebuild_escalation.rb +++ b/app/models/observer/sla/ticket_rebuild_escalation.rb @@ -25,7 +25,7 @@ class Observer::Sla::TicketRebuildEscalation < ActiveRecord::Observer # check if condition has changed changed = false - fields_to_check = if record.class == Sla + fields_to_check = if record.instance_of?(Sla) %w[condition calendar_id first_response_time update_time solution_time] else %w[timezone business_hours default ical_url public_holidays] diff --git a/app/models/observer/ticket/article/communicate_twitter/background_job.rb b/app/models/observer/ticket/article/communicate_twitter/background_job.rb index b442c35ce..582dfa575 100644 --- a/app/models/observer/ticket/article/communicate_twitter/background_job.rb +++ b/app/models/observer/ticket/article/communicate_twitter/background_job.rb @@ -72,7 +72,7 @@ class Observer::Ticket::Article::CommunicateTwitter::BackgroundJob end # regular tweet - elsif tweet.class == Twitter::Tweet + elsif tweet.instance_of?(Twitter::Tweet) tweet_type = 'Tweet' article.from = "@#{tweet.user.screen_name}" if tweet.user_mentions diff --git a/app/models/ticket.rb b/app/models/ticket.rb index faed6e6e3..cbb3cdb9c 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -601,7 +601,7 @@ condition example # validate value / allow blank but only if pre_condition exists and is not specific if !selector.key?('value') || - (selector['value'].class == Array && selector['value'].respond_to?(:blank?) && selector['value'].blank?) || + (selector['value'].instance_of?(Array) && selector['value'].respond_to?(:blank?) && selector['value'].blank?) || (selector['operator'].start_with?('contains') && selector['value'].respond_to?(:blank?) && selector['value'].blank?) return nil if selector['pre_condition'].nil? return nil if selector['pre_condition'].respond_to?(:blank?) && selector['pre_condition'].blank? diff --git a/app/models/transaction/slack.rb b/app/models/transaction/slack.rb index 7ede4fc48..072d0da41 100644 --- a/app/models/transaction/slack.rb +++ b/app/models/transaction/slack.rb @@ -134,7 +134,7 @@ class Transaction::Slack end # check action - if local_config['types'].class == Array + if local_config['types'].instance_of?(Array) hit = false local_config['types'].each do |type| next if type.to_s != @item[:type].to_s @@ -148,7 +148,7 @@ class Transaction::Slack end # check group - if local_config['group_ids'].class == Array + if local_config['group_ids'].instance_of?(Array) hit = false local_config['group_ids'].each do |group_id| next if group_id.to_s != ticket.group_id.to_s diff --git a/app/models/translation.rb b/app/models/translation.rb index 868c9e802..f82594425 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -226,7 +226,7 @@ or def self.timestamp(locale, timezone, timestamp) - if timestamp.class == String + if timestamp.instance_of?(String) begin timestamp_parsed = Time.zone.parse(timestamp) return timestamp.to_s if !timestamp_parsed @@ -272,7 +272,7 @@ or def self.date(locale, date) - if date.class == String + if date.instance_of?(String) begin date_parsed = Date.parse(date) return date.to_s if !date_parsed diff --git a/db/migrate/20171023000001_fixed_store_upgrade_ror_45.rb b/db/migrate/20171023000001_fixed_store_upgrade_ror_45.rb index 83212d37d..4a0d0d7d7 100644 --- a/db/migrate/20171023000001_fixed_store_upgrade_ror_45.rb +++ b/db/migrate/20171023000001_fixed_store_upgrade_ror_45.rb @@ -34,7 +34,7 @@ class FixedStoreUpgradeRor45 < ActiveRecord::Migration[5.0] end def cleanup(value) - if value.class == ActionController::Parameters + if value.instance_of?(ActionController::Parameters) value = value.permit!.to_h end return value if value.class != ActiveSupport::HashWithIndifferentAccess && value.class != Hash diff --git a/db/migrate/20180410000001_cleanup_user_preferences_notification_sound2.rb b/db/migrate/20180410000001_cleanup_user_preferences_notification_sound2.rb index 10e860cd7..936a73aef 100644 --- a/db/migrate/20180410000001_cleanup_user_preferences_notification_sound2.rb +++ b/db/migrate/20180410000001_cleanup_user_preferences_notification_sound2.rb @@ -1,10 +1,10 @@ class CleanupUserPreferencesNotificationSound2 < ActiveRecord::Migration[5.1] def local_to_h!(value) - if value.class == ActionController::Parameters + if value.instance_of?(ActionController::Parameters) value = value.permit!.to_h end - if value.class == Hash || value.class == ActiveSupport::HashWithIndifferentAccess + if value.instance_of?(Hash) || value.instance_of?(ActiveSupport::HashWithIndifferentAccess) value.each_key do |local_key| value[local_key] = local_to_h!(value[local_key]) end diff --git a/db/migrate/20180806000001_fixed_twitter_ticket_article_preferences7.rb b/db/migrate/20180806000001_fixed_twitter_ticket_article_preferences7.rb index 71dad8644..b855332d3 100644 --- a/db/migrate/20180806000001_fixed_twitter_ticket_article_preferences7.rb +++ b/db/migrate/20180806000001_fixed_twitter_ticket_article_preferences7.rb @@ -16,11 +16,11 @@ class FixedTwitterTicketArticlePreferences7 < ActiveRecord::Migration[5.0] next if value.class != ActiveSupport::HashWithIndifferentAccess value.each do |sub_key, sub_level| - if sub_level.class == NilClass + if sub_level.instance_of?(NilClass) value[sub_key] = nil next end - if sub_level.class == Twitter::Place || sub_level.class == Twitter::Geo + if sub_level.instance_of?(Twitter::Place) || sub_level.instance_of?(Twitter::Geo) value[sub_key] = sub_level.to_h changed = true next diff --git a/lib/core_ext/active_record/connection_adapters/postgresql/schema_statements.rb b/lib/core_ext/active_record/connection_adapters/postgresql/schema_statements.rb index 8d5473bea..ae9bc6ee2 100644 --- a/lib/core_ext/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/lib/core_ext/active_record/connection_adapters/postgresql/schema_statements.rb @@ -10,7 +10,7 @@ module ActiveRecord index_name, index_type, index_columns, index_options, index_algorithm, index_using = add_index_options(table_name, column_name, options) column_names = index_columns.split ', ' - if column_names.class == Array + if column_names.instance_of?(Array) index_columns_new = [] column_names.each do |i| if i =~ /^"(name|login|locale|alias)"$/ || i.end_with?('name"') diff --git a/lib/html_sanitizer.rb b/lib/html_sanitizer.rb index c645a0656..ca7798904 100644 --- a/lib/html_sanitizer.rb +++ b/lib/html_sanitizer.rb @@ -324,7 +324,7 @@ cleanup html string: end # remove not needed new lines - if node.class == Nokogiri::XML::Text + if node.instance_of?(Nokogiri::XML::Text) if !node.parent || (node.parent.name != 'pre' && node.parent.name != 'code') # rubocop:disable Style/SoleNestedConditional content = node.content if content diff --git a/lib/idoit.rb b/lib/idoit.rb index 42a599379..a40a1d112 100644 --- a/lib/idoit.rb +++ b/lib/idoit.rb @@ -128,7 +128,7 @@ or with filter: raise "Can't fetch objects from #{url}: #{result.error}" if !result.success? # add link to idoit - if result.data['result'].class == Array + if result.data['result'].instance_of?(Array) result.data['result'].each do |item| next if !item['id'] diff --git a/lib/notification_factory/renderer.rb b/lib/notification_factory/renderer.rb index ad34237da..292a33a36 100644 --- a/lib/notification_factory/renderer.rb +++ b/lib/notification_factory/renderer.rb @@ -173,8 +173,8 @@ examples how to use private def convert_to_timezone(value) - return Translation.timestamp(@locale, @timezone, value) if value.class == ActiveSupport::TimeWithZone - return Translation.date(@locale, value) if value.class == Date + return Translation.timestamp(@locale, @timezone, value) if value.instance_of?(ActiveSupport::TimeWithZone) + return Translation.date(@locale, value) if value.instance_of?(Date) value end diff --git a/lib/push_messages.rb b/lib/push_messages.rb index fcb9d9ab1..5cdcc59ab 100644 --- a/lib/push_messages.rb +++ b/lib/push_messages.rb @@ -1,7 +1,7 @@ module PushMessages def self.enabled? - return true if Thread.current[:push_messages].class == Array + return true if Thread.current[:push_messages].instance_of?(Array) false end diff --git a/lib/twitter_sync.rb b/lib/twitter_sync.rb index d50e7df36..39dd0d919 100644 --- a/lib/twitter_sync.rb +++ b/lib/twitter_sync.rb @@ -122,7 +122,7 @@ class TwitterSync # normalize message message = {} - if tweet.class == Twitter::Tweet + if tweet.instance_of?(Twitter::Tweet) message = { type: 'tweet', text: tweet.text, @@ -610,11 +610,11 @@ or # replace Twitter::NullObject with nill to prevent elasticsearch index issue preferences.each do |key, value| - if value.class == Twitter::Place || value.class == Twitter::Geo + if value.instance_of?(Twitter::Place) || value.instance_of?(Twitter::Geo) preferences[key] = value.to_h next end - if value.class == Twitter::NullObject + if value.instance_of?(Twitter::NullObject) preferences[key] = nil next end @@ -622,11 +622,11 @@ or next if !value.is_a?(Hash) value.each do |sub_key, sub_level| - if sub_level.class == NilClass + if sub_level.instance_of?(NilClass) value[sub_key] = nil next end - if sub_level.class == Twitter::Place || sub_level.class == Twitter::Geo + if sub_level.instance_of?(Twitter::Place) || sub_level.instance_of?(Twitter::Geo) value[sub_key] = sub_level.to_h next end diff --git a/spec/db/migrate/issue_1905_exchange_login_from_remote_id_spec.rb b/spec/db/migrate/issue_1905_exchange_login_from_remote_id_spec.rb index c1514f6a4..bd156a6a9 100644 --- a/spec/db/migrate/issue_1905_exchange_login_from_remote_id_spec.rb +++ b/spec/db/migrate/issue_1905_exchange_login_from_remote_id_spec.rb @@ -19,7 +19,7 @@ RSpec.describe Issue1905ExchangeLoginFromRemoteId, type: :db_migration do } ) - expect(backend).to receive(:config).and_return(invalid_config) + expect(backend).to receive(:config).and_return(invalid_config) # rubocop:disable RSpec/StubbedMock allow(backend).to receive(:config).and_call_original migrate @@ -36,7 +36,7 @@ RSpec.describe Issue1905ExchangeLoginFromRemoteId, type: :db_migration do shared_examples 'irrelevant config' do it 'does not change the config' do - expect(backend).to receive(:config).and_return(config) + allow(backend).to receive(:config).and_return(config) expect(backend).not_to receive(:config=) migrate end diff --git a/spec/db/migrate/object_manager_attribute_date_remove_future_past_spec.rb b/spec/db/migrate/object_manager_attribute_date_remove_future_past_spec.rb index c279d6f31..73d96c458 100644 --- a/spec/db/migrate/object_manager_attribute_date_remove_future_past_spec.rb +++ b/spec/db/migrate/object_manager_attribute_date_remove_future_past_spec.rb @@ -14,8 +14,8 @@ RSpec.describe ObjectManagerAttributeDateRemoveFuturePast, type: :db_migration d # mock interfaces to save time # otherwise we would have to reseed the database - expect(ObjectManager::Attribute).to receive(:where).and_return([subject]) - expect(subject).to receive(:save!) + allow(ObjectManager::Attribute).to receive(:where).and_return([subject]) + allow(subject).to receive(:save!) migrate @@ -39,7 +39,7 @@ RSpec.describe ObjectManagerAttributeDateRemoveFuturePast, type: :db_migration d # mock interfaces to save time # otherwise we would have to reseed the database - expect(ObjectManager::Attribute).to receive(:where).and_return([subject]) + allow(ObjectManager::Attribute).to receive(:where).and_return([subject]) # expect(subject).to receive(:save!) expect { migrate }.not_to raise_error diff --git a/spec/jobs/search_index_job_spec.rb b/spec/jobs/search_index_job_spec.rb index ee7c1463b..32655b6da 100644 --- a/spec/jobs/search_index_job_spec.rb +++ b/spec/jobs/search_index_job_spec.rb @@ -4,20 +4,25 @@ RSpec.describe SearchIndexJob, type: :job do it 'calls search_index_update_backend on matching record' do user = create(:user) - expect(::User).to receive(:lookup).with(id: user.id).and_return(user) - expect(user).to receive(:search_index_update_backend) + allow(::User).to receive(:lookup).with(id: user.id).and_return(user) + allow(user).to receive(:search_index_update_backend) described_class.perform_now('User', user.id) + expect(user).to have_received(:search_index_update_backend) end it "doesn't perform for non existing records" do id = 9999 - expect(::User).to receive(:lookup).with(id: id).and_return(nil) + allow(::User).to receive(:lookup).with(id: id).and_return(nil) + allow(SearchIndexBackend).to receive(:add) + described_class.perform_now('User', id) + expect(SearchIndexBackend).not_to have_received(:add) end it 'retries on exception' do - expect(::User).to receive(:lookup).and_raise(RuntimeError) + allow(::User).to receive(:lookup).and_raise(RuntimeError) + described_class.perform_now('User', 1) expect(described_class).to have_been_enqueued end diff --git a/spec/lib/auth/developer_spec.rb b/spec/lib/auth/developer_spec.rb index 78f21f6df..243cb24dd 100644 --- a/spec/lib/auth/developer_spec.rb +++ b/spec/lib/auth/developer_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Auth::Developer do it "authenticates users with password 'test'" do allow(Setting).to receive(:get) - expect(Setting).to receive(:get).with('developer_mode').and_return(true) + allow(Setting).to receive(:get).with('developer_mode').and_return(true) result = instance.valid?(user, 'test') @@ -26,7 +26,7 @@ RSpec.describe Auth::Developer do it "doesn't authenticate if developer mode is off" do allow(Setting).to receive(:get) - expect(Setting).to receive(:get).with('developer_mode').and_return(false) + allow(Setting).to receive(:get).with('developer_mode').and_return(false) result = instance.valid?(user, password) @@ -36,7 +36,7 @@ RSpec.describe Auth::Developer do it "doesn't authenticate with correct password" do allow(Setting).to receive(:get) - expect(Setting).to receive(:get).with('developer_mode').and_return(true) + allow(Setting).to receive(:get).with('developer_mode').and_return(true) result = instance.valid?(user, password) diff --git a/spec/lib/auth/ldap_spec.rb b/spec/lib/auth/ldap_spec.rb index e02c63db5..f1befcbe7 100644 --- a/spec/lib/auth/ldap_spec.rb +++ b/spec/lib/auth/ldap_spec.rb @@ -14,10 +14,10 @@ RSpec.describe ::Auth::Ldap do it 'authenticates users' do allow(Setting).to receive(:get) - expect(Setting).to receive(:get).with('ldap_integration').and_return(true) + allow(Setting).to receive(:get).with('ldap_integration').and_return(true) ldap_user = double(valid?: true) - expect(::Ldap::User).to receive(:new).and_return(ldap_user) + allow(::Ldap::User).to receive(:new).and_return(ldap_user) result = instance.valid?(user, password) expect(result).to be true @@ -26,7 +26,7 @@ RSpec.describe ::Auth::Ldap do it 'authenticates via configurable user attributes' do allow(Setting).to receive(:get) - expect(Setting).to receive(:get).with('ldap_integration').and_return(true) + allow(Setting).to receive(:get).with('ldap_integration').and_return(true) instance = described_class.new( adapter: described_class.name, @@ -34,9 +34,9 @@ RSpec.describe ::Auth::Ldap do ) ldap_user = double - expect(ldap_user).to receive(:valid?).with(user.firstname, password).and_return(true) + allow(ldap_user).to receive(:valid?).with(user.firstname, password).and_return(true) - expect(::Ldap::User).to receive(:new).and_return(ldap_user) + allow(::Ldap::User).to receive(:new).and_return(ldap_user) result = instance.valid?(user, password) expect(result).to be true @@ -47,7 +47,7 @@ RSpec.describe ::Auth::Ldap do it "doesn't authenticate if 'ldap_integration' Setting is disabled" do allow(Setting).to receive(:get) - expect(Setting).to receive(:get).with('ldap_integration').and_return(false) + allow(Setting).to receive(:get).with('ldap_integration').and_return(false) result = instance.valid?(user, password) expect(result).to be false @@ -56,10 +56,10 @@ RSpec.describe ::Auth::Ldap do it "doesn't authenticate if ldap says 'nope'" do allow(Setting).to receive(:get) - expect(Setting).to receive(:get).with('ldap_integration').and_return(true) + allow(Setting).to receive(:get).with('ldap_integration').and_return(true) ldap_user = double(valid?: false) - expect(::Ldap::User).to receive(:new).and_return(ldap_user) + allow(::Ldap::User).to receive(:new).and_return(ldap_user) result = instance.valid?(user, password) expect(result).to be false diff --git a/spec/lib/import/base_factory_examples.rb b/spec/lib/import/base_factory_examples.rb index a78d6547a..fc5d1bf58 100644 --- a/spec/lib/import/base_factory_examples.rb +++ b/spec/lib/import/base_factory_examples.rb @@ -23,8 +23,10 @@ end RSpec.shared_examples 'Import::BaseFactory extender' do it 'calls new on determined backend object' do record = double() - expect(described_class).to receive(:backend_class).and_return(Class) - expect(Class).to receive(:new).with(record, any_args) + allow(described_class).to receive(:backend_class).and_return(Class) + allow(Class).to receive(:new) + described_class.import([record]) + expect(Class).to have_received(:new).with(record, any_args) end end diff --git a/spec/lib/import/helper_spec.rb b/spec/lib/import/helper_spec.rb index 1ac356672..8d16e5a5c 100644 --- a/spec/lib/import/helper_spec.rb +++ b/spec/lib/import/helper_spec.rb @@ -7,12 +7,14 @@ RSpec.describe Import::Helper do context 'import mode' do it 'checks if import_mode is active' do - expect(Setting).to receive(:get).with('import_mode').and_return(true) + allow(Setting).to receive(:get).with('import_mode').and_return(true) + expect( described_class.check_import_mode ).to be true end it 'throws an exception if import_mode is disabled' do - expect(Setting).to receive(:get).with('import_mode').and_return(false) + allow(Setting).to receive(:get).with('import_mode').and_return(false) + expect { described_class.check_import_mode }.to raise_error(RuntimeError) end end @@ -20,12 +22,14 @@ RSpec.describe Import::Helper do context 'system init' do it 'checks if system_init_done is active' do - expect(Setting).to receive(:get).with('system_init_done').and_return(false) + allow(Setting).to receive(:get).with('system_init_done').and_return(false) + expect( described_class.check_system_init_done ).to be true end it 'throws an exception if system_init_done is disabled' do - expect(Setting).to receive(:get).with('system_init_done').and_return(true) + allow(Setting).to receive(:get).with('system_init_done').and_return(true) + expect { described_class.check_system_init_done }.to raise_error(RuntimeError) end end diff --git a/spec/lib/import/otrs/article/attachment_factory_spec.rb b/spec/lib/import/otrs/article/attachment_factory_spec.rb index ef2ea0c1f..a85657e81 100644 --- a/spec/lib/import/otrs/article/attachment_factory_spec.rb +++ b/spec/lib/import/otrs/article/attachment_factory_spec.rb @@ -31,7 +31,7 @@ RSpec.describe Import::OTRS::Article::AttachmentFactory do end def article_attachment_expectations(article_attachments) - expect(local_article).to receive(:attachments).and_return(article_attachments) + allow(local_article).to receive(:attachments).and_return(article_attachments) end it_behaves_like 'Import factory' diff --git a/spec/lib/import/otrs/article_customer_spec.rb b/spec/lib/import/otrs/article_customer_spec.rb index c1a8e0346..81875adfa 100644 --- a/spec/lib/import/otrs/article_customer_spec.rb +++ b/spec/lib/import/otrs/article_customer_spec.rb @@ -13,21 +13,24 @@ RSpec.describe Import::OTRS::ArticleCustomer do let(:start_import_test) { described_class.new(object_structure) } it 'finds customers by email' do - expect(import_object).to receive(:find_by).with(email: 'kunde2@kunde.de').and_return(existing_object) + allow(import_object).to receive(:find_by).with(email: 'kunde2@kunde.de').and_return(existing_object) + expect(import_object).not_to receive(:create) start_import_test end it 'finds customers by login' do - expect(import_object).to receive(:find_by).with(email: 'kunde2@kunde.de') - expect(import_object).to receive(:find_by).with(login: 'kunde2@kunde.de').and_return(existing_object) + allow(import_object).to receive(:find_by) + allow(import_object).to receive(:find_by).with(login: 'kunde2@kunde.de').and_return(existing_object) + expect(import_object).not_to receive(:create) start_import_test end it 'creates customers' do + allow(import_object).to receive(:create).and_return(existing_object) + expect(import_object).to receive(:find_by).at_least(:once) - expect(import_object).to receive(:create).and_return(existing_object) start_import_test end diff --git a/spec/lib/import/otrs/article_spec.rb b/spec/lib/import/otrs/article_spec.rb index e0d644842..f2e268597 100644 --- a/spec/lib/import/otrs/article_spec.rb +++ b/spec/lib/import/otrs/article_spec.rb @@ -3,14 +3,16 @@ require 'rails_helper' RSpec.describe Import::OTRS::Article do def creates_with(zammad_structure) - expect(import_object).to receive(:new).with(zammad_structure).and_call_original + allow(import_object).to receive(:new).with(zammad_structure).and_call_original + expect_any_instance_of(import_object).to receive(:save) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) start_import_test end def updates_with(zammad_structure) - expect(import_object).to receive(:find_by).and_return(existing_object) + allow(import_object).to receive(:find_by).and_return(existing_object) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test diff --git a/spec/lib/import/otrs/customer_spec.rb b/spec/lib/import/otrs/customer_spec.rb index e1709b13e..f3686e479 100644 --- a/spec/lib/import/otrs/customer_spec.rb +++ b/spec/lib/import/otrs/customer_spec.rb @@ -3,13 +3,15 @@ require 'rails_helper' RSpec.describe Import::OTRS::Customer do def creates_with(zammad_structure) - expect(import_object).to receive(:create).with(zammad_structure).and_return(existing_object) + allow(import_object).to receive(:create).with(zammad_structure).and_return(existing_object) + expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) start_import_test end def updates_with(zammad_structure) - expect(import_object).to receive(:find_by).and_return(existing_object) + allow(import_object).to receive(:find_by).and_return(existing_object) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test @@ -62,8 +64,8 @@ RSpec.describe Import::OTRS::Customer do end it 'finds Organizations by OTRS CustomerID' do - expect(Import::OTRS::Requester).to receive(:load).and_return(otrs_dummy_response) - expect(import_object).to receive(:find_by).with(name: customer_id).and_return(existing_object) + allow(Import::OTRS::Requester).to receive(:load).and_return(otrs_dummy_response) + allow(import_object).to receive(:find_by).with(name: customer_id).and_return(existing_object) expect(described_class.by_customer_id(customer_id)).to be(existing_object) end diff --git a/spec/lib/import/otrs/customer_user_spec.rb b/spec/lib/import/otrs/customer_user_spec.rb index 9dd3c44f5..3cb72f86d 100644 --- a/spec/lib/import/otrs/customer_user_spec.rb +++ b/spec/lib/import/otrs/customer_user_spec.rb @@ -3,28 +3,30 @@ require 'rails_helper' RSpec.describe Import::OTRS::CustomerUser do def creates_with(zammad_structure) - expect_organization_lookup - expect(import_object).to receive(:new).with(zammad_structure).and_call_original + allow_organization_lookup + allow(import_object).to receive(:new).with(zammad_structure).and_call_original + expect_any_instance_of(import_object).to receive(:save) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) start_import_test end def updates_with(zammad_structure) - expect_organization_lookup - expect(import_object).to receive(:find_by).and_return(existing_object) + allow_organization_lookup + allow(import_object).to receive(:find_by).and_return(existing_object) # we delete the :role_ids from the zammad_structure to make sure that # a) role_ids call returns the initial role_ids # b) and update! gets called without them - expect(existing_object).to receive(:role_ids).and_return(zammad_structure.delete(:role_ids)).at_least(:once) + allow(existing_object).to receive(:role_ids).and_return(zammad_structure.delete(:role_ids)).at_least(:once) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test end - def expect_organization_lookup - expect(Import::OTRS::Customer).to receive(:by_customer_id).and_return(organization) - expect(organization).to receive(:id).and_return(organization_id) + def allow_organization_lookup + allow(Import::OTRS::Customer).to receive(:by_customer_id).and_return(organization) + allow(organization).to receive(:id).and_return(organization_id) end def load_customer_json(file) diff --git a/spec/lib/import/otrs/dynamic_field_spec.rb b/spec/lib/import/otrs/dynamic_field_spec.rb index 411f4af37..27135c3c2 100644 --- a/spec/lib/import/otrs/dynamic_field_spec.rb +++ b/spec/lib/import/otrs/dynamic_field_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Import::OTRS::DynamicField do it_behaves_like 'Import::OTRS::DynamicField' it 'requires an implementation of init_callback' do - expect(ObjectManager::Attribute).to receive(:get).and_return(false) + allow(ObjectManager::Attribute).to receive(:get).and_return(false) expect do start_import_test end.to raise_error(RuntimeError) diff --git a/spec/lib/import/otrs/priority_factory_spec.rb b/spec/lib/import/otrs/priority_factory_spec.rb index d9637b526..7e2d96302 100644 --- a/spec/lib/import/otrs/priority_factory_spec.rb +++ b/spec/lib/import/otrs/priority_factory_spec.rb @@ -9,8 +9,10 @@ RSpec.describe Import::OTRS::PriorityFactory do import_data = { name: 'test', } - expect(::Import::OTRS::Priority).to receive(:new).with(import_data) + allow(::Import::OTRS::Priority).to receive(:new) described_class.import([import_data]) + + expect(::Import::OTRS::Priority).to have_received(:new).with(import_data) end it 'sets default create Priority' do @@ -19,7 +21,7 @@ RSpec.describe Import::OTRS::PriorityFactory do priority.callback_loop = true priority.save - expect(Import::OTRS::SysConfigFactory).to receive(:postmaster_default_lookup).with(:priority_default_create).and_return(priority.name) + allow(Import::OTRS::SysConfigFactory).to receive(:postmaster_default_lookup).with(:priority_default_create).and_return(priority.name) described_class.update_attribute_settings priority.reload @@ -33,7 +35,7 @@ RSpec.describe Import::OTRS::PriorityFactory do priority.callback_loop = true priority.save - expect(Import::OTRS).to receive(:diff?).and_return(true) + allow(Import::OTRS).to receive(:diff?).and_return(true) described_class.update_attribute_settings priority.reload diff --git a/spec/lib/import/otrs/priority_spec.rb b/spec/lib/import/otrs/priority_spec.rb index 69cf67f85..1edccf8e9 100644 --- a/spec/lib/import/otrs/priority_spec.rb +++ b/spec/lib/import/otrs/priority_spec.rb @@ -3,14 +3,16 @@ require 'rails_helper' RSpec.describe Import::OTRS::Priority do def creates_with(zammad_structure) - expect(import_object).to receive(:new).with(zammad_structure).and_call_original + allow(import_object).to receive(:new).with(zammad_structure).and_call_original + expect_any_instance_of(import_object).to receive(:save) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) start_import_test end def updates_with(zammad_structure) - expect(import_object).to receive(:find_by).and_return(existing_object) + allow(import_object).to receive(:find_by).and_return(existing_object) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test diff --git a/spec/lib/import/otrs/queue_spec.rb b/spec/lib/import/otrs/queue_spec.rb index b873a9d67..99f105f3e 100644 --- a/spec/lib/import/otrs/queue_spec.rb +++ b/spec/lib/import/otrs/queue_spec.rb @@ -3,14 +3,16 @@ require 'rails_helper' RSpec.describe Import::OTRS::Queue do def creates_with(zammad_structure) - expect(import_object).to receive(:new).with(zammad_structure).and_call_original + allow(import_object).to receive(:new).with(zammad_structure).and_call_original + expect_any_instance_of(import_object).to receive(:save) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) start_import_test end def updates_with(zammad_structure) - expect(import_object).to receive(:find_by).and_return(existing_object) + allow(import_object).to receive(:find_by).and_return(existing_object) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test diff --git a/spec/lib/import/otrs/requester_spec.rb b/spec/lib/import/otrs/requester_spec.rb index c92b3eaf3..bb6234795 100644 --- a/spec/lib/import/otrs/requester_spec.rb +++ b/spec/lib/import/otrs/requester_spec.rb @@ -19,20 +19,20 @@ RSpec.describe Import::OTRS::Requester do let(:response) do response = double() response_body = double() - expect(response_body).to receive(:to_s).at_least(:once).and_return('{"Result": {}}') - expect(response).to receive('success?').at_least(:once).and_return(true) - expect(response).to receive('body').at_least(:once).and_return(response_body) + allow(response_body).to receive(:to_s).at_least(:once).and_return('{"Result": {}}') + allow(response).to receive('success?').at_least(:once).and_return(true) + allow(response).to receive('body').at_least(:once).and_return(response_body) response end it 'is active if no args are given' do - expect(UserAgent).to receive(:post).and_return(response) + allow(UserAgent).to receive(:post).and_return(response) described_class.load('Ticket') described_class.load('Ticket') end it 'is not active if args are given' do - expect(UserAgent).to receive(:post).twice.and_return(response) + allow(UserAgent).to receive(:post).twice.and_return(response) described_class.load('Ticket', offset: 10) described_class.load('Ticket', offset: 20) end diff --git a/spec/lib/import/otrs/state_factory_spec.rb b/spec/lib/import/otrs/state_factory_spec.rb index 2bf2806a4..eab0c374d 100644 --- a/spec/lib/import/otrs/state_factory_spec.rb +++ b/spec/lib/import/otrs/state_factory_spec.rb @@ -57,7 +57,7 @@ RSpec.describe Import::OTRS::StateFactory do name: 'pending_time', ) - expect(Import::OTRS).to receive(:diff?).and_return(true) + allow(Import::OTRS).to receive(:diff?).and_return(true) expect do described_class.update_attribute_settings @@ -81,8 +81,8 @@ RSpec.describe Import::OTRS::StateFactory do state.callback_loop = true state.save - expect(Import::OTRS::SysConfigFactory).to receive(:postmaster_default_lookup).with(:state_default_create).and_return(state.name) - expect(Import::OTRS::SysConfigFactory).to receive(:postmaster_default_lookup).with(:state_default_follow_up).and_return(state.name) + allow(Import::OTRS::SysConfigFactory).to receive(:postmaster_default_lookup).with(:state_default_create).and_return(state.name) + allow(Import::OTRS::SysConfigFactory).to receive(:postmaster_default_lookup).with(:state_default_follow_up).and_return(state.name) described_class.update_attribute state.reload @@ -98,7 +98,7 @@ RSpec.describe Import::OTRS::StateFactory do state.callback_loop = true state.save - expect(Import::OTRS).to receive(:diff?).and_return(true) + allow(Import::OTRS).to receive(:diff?).and_return(true) described_class.update_attribute_settings state.reload diff --git a/spec/lib/import/otrs/state_spec.rb b/spec/lib/import/otrs/state_spec.rb index 1cd62546d..f77225025 100644 --- a/spec/lib/import/otrs/state_spec.rb +++ b/spec/lib/import/otrs/state_spec.rb @@ -3,15 +3,17 @@ require 'rails_helper' RSpec.describe Import::OTRS::State do def creates_with(zammad_structure) - expect(import_object).to receive(:find_by).and_return(nil) - expect(import_object).to receive(:new).with(zammad_structure).and_call_original + allow(import_object).to receive(:find_by).and_return(nil) + allow(import_object).to receive(:new).with(zammad_structure).and_call_original + expect_any_instance_of(import_object).to receive(:save) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) start_import_test end def updates_with(zammad_structure) - expect(import_object).to receive(:find_by).and_return(existing_object) + allow(import_object).to receive(:find_by).and_return(existing_object) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test diff --git a/spec/lib/import/otrs/ticket_spec.rb b/spec/lib/import/otrs/ticket_spec.rb index 991c9fda5..16ec2b47f 100644 --- a/spec/lib/import/otrs/ticket_spec.rb +++ b/spec/lib/import/otrs/ticket_spec.rb @@ -3,15 +3,17 @@ require 'rails_helper' RSpec.describe Import::OTRS::Ticket do def creates_with(zammad_structure) - expect(import_object).to receive(:new).with(zammad_structure).and_call_original + allow(import_object).to receive(:new).with(zammad_structure).and_call_original + expect_any_instance_of(import_object).to receive(:save) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) start_import_test end def updates_with(zammad_structure) - expect(import_object).to receive(:find_by).and_return(existing_object) - expect(existing_object).to receive(:update!).with(zammad_structure) + allow(import_object).to receive(:find_by).and_return(existing_object) + allow(existing_object).to receive(:update!).with(zammad_structure) + expect(import_object).not_to receive(:new) start_import_test end diff --git a/spec/lib/import/otrs/user_spec.rb b/spec/lib/import/otrs/user_spec.rb index e56bc53e2..b0f860f02 100644 --- a/spec/lib/import/otrs/user_spec.rb +++ b/spec/lib/import/otrs/user_spec.rb @@ -3,19 +3,21 @@ require 'rails_helper' RSpec.describe Import::OTRS::User do def creates_with(zammad_structure) - expect(import_object).to receive(:find_by).and_return(nil) - expect(import_object).to receive(:new).with(zammad_structure).and_call_original + allow(import_object).to receive(:find_by).and_return(nil) + allow(import_object).to receive(:new).with(zammad_structure).and_call_original + expect_any_instance_of(import_object).to receive(:save) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) start_import_test end def updates_with(zammad_structure) - expect(import_object).to receive(:find_by).and_return(existing_object) + allow(import_object).to receive(:find_by).and_return(existing_object) # we delete the :role_ids from the zammad_structure to make sure that # a) role_ids call returns the initial role_ids # b) and update! gets called without them - expect(existing_object).to receive(:role_ids).and_return(zammad_structure.delete(:role_ids)) + allow(existing_object).to receive(:role_ids).and_return(zammad_structure.delete(:role_ids)) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test @@ -33,7 +35,7 @@ RSpec.describe Import::OTRS::User do end def user_expectations - expect(User).to receive(:where).and_return([]) + allow(User).to receive(:where).and_return([]) end # this is really bad and should get improved! diff --git a/spec/lib/ldap/group_spec.rb b/spec/lib/ldap/group_spec.rb index a91aced89..f9c3302c2 100644 --- a/spec/lib/ldap/group_spec.rb +++ b/spec/lib/ldap/group_spec.rb @@ -81,7 +81,7 @@ RSpec.describe Ldap::Group do it 'returns a Hash of groups' do ldap_entry = build(:ldap_entry) - expect(mocked_ldap).to receive(:search).and_return(ldap_entry) + allow(mocked_ldap).to receive(:search).and_return(ldap_entry) expect(instance.list).to be_a(Hash) end end @@ -99,7 +99,7 @@ RSpec.describe Ldap::Group do end it 'tries filters and returns first one with entries' do - expect(mocked_ldap).to receive(:entries?).and_return(true) + allow(mocked_ldap).to receive(:entries?).and_return(true) expect(instance.filter).to be_a(String) end diff --git a/spec/lib/ldap/guid_spec.rb b/spec/lib/ldap/guid_spec.rb index 415dc27bd..0c413ac1b 100644 --- a/spec/lib/ldap/guid_spec.rb +++ b/spec/lib/ldap/guid_spec.rb @@ -28,12 +28,13 @@ RSpec.describe Ldap::Guid do end it 'tunnels to instance method' do - instance = double() - expect(instance).to receive(:hex) - expect(described_class).to receive(:new).with(string).and_return(instance) + allow(instance).to receive(:hex) + allow(described_class).to receive(:new).with(string).and_return(instance) described_class.hex(string) + + expect(instance).to have_received(:hex) end end @@ -46,10 +47,11 @@ RSpec.describe Ldap::Guid do it 'tunnels to instance method' do instance = double() - expect(instance).to receive(:string) - expect(described_class).to receive(:new).with(hex).and_return(instance) + allow(instance).to receive(:string) + allow(described_class).to receive(:new).with(hex).and_return(instance) described_class.string(hex) + expect(instance).to have_received(:string) end end diff --git a/spec/lib/ldap/user_spec.rb b/spec/lib/ldap/user_spec.rb index 5889e7c7d..ad9deef6f 100644 --- a/spec/lib/ldap/user_spec.rb +++ b/spec/lib/ldap/user_spec.rb @@ -94,24 +94,24 @@ RSpec.describe Ldap::User do it 'validates username and password' do connection = double() - expect(mocked_ldap).to receive(:connection).and_return(connection) + allow(mocked_ldap).to receive(:connection).and_return(connection) build(:ldap_entry) - expect(mocked_ldap).to receive(:base_dn) - expect(connection).to receive(:bind_as).and_return(true) + allow(mocked_ldap).to receive(:base_dn) + allow(connection).to receive(:bind_as).and_return(true) expect(instance.valid?('example_username', 'password')).to be true end it 'fails for invalid credentials' do connection = double() - expect(mocked_ldap).to receive(:connection).and_return(connection) + allow(mocked_ldap).to receive(:connection).and_return(connection) build(:ldap_entry) - expect(mocked_ldap).to receive(:base_dn) - expect(connection).to receive(:bind_as).and_return(false) + allow(mocked_ldap).to receive(:base_dn) + allow(connection).to receive(:bind_as).and_return(false) expect(instance.valid?('example_username', 'wrong_password')).to be false end @@ -132,7 +132,7 @@ RSpec.describe Ldap::User do # blacklisted attribute ldap_entry['lastlogon'] = DateTime.current - expect(mocked_ldap).to receive(:search).and_yield(ldap_entry) + allow(mocked_ldap).to receive(:search).and_yield(ldap_entry) attributes = instance.attributes @@ -159,7 +159,7 @@ RSpec.describe Ldap::User do end it 'tries filters and returns first one with entries' do - expect(mocked_ldap).to receive(:entries?).and_return(true) + allow(mocked_ldap).to receive(:entries?).and_return(true) expect(instance.filter).to be_a(String) end @@ -187,7 +187,7 @@ RSpec.describe Ldap::User do # selectable attribute ldap_entry['objectguid'] = 'f742b361-32c6-4a92-baaa-eaae7df657ee' - expect(mocked_ldap).to receive(:search).and_yield(ldap_entry) + allow(mocked_ldap).to receive(:search).and_yield(ldap_entry) expect(instance.uid_attribute).to be_a(String) end diff --git a/spec/lib/ldap_spec.rb b/spec/lib/ldap_spec.rb index 4a2c01b62..38936ad9d 100644 --- a/spec/lib/ldap_spec.rb +++ b/spec/lib/ldap_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Ldap do let(:mocked_ldap) { double(bind: true) } def mock_initialization(given:, expected:) - expect(Net::LDAP).to receive(:new).with(expected).and_return(mocked_ldap) + allow(Net::LDAP).to receive(:new).with(expected).and_return(mocked_ldap) described_class.new(given) end @@ -43,7 +43,7 @@ RSpec.describe Ldap do port: 1337, } - expect(mocked_ldap).to receive(:auth).with(config[:bind_user], config[:bind_pw]) + allow(mocked_ldap).to receive(:auth).with(config[:bind_user], config[:bind_pw]) mock_initialization( given: config, @@ -64,12 +64,13 @@ RSpec.describe Ldap do port: 1337, } - expect(mocked_ldap).not_to receive(:auth).with(config[:bind_user], config[:bind_pw]) + allow(mocked_ldap).to receive(:auth) mock_initialization( given: config, expected: params, ) + expect(mocked_ldap).not_to have_received(:auth).with(config[:bind_user], config[:bind_pw]) end it 'requires bind_pw' do @@ -85,12 +86,13 @@ RSpec.describe Ldap do port: 1337, } - expect(mocked_ldap).not_to receive(:auth).with(config[:bind_user], config[:bind_pw]) + allow(mocked_ldap).to receive(:auth) mock_initialization( given: config, expected: params, ) + expect(mocked_ldap).not_to have_received(:auth).with(config[:bind_user], config[:bind_pw]) end end @@ -191,7 +193,8 @@ RSpec.describe Ldap do port: 1337, } - expect(Setting).to receive(:get).with('ldap_config').and_return(config) + allow(Setting).to receive(:get) + allow(Setting).to receive(:get).with('ldap_config').and_return(config) mock_initialization( given: nil, @@ -207,7 +210,7 @@ RSpec.describe Ldap do # as return param of Net::LDAP.new let(:mocked_ldap) { double(bind: true) } let(:instance) do - expect(Net::LDAP).to receive(:new).and_return(mocked_ldap) + allow(Net::LDAP).to receive(:new).and_return(mocked_ldap) described_class.new( host: 'localhost', port: 1337, @@ -221,12 +224,11 @@ RSpec.describe Ldap do end it 'returns preferences' do - attributes = { namingcontexts: ['ou=dep1,ou=org', 'ou=dep2,ou=org'] } + allow(mocked_ldap).to receive(:search_root_dse).and_return(attributes) - expect(mocked_ldap).to receive(:search_root_dse).and_return(attributes) expect(instance.preferences).to eq(attributes) end end @@ -256,7 +258,7 @@ RSpec.describe Ldap do } yield_entry = build(:ldap_entry) - expect(mocked_ldap).to receive(:search).with(include(expected)).and_yield(yield_entry).and_return(true) + allow(mocked_ldap).to receive(:search).with(include(expected)).and_yield(yield_entry).and_return(true) check_entry = nil instance.search(filter, additional) { |entry| check_entry = entry } @@ -276,7 +278,7 @@ RSpec.describe Ldap do } yield_entry = build(:ldap_entry) - expect(mocked_ldap).to receive(:search).with(include(expected)).and_yield(yield_entry).and_return(true) + allow(mocked_ldap).to receive(:search).with(include(expected)).and_yield(yield_entry).and_return(true) check_entry = nil instance.search(filter, additional) { |entry| check_entry = entry } @@ -291,7 +293,7 @@ RSpec.describe Ldap do scope: Net::LDAP::SearchScope_WholeSubtree, } - expect(Net::LDAP).to receive(:new).and_return(mocked_ldap) + allow(Net::LDAP).to receive(:new).and_return(mocked_ldap) instance = described_class.new( host: 'localhost', port: 1337, @@ -299,7 +301,7 @@ RSpec.describe Ldap do ) yield_entry = build(:ldap_entry) - expect(mocked_ldap).to receive(:search).with(include(expected)).and_yield(yield_entry).and_return(true) + allow(mocked_ldap).to receive(:search).with(include(expected)).and_yield(yield_entry).and_return(true) check_entry = nil instance.search(filter) { |entry| check_entry = entry } @@ -316,22 +318,20 @@ RSpec.describe Ldap do end it 'returns true if entries are present' do - params = { filter: filter } + allow(mocked_ldap).to receive(:search).with(include(params)).and_yield(build(:ldap_entry)).and_return(nil) - expect(mocked_ldap).to receive(:search).with(include(params)).and_yield(build(:ldap_entry)).and_return(nil) expect(instance.entries?(filter)).to be true end it 'returns false if no entries are present' do - params = { filter: filter } + allow(mocked_ldap).to receive(:search).with(include(params)).and_return(true) - expect(mocked_ldap).to receive(:search).with(include(params)).and_return(true) expect(instance.entries?(filter)).to be false end diff --git a/spec/lib/migration_job/ldap_samaccountname_to_uid_spec.rb b/spec/lib/migration_job/ldap_samaccountname_to_uid_spec.rb index 9c91ff20a..b4b1075a6 100644 --- a/spec/lib/migration_job/ldap_samaccountname_to_uid_spec.rb +++ b/spec/lib/migration_job/ldap_samaccountname_to_uid_spec.rb @@ -3,27 +3,29 @@ require 'rails_helper' RSpec.describe MigrationJob::LdapSamaccountnameToUid do it 'performs no changes if no LDAP config present' do - expect(Setting).not_to receive(:set) - expect(Import::Ldap).to receive(:config).and_return(nil) + allow(Setting).to receive(:set) + allow(Import::Ldap).to receive(:config).and_return(nil) described_class.new.perform + expect(Setting).not_to have_received(:set) end it 'performs no changes if uid attributes equals' do - expect(Setting).not_to receive(:set) + allow(Setting).to receive(:set) ldap_config = { 'user_uid' => 'samaccountname' } - expect(Import::Ldap).to receive(:config).and_return(ldap_config) + allow(Import::Ldap).to receive(:config).and_return(ldap_config) ldap_user = double() - expect(ldap_user).to receive(:uid_attribute).and_return('samaccountname') - expect(::Ldap::User).to receive(:new).and_return(ldap_user) + allow(ldap_user).to receive(:uid_attribute).and_return('samaccountname') + allow(::Ldap::User).to receive(:new).and_return(ldap_user) allow(::Ldap).to receive(:new) described_class.new.perform + expect(Setting).not_to have_received(:set) end it 'performs Setting change if uid attribute differ' do @@ -34,16 +36,18 @@ RSpec.describe MigrationJob::LdapSamaccountnameToUid do 'user_uid' => 'samaccountname' } - expect(Setting).to receive(:set).with('ldap_config', ldap_config_new) + allow(Setting).to receive(:set) - expect(Import::Ldap).to receive(:config).and_return(ldap_config_obsolete) + allow(Import::Ldap).to receive(:config).and_return(ldap_config_obsolete) ldap_user = double() - expect(ldap_user).to receive(:uid_attribute).and_return('objectguid') - expect(::Ldap::User).to receive(:new).and_return(ldap_user) + allow(ldap_user).to receive(:uid_attribute).and_return('objectguid') + allow(::Ldap::User).to receive(:new).and_return(ldap_user) allow(::Ldap).to receive(:new) described_class.new.perform + + expect(Setting).to have_received(:set).with('ldap_config', ldap_config_new) end end diff --git a/spec/lib/sequencer/sequence/import/ldap/users_spec.rb b/spec/lib/sequencer/sequence/import/ldap/users_spec.rb index 0ded1b0d8..cf6e8c048 100644 --- a/spec/lib/sequencer/sequence/import/ldap/users_spec.rb +++ b/spec/lib/sequencer/sequence/import/ldap/users_spec.rb @@ -40,14 +40,14 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence ) # LDAP::Group - expect(connection).to receive(:search).and_yield(group_entry) - expect(connection).to receive(:entries?).and_return(true) + allow(connection).to receive(:search).and_yield(group_entry) + allow(connection).to receive(:entries?).and_return(true) # Sequencer::Unit::Import::Ldap::Users::Total - expect(connection).to receive(:count).and_return(1) + allow(connection).to receive(:count).and_return(1) # Sequencer::Unit::Import::Ldap::Users::SubSequence - expect(connection).to receive(:search).and_yield(user_entry) + allow(connection).to receive(:search).and_yield(user_entry) expect do process( @@ -70,15 +70,8 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence group_entry['member'] = ['some.other.dn'] # LDAP::Group - expect(connection).to receive(:search).and_yield(group_entry) - expect(connection).to receive(:entries?).and_return(true) - - # Sequencer::Unit::Import::Ldap::Users::Total - # cached - # expect(connection).to receive(:count).and_return(1) - - # Sequencer::Unit::Import::Ldap::Users::SubSequence - expect(connection).to receive(:search).and_yield(user_entry) + allow(connection).to receive(:search).and_yield(group_entry) + allow(connection).to receive(:entries?).and_return(true) expect do process( @@ -129,15 +122,12 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence base_dn: 'test' ) - # LDAP::Group - expect(connection).to receive(:search).and_yield(group_entry) - expect(connection).to receive(:entries?).and_return(true) + # LDAP::Group and Sequencer::Unit::Import::Ldap::Users::SubSequence + allow(connection).to receive(:search).and_yield(group_entry).and_yield(user_entry) + allow(connection).to receive(:entries?).and_return(true) # Sequencer::Unit::Import::Ldap::Users::Total - expect(connection).to receive(:count).and_return(1) - - # Sequencer::Unit::Import::Ldap::Users::SubSequence - expect(connection).to receive(:search).and_yield(user_entry) + allow(connection).to receive(:count).and_return(1) expect do process( @@ -160,15 +150,15 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence group_entry['member'] = ['some.other.dn'] # LDAP::Group - expect(connection).to receive(:search).and_yield(group_entry) - expect(connection).to receive(:entries?).and_return(true) + allow(connection).to receive(:search).and_yield(group_entry) + allow(connection).to receive(:entries?).and_return(true) # Sequencer::Unit::Import::Ldap::Users::Total # cached # expect(connection).to receive(:count).and_return(1) # Sequencer::Unit::Import::Ldap::Users::SubSequence - expect(connection).to receive(:search).and_yield(user_entry) + allow(connection).to receive(:search).and_yield(user_entry) expect do process( diff --git a/spec/lib/sequencer/unit/common/attribute_mapper_spec.rb b/spec/lib/sequencer/unit/common/attribute_mapper_spec.rb index ad608a476..020831f3e 100644 --- a/spec/lib/sequencer/unit/common/attribute_mapper_spec.rb +++ b/spec/lib/sequencer/unit/common/attribute_mapper_spec.rb @@ -16,12 +16,12 @@ RSpec.describe Sequencer::Unit::Common::AttributeMapper, sequencer: :unit do end it 'declares uses from map keys' do - expect(described_class).to receive(:map).and_return(map) + allow(described_class).to receive(:map).and_return(map) expect(described_class.uses).to eq(map.keys) end it 'declares provides from map values' do - expect(described_class).to receive(:map).and_return(map) + allow(described_class).to receive(:map).and_return(map) expect(described_class.provides).to eq(map.values) end diff --git a/spec/lib/sequencer/unit/import/common/mapping/flat_keys_spec.rb b/spec/lib/sequencer/unit/import/common/mapping/flat_keys_spec.rb index 0ce2aacd2..c9bbb1a32 100644 --- a/spec/lib/sequencer/unit/import/common/mapping/flat_keys_spec.rb +++ b/spec/lib/sequencer/unit/import/common/mapping/flat_keys_spec.rb @@ -25,7 +25,7 @@ RSpec.describe Sequencer::Unit::Import::Common::Mapping::FlatKeys, sequencer: :u } provided = process(parameters) do |instance| - expect(instance).to receive(:mapping).and_return(mapping) + allow(instance).to receive(:mapping).and_return(mapping) end expect(provided).to eq( diff --git a/spec/lib/sequencer/unit/import/common/model/attributes/remote_id_spec.rb b/spec/lib/sequencer/unit/import/common/model/attributes/remote_id_spec.rb index 130165da8..2e8f14d34 100644 --- a/spec/lib/sequencer/unit/import/common/model/attributes/remote_id_spec.rb +++ b/spec/lib/sequencer/unit/import/common/model/attributes/remote_id_spec.rb @@ -22,7 +22,7 @@ RSpec.describe Sequencer::Unit::Import::Common::Model::Attributes::RemoteId, seq } provided = process(parameters) do |instance| - expect(instance).to receive(:attribute).and_return(:other_attribute) + allow(instance).to receive(:attribute).and_return(:other_attribute) end expect(provided).to include(remote_id: '123abc') diff --git a/spec/lib/sequencer/unit/import/common/object_attribute/sanitized_name_spec.rb b/spec/lib/sequencer/unit/import/common/object_attribute/sanitized_name_spec.rb index d471fb53d..4fc7cba27 100644 --- a/spec/lib/sequencer/unit/import/common/object_attribute/sanitized_name_spec.rb +++ b/spec/lib/sequencer/unit/import/common/object_attribute/sanitized_name_spec.rb @@ -13,7 +13,7 @@ RSpec.describe Sequencer::Unit::Import::Common::ObjectAttribute::SanitizedName, it 'replaces whitespaces' do provided = process do |instance| - expect(instance).to receive(:unsanitized_name).and_return('model name') + allow(instance).to receive(:unsanitized_name).and_return('model name') end expect(provided[:sanitized_name]).to eq('model_name') @@ -21,7 +21,7 @@ RSpec.describe Sequencer::Unit::Import::Common::ObjectAttribute::SanitizedName, it 'replaces dashes' do provided = process do |instance| - expect(instance).to receive(:unsanitized_name).and_return('model-name') + allow(instance).to receive(:unsanitized_name).and_return('model-name') end expect(provided[:sanitized_name]).to eq('model_name') @@ -29,7 +29,7 @@ RSpec.describe Sequencer::Unit::Import::Common::ObjectAttribute::SanitizedName, it 'replaces ids suffix' do provided = process do |instance| - expect(instance).to receive(:unsanitized_name).and_return('Model Ids') + allow(instance).to receive(:unsanitized_name).and_return('Model Ids') end expect(provided[:sanitized_name]).to eq('model_nos') @@ -37,7 +37,7 @@ RSpec.describe Sequencer::Unit::Import::Common::ObjectAttribute::SanitizedName, it 'replaces id suffix' do provided = process do |instance| - expect(instance).to receive(:unsanitized_name).and_return('Model Id') + allow(instance).to receive(:unsanitized_name).and_return('Model Id') end expect(provided[:sanitized_name]).to eq('model_no') @@ -45,7 +45,7 @@ RSpec.describe Sequencer::Unit::Import::Common::ObjectAttribute::SanitizedName, it 'replaces non-ASCII characters' do provided = process do |instance| - expect(instance).to receive(:unsanitized_name).and_return('Ærøskøbing Ät Mödél') + allow(instance).to receive(:unsanitized_name).and_return('Ærøskøbing Ät Mödél') end expect(provided[:sanitized_name]).to eq('a_eroskobing_at_model') diff --git a/spec/models/import_job_spec.rb b/spec/models/import_job_spec.rb index f1a7cf8c6..2b14f7378 100644 --- a/spec/models/import_job_spec.rb +++ b/spec/models/import_job_spec.rb @@ -78,7 +78,7 @@ RSpec.describe ImportJob do it 'queues registered import jobs' do allow(Setting).to receive(:get) - expect(Setting).to receive(:get).with('import_backends').and_return([test_backend_name]) + allow(Setting).to receive(:get).with('import_backends').and_return([test_backend_name]) expect do described_class.queue_registered @@ -89,8 +89,8 @@ RSpec.describe ImportJob do it "doesn't queue if backend isn't #queueable?" do allow(Setting).to receive(:get) - expect(Setting).to receive(:get).with('import_backends').and_return([test_backend_name]) - expect(test_backend_class).to receive(:queueable?).and_return(false) + allow(Setting).to receive(:get).with('import_backends').and_return([test_backend_name]) + allow(test_backend_class).to receive(:queueable?).and_return(false) expect do described_class.queue_registered @@ -100,11 +100,10 @@ RSpec.describe ImportJob do end it "doesn't queue if unfinished job entries exist" do - create(:import_job) allow(Setting).to receive(:get) - expect(Setting).to receive(:get).with('import_backends').and_return([test_backend_name]) + allow(Setting).to receive(:get).with('import_backends').and_return([test_backend_name]) expect do described_class.queue_registered @@ -115,9 +114,11 @@ RSpec.describe ImportJob do it 'logs errors for invalid registered backends' do allow(Setting).to receive(:get) - expect(Setting).to receive(:get).with('import_backends').and_return(['InvalidBackend']) - expect(described_class.logger).to receive(:error) + allow(Setting).to receive(:get).with('import_backends').and_return(['InvalidBackend']) + + allow(described_class.logger).to receive(:error) described_class.queue_registered + expect(described_class.logger).to have_received(:error) end end @@ -149,7 +150,7 @@ RSpec.describe ImportJob do describe '#start_registered' do it 'queues and starts registered import backends' do allow(Setting).to receive(:get) - expect(Setting).to receive(:get).with('import_backends').and_return([test_backend_name]) + allow(Setting).to receive(:get).with('import_backends').and_return([test_backend_name]) expect do described_class.start_registered @@ -173,8 +174,8 @@ RSpec.describe ImportJob do describe '#backends' do it 'returns list of backend namespaces' do - expect(Setting).to receive(:get).with('import_backends').and_return(['Import::Ldap']) - expect(Import::Ldap).to receive(:active?).and_return(true) + allow(Setting).to receive(:get).with('import_backends').and_return(['Import::Ldap']) + allow(Import::Ldap).to receive(:active?).and_return(true) backends = described_class.backends @@ -183,18 +184,21 @@ RSpec.describe ImportJob do end it 'returns blank array if none are found' do - expect(Setting).to receive(:get).with('import_backends') + allow(Setting).to receive(:get).with('import_backends') + expect(described_class.backends).to eq([]) end it "doesn't return invalid backends" do - expect(Setting).to receive(:get).with('import_backends').and_return(['Import::InvalidBackend']) + allow(Setting).to receive(:get).with('import_backends').and_return(['Import::InvalidBackend']) + expect(described_class.backends).to eq([]) end it "doesn't return inactive backends" do - expect(Setting).to receive(:get).with('import_backends').and_return(['Import::Ldap']) - expect(Import::Ldap).to receive(:active?).and_return(false) + allow(Setting).to receive(:get).with('import_backends').and_return(['Import::Ldap']) + allow(Import::Ldap).to receive(:active?).and_return(false) + expect(described_class.backends).to eq([]) end end @@ -221,7 +225,7 @@ RSpec.describe ImportJob do instance = create(:import_job) error_message = 'Some horrible error' - expect_any_instance_of(test_backend_class).to receive(:start).and_raise(error_message) + allow_any_instance_of(test_backend_class).to receive(:start).and_raise(error_message) expect do instance.start diff --git a/spec/models/object_manager/attribute/validation_spec.rb b/spec/models/object_manager/attribute/validation_spec.rb index 9368a2f9e..42f2b02ce 100644 --- a/spec/models/object_manager/attribute/validation_spec.rb +++ b/spec/models/object_manager/attribute/validation_spec.rb @@ -68,7 +68,7 @@ RSpec.describe ObjectManager::Attribute::Validation, application_handle: 'applic end it 'is skipped because of import_mode is active' do - expect(Setting).to receive(:get).with('import_mode').and_return(true) + allow(Setting).to receive(:get).with('import_mode').and_return(true) subject.validate(record) expect(backend).not_to have_received(:validate) end diff --git a/spec/models/scheduler_spec.rb b/spec/models/scheduler_spec.rb index e0b9a03ef..d85740a83 100644 --- a/spec/models/scheduler_spec.rb +++ b/spec/models/scheduler_spec.rb @@ -67,7 +67,7 @@ RSpec.describe Scheduler do describe '.cleanup' do it 'gets called by .threads' do - expect(described_class).to receive(:cleanup).and_throw(:called) + allow(described_class).to receive(:cleanup).and_throw(:called) expect do described_class.threads end.to throw_symbol(:called) diff --git a/spec/requests/integration/placetel_spec.rb b/spec/requests/integration/placetel_spec.rb index 0697f66e9..9f9a2f14e 100644 --- a/spec/requests/integration/placetel_spec.rb +++ b/spec/requests/integration/placetel_spec.rb @@ -1,7 +1,5 @@ require 'rails_helper' -# rubocop:disable Style/CombinableLoops - RSpec.describe 'Integration Placetel', type: :request do let(:agent) do @@ -618,5 +616,3 @@ RSpec.describe 'Integration Placetel', type: :request do end end end - -# rubocop:enable Style/CombinableLoops diff --git a/spec/requests/integration/sipgate_spec.rb b/spec/requests/integration/sipgate_spec.rb index 98013065e..6a8f9cb52 100644 --- a/spec/requests/integration/sipgate_spec.rb +++ b/spec/requests/integration/sipgate_spec.rb @@ -1,7 +1,5 @@ require 'rails_helper' -# rubocop:disable Style/CombinableLoops - RSpec.describe 'Integration Sipgate', type: :request do let(:agent) do @@ -490,5 +488,3 @@ RSpec.describe 'Integration Sipgate', type: :request do end end end - -# rubocop:enable Style/CombinableLoops diff --git a/spec/system/system/translations_spec.rb b/spec/system/system/translations_spec.rb index 5f9ac1c63..afa80a852 100644 --- a/spec/system/system/translations_spec.rb +++ b/spec/system/system/translations_spec.rb @@ -8,8 +8,8 @@ RSpec.describe 'System > Translations', type: :system do it 'when clicking "Get latest translations" fetches all translations' do visit 'system/translation' - expect(Translation).to receive(:load).with('de-de').and_return(true) - expect(Translation).to receive(:load).with('en-us').and_return(true) + allow(Translation).to receive(:load).with('de-de').and_return(true) + allow(Translation).to receive(:load).with('en-us').and_return(true) click '.js-syncChanges' diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index ae05150f9..5fffed85e 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -983,7 +983,7 @@ class TestCase < ActiveSupport::TestCase if params[:css] element = instance.find_elements(css: params[:css])[0] end - if params[:value].class == Array + if params[:value].instance_of?(Array) params[:value].each do |key| if element element.send_keys(key)