Maintenance: Updated rubocop(-* gems) to latest version (1.0.0).

This commit is contained in:
Thorsten Eckel 2020-10-22 15:57:01 +02:00
parent 2ffa821d65
commit 0b9e6676f8
60 changed files with 252 additions and 224 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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]

View file

@ -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

View file

@ -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?

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"')

View file

@ -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

View file

@ -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']

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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'

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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!

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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(

View file

@ -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

View file

@ -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(

View file

@ -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')

View file

@ -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')

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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'

View file

@ -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)