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) omniauth-oauth2 (>= 1.4.0)
openssl (2.1.2) openssl (2.1.2)
parallel (1.19.2) parallel (1.19.2)
parser (2.7.1.5) parser (2.7.2.0)
ast (~> 2.4.1) ast (~> 2.4.1)
pg (0.21.0) pg (0.21.0)
pluginator (1.5.0) pluginator (1.5.0)
@ -427,7 +427,7 @@ GEM
rb-inotify (0.10.0) rb-inotify (0.10.0)
ffi (~> 1.0) ffi (~> 1.0)
rchardet (1.8.0) rchardet (1.8.0)
regexp_parser (1.8.0) regexp_parser (1.8.2)
rest-client (2.0.2) rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0) http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0) mime-types (>= 1.16, < 4.0)
@ -452,16 +452,16 @@ GEM
rspec-support (~> 3.9.0) rspec-support (~> 3.9.0)
rspec-support (3.9.3) rspec-support (3.9.3)
rszr (0.5.2) rszr (0.5.2)
rubocop (0.92.0) rubocop (0.93.1)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 2.7.1.5) parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0) rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7) regexp_parser (>= 1.8)
rexml rexml
rubocop-ast (>= 0.5.0) rubocop-ast (>= 0.6.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0) unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.5.0) rubocop-ast (1.0.0)
parser (>= 2.7.1.5) parser (>= 2.7.1.5)
rubocop-performance (1.8.1) rubocop-performance (1.8.1)
rubocop (>= 0.87.0) rubocop (>= 0.87.0)
@ -470,8 +470,9 @@ GEM
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
rack (>= 1.1) rack (>= 1.1)
rubocop (>= 0.87.0) rubocop (>= 0.87.0)
rubocop-rspec (1.43.2) rubocop-rspec (1.44.1)
rubocop (~> 0.87) rubocop (~> 0.87)
rubocop-ast (>= 0.7.1)
ruby-progressbar (1.10.1) ruby-progressbar (1.10.1)
ruby-saml (1.10.2) ruby-saml (1.10.2)
nokogiri (>= 1.5.10) nokogiri (>= 1.5.10)

View file

@ -104,7 +104,7 @@ curl http://localhost/api/v1/monitoring/health_check?token=XXX
handler_attempts_map = {} handler_attempts_map = {}
failed_jobs.order(:created_at).limit(10).each do |job| 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'] job.payload_object.job_data['job_class']
else else
job.name job.name

View file

@ -80,7 +80,7 @@ class TicketsController < ApplicationController
# POST /api/v1/tickets # POST /api/v1/tickets
def create def create
customer = {} customer = {}
if params[:customer].class == ActionController::Parameters if params[:customer].instance_of?(ActionController::Parameters)
customer = params[:customer] customer = params[:customer]
params.delete(:customer) params.delete(:customer)
end end

View file

@ -105,7 +105,7 @@ add avatar by url
# fetch image based on http url # fetch image based on http url
if data[:url].present? if data[:url].present?
if data[:url].class == Tempfile if data[:url].instance_of?(Tempfile)
logger.info "Reading image from tempfile '#{data[:url].inspect}'" logger.info "Reading image from tempfile '#{data[:url].inspect}'"
content = data[:url].read content = data[:url].read
filename = data[:url].path filename = data[:url].path

View file

@ -88,7 +88,7 @@ generate email with S/MIME
# place to add inline attachments related to html alternative # place to add inline attachments related to html alternative
attr[:attachments]&.each do |attachment| attr[:attachments]&.each do |attachment|
next if attachment.class == Hash next if attachment.instance_of?(Hash)
next if attachment.preferences['Content-ID'].blank? next if attachment.preferences['Content-ID'].blank?
attachment = Mail::Part.new do attachment = Mail::Part.new do
@ -107,7 +107,7 @@ generate email with S/MIME
# add attachments # add attachments
attr[:attachments]&.each do |attachment| attr[:attachments]&.each do |attachment|
if attachment.class == Hash if attachment.instance_of?(Hash)
attachment['content-id'] = nil attachment['content-id'] = nil
mail.attachments[attachment[:filename]] = attachment mail.attachments[attachment[:filename]] = attachment
else else

View file

@ -678,11 +678,12 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again
filename = file.header[:content_disposition].try(:filename) filename = file.header[:content_disposition].try(:filename)
rescue rescue
begin 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 filename = $3
elsif file.header[:content_disposition].to_s =~ /(filename|name)(\*{0,1})='(.+?)'/i when /(filename|name)(\*{0,1})='(.+?)'/i
filename = $3 filename = $3
elsif file.header[:content_disposition].to_s =~ /(filename|name)(\*{0,1})=(.+?);/i when /(filename|name)(\*{0,1})=(.+?);/i
filename = $3 filename = $3
end end
rescue rescue
@ -691,11 +692,12 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again
end end
begin 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 filename = $3
elsif file.header[:content_disposition].to_s =~ /(filename|name)(\*{0,1})='(.+?)'/i when /(filename|name)(\*{0,1})='(.+?)'/i
filename = $3 filename = $3
elsif file.header[:content_disposition].to_s =~ /(filename|name)(\*{0,1})=(.+?);/i when /(filename|name)(\*{0,1})=(.+?);/i
filename = $3 filename = $3
end end
rescue rescue
@ -704,11 +706,12 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again
# as fallback, use raw values # as fallback, use raw values
if filename.blank? 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 filename = $3
elsif headers_store['Content-Disposition'].to_s =~ /(filename|name)(\*{0,1})='(.+?)'/i when /(filename|name)(\*{0,1})='(.+?)'/i
filename = $3 filename = $3
elsif headers_store['Content-Disposition'].to_s =~ /(filename|name)(\*{0,1})=(.+?);/i when /(filename|name)(\*{0,1})=(.+?);/i
filename = $3 filename = $3
end end
end end

View file

@ -247,8 +247,8 @@ returns
record_attributes_with_association_names = record.attributes_with_association_names record_attributes_with_association_names = record.attributes_with_association_names
records_attributes_with_association_names.push 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| record_attributes_with_association_names.each do |key, value|
next if value.class == ActiveSupport::HashWithIndifferentAccess next if value.instance_of?(ActiveSupport::HashWithIndifferentAccess)
next if value.class == Hash next if value.instance_of?(Hash)
next if csv_attributes_ignored&.include?(key.to_sym) next if csv_attributes_ignored&.include?(key.to_sym)
next if key.end_with?('_id') next if key.end_with?('_id')
next if key.end_with?('_ids') next if key.end_with?('_ids')
@ -269,11 +269,11 @@ returns
position = -1 position = -1
header.each do |key| header.each do |key|
position += 1 position += 1
if record[key].class == ActiveSupport::TimeWithZone if record[key].instance_of?(ActiveSupport::TimeWithZone)
row.push record[key].iso8601 row.push record[key].iso8601
next next
end end
if record[key].class == Array if record[key].instance_of?(Array)
entry_count = -2 entry_count = -2
record[key].each do |entry| record[key].each do |entry|
entry_count += 1 entry_count += 1

View file

@ -356,7 +356,7 @@ Cti::Log.process(
user = params['user'] user = params['user']
queue = params['queue'] queue = params['queue']
call_id = params['callId'] || params['call_id'] call_id = params['callId'] || params['call_id']
if user.class == Array if user.instance_of?(Array)
user = user.join(', ') user = user.join(', ')
end end

View file

@ -25,7 +25,7 @@ class Observer::Sla::TicketRebuildEscalation < ActiveRecord::Observer
# check if condition has changed # check if condition has changed
changed = false 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] %w[condition calendar_id first_response_time update_time solution_time]
else else
%w[timezone business_hours default ical_url public_holidays] %w[timezone business_hours default ical_url public_holidays]

View file

@ -72,7 +72,7 @@ class Observer::Ticket::Article::CommunicateTwitter::BackgroundJob
end end
# regular tweet # regular tweet
elsif tweet.class == Twitter::Tweet elsif tweet.instance_of?(Twitter::Tweet)
tweet_type = 'Tweet' tweet_type = 'Tweet'
article.from = "@#{tweet.user.screen_name}" article.from = "@#{tweet.user.screen_name}"
if tweet.user_mentions 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 # validate value / allow blank but only if pre_condition exists and is not specific
if !selector.key?('value') || 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?) (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'].nil?
return nil if selector['pre_condition'].respond_to?(:blank?) && selector['pre_condition'].blank? return nil if selector['pre_condition'].respond_to?(:blank?) && selector['pre_condition'].blank?

View file

@ -134,7 +134,7 @@ class Transaction::Slack
end end
# check action # check action
if local_config['types'].class == Array if local_config['types'].instance_of?(Array)
hit = false hit = false
local_config['types'].each do |type| local_config['types'].each do |type|
next if type.to_s != @item[:type].to_s next if type.to_s != @item[:type].to_s
@ -148,7 +148,7 @@ class Transaction::Slack
end end
# check group # check group
if local_config['group_ids'].class == Array if local_config['group_ids'].instance_of?(Array)
hit = false hit = false
local_config['group_ids'].each do |group_id| local_config['group_ids'].each do |group_id|
next if group_id.to_s != ticket.group_id.to_s next if group_id.to_s != ticket.group_id.to_s

View file

@ -226,7 +226,7 @@ or
def self.timestamp(locale, timezone, timestamp) def self.timestamp(locale, timezone, timestamp)
if timestamp.class == String if timestamp.instance_of?(String)
begin begin
timestamp_parsed = Time.zone.parse(timestamp) timestamp_parsed = Time.zone.parse(timestamp)
return timestamp.to_s if !timestamp_parsed return timestamp.to_s if !timestamp_parsed
@ -272,7 +272,7 @@ or
def self.date(locale, date) def self.date(locale, date)
if date.class == String if date.instance_of?(String)
begin begin
date_parsed = Date.parse(date) date_parsed = Date.parse(date)
return date.to_s if !date_parsed return date.to_s if !date_parsed

View file

@ -34,7 +34,7 @@ class FixedStoreUpgradeRor45 < ActiveRecord::Migration[5.0]
end end
def cleanup(value) def cleanup(value)
if value.class == ActionController::Parameters if value.instance_of?(ActionController::Parameters)
value = value.permit!.to_h value = value.permit!.to_h
end end
return value if value.class != ActiveSupport::HashWithIndifferentAccess && value.class != Hash return value if value.class != ActiveSupport::HashWithIndifferentAccess && value.class != Hash

View file

@ -1,10 +1,10 @@
class CleanupUserPreferencesNotificationSound2 < ActiveRecord::Migration[5.1] class CleanupUserPreferencesNotificationSound2 < ActiveRecord::Migration[5.1]
def local_to_h!(value) def local_to_h!(value)
if value.class == ActionController::Parameters if value.instance_of?(ActionController::Parameters)
value = value.permit!.to_h value = value.permit!.to_h
end 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.each_key do |local_key|
value[local_key] = local_to_h!(value[local_key]) value[local_key] = local_to_h!(value[local_key])
end end

View file

@ -16,11 +16,11 @@ class FixedTwitterTicketArticlePreferences7 < ActiveRecord::Migration[5.0]
next if value.class != ActiveSupport::HashWithIndifferentAccess next if value.class != ActiveSupport::HashWithIndifferentAccess
value.each do |sub_key, sub_level| value.each do |sub_key, sub_level|
if sub_level.class == NilClass if sub_level.instance_of?(NilClass)
value[sub_key] = nil value[sub_key] = nil
next next
end 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 value[sub_key] = sub_level.to_h
changed = true changed = true
next 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) 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 ', ' column_names = index_columns.split ', '
if column_names.class == Array if column_names.instance_of?(Array)
index_columns_new = [] index_columns_new = []
column_names.each do |i| column_names.each do |i|
if i =~ /^"(name|login|locale|alias)"$/ || i.end_with?('name"') if i =~ /^"(name|login|locale|alias)"$/ || i.end_with?('name"')

View file

@ -324,7 +324,7 @@ cleanup html string:
end end
# remove not needed new lines # 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 if !node.parent || (node.parent.name != 'pre' && node.parent.name != 'code') # rubocop:disable Style/SoleNestedConditional
content = node.content content = node.content
if content if content

View file

@ -128,7 +128,7 @@ or with filter:
raise "Can't fetch objects from #{url}: #{result.error}" if !result.success? raise "Can't fetch objects from #{url}: #{result.error}" if !result.success?
# add link to idoit # add link to idoit
if result.data['result'].class == Array if result.data['result'].instance_of?(Array)
result.data['result'].each do |item| result.data['result'].each do |item|
next if !item['id'] next if !item['id']

View file

@ -173,8 +173,8 @@ examples how to use
private private
def convert_to_timezone(value) def convert_to_timezone(value)
return Translation.timestamp(@locale, @timezone, value) if value.class == ActiveSupport::TimeWithZone return Translation.timestamp(@locale, @timezone, value) if value.instance_of?(ActiveSupport::TimeWithZone)
return Translation.date(@locale, value) if value.class == Date return Translation.date(@locale, value) if value.instance_of?(Date)
value value
end end

View file

@ -1,7 +1,7 @@
module PushMessages module PushMessages
def self.enabled? def self.enabled?
return true if Thread.current[:push_messages].class == Array return true if Thread.current[:push_messages].instance_of?(Array)
false false
end end

View file

@ -122,7 +122,7 @@ class TwitterSync
# normalize message # normalize message
message = {} message = {}
if tweet.class == Twitter::Tweet if tweet.instance_of?(Twitter::Tweet)
message = { message = {
type: 'tweet', type: 'tweet',
text: tweet.text, text: tweet.text,
@ -610,11 +610,11 @@ or
# replace Twitter::NullObject with nill to prevent elasticsearch index issue # replace Twitter::NullObject with nill to prevent elasticsearch index issue
preferences.each do |key, value| 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 preferences[key] = value.to_h
next next
end end
if value.class == Twitter::NullObject if value.instance_of?(Twitter::NullObject)
preferences[key] = nil preferences[key] = nil
next next
end end
@ -622,11 +622,11 @@ or
next if !value.is_a?(Hash) next if !value.is_a?(Hash)
value.each do |sub_key, sub_level| value.each do |sub_key, sub_level|
if sub_level.class == NilClass if sub_level.instance_of?(NilClass)
value[sub_key] = nil value[sub_key] = nil
next next
end 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 value[sub_key] = sub_level.to_h
next next
end 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 allow(backend).to receive(:config).and_call_original
migrate migrate
@ -36,7 +36,7 @@ RSpec.describe Issue1905ExchangeLoginFromRemoteId, type: :db_migration do
shared_examples 'irrelevant config' do shared_examples 'irrelevant config' do
it 'does not change the 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=) expect(backend).not_to receive(:config=)
migrate migrate
end end

View file

@ -14,8 +14,8 @@ RSpec.describe ObjectManagerAttributeDateRemoveFuturePast, type: :db_migration d
# mock interfaces to save time # mock interfaces to save time
# otherwise we would have to reseed the database # 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!) allow(subject).to receive(:save!)
migrate migrate
@ -39,7 +39,7 @@ RSpec.describe ObjectManagerAttributeDateRemoveFuturePast, type: :db_migration d
# mock interfaces to save time # mock interfaces to save time
# otherwise we would have to reseed the database # 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(subject).to receive(:save!)
expect { migrate }.not_to raise_error 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 it 'calls search_index_update_backend on matching record' do
user = create(:user) user = create(:user)
expect(::User).to receive(:lookup).with(id: user.id).and_return(user) allow(::User).to receive(:lookup).with(id: user.id).and_return(user)
expect(user).to receive(:search_index_update_backend) allow(user).to receive(:search_index_update_backend)
described_class.perform_now('User', user.id) described_class.perform_now('User', user.id)
expect(user).to have_received(:search_index_update_backend)
end end
it "doesn't perform for non existing records" do it "doesn't perform for non existing records" do
id = 9999 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) described_class.perform_now('User', id)
expect(SearchIndexBackend).not_to have_received(:add)
end end
it 'retries on exception' do 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) described_class.perform_now('User', 1)
expect(described_class).to have_been_enqueued expect(described_class).to have_been_enqueued
end end

View file

@ -12,7 +12,7 @@ RSpec.describe Auth::Developer do
it "authenticates users with password 'test'" do it "authenticates users with password 'test'" do
allow(Setting).to receive(:get) 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') result = instance.valid?(user, 'test')
@ -26,7 +26,7 @@ RSpec.describe Auth::Developer do
it "doesn't authenticate if developer mode is off" do it "doesn't authenticate if developer mode is off" do
allow(Setting).to receive(:get) 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) result = instance.valid?(user, password)
@ -36,7 +36,7 @@ RSpec.describe Auth::Developer do
it "doesn't authenticate with correct password" do it "doesn't authenticate with correct password" do
allow(Setting).to receive(:get) 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) result = instance.valid?(user, password)

View file

@ -14,10 +14,10 @@ RSpec.describe ::Auth::Ldap do
it 'authenticates users' do it 'authenticates users' do
allow(Setting).to receive(:get) 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) 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) result = instance.valid?(user, password)
expect(result).to be true expect(result).to be true
@ -26,7 +26,7 @@ RSpec.describe ::Auth::Ldap do
it 'authenticates via configurable user attributes' do it 'authenticates via configurable user attributes' do
allow(Setting).to receive(:get) 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( instance = described_class.new(
adapter: described_class.name, adapter: described_class.name,
@ -34,9 +34,9 @@ RSpec.describe ::Auth::Ldap do
) )
ldap_user = double 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) result = instance.valid?(user, password)
expect(result).to be true 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 it "doesn't authenticate if 'ldap_integration' Setting is disabled" do
allow(Setting).to receive(:get) 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) result = instance.valid?(user, password)
expect(result).to be false expect(result).to be false
@ -56,10 +56,10 @@ RSpec.describe ::Auth::Ldap do
it "doesn't authenticate if ldap says 'nope'" do it "doesn't authenticate if ldap says 'nope'" do
allow(Setting).to receive(:get) 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) 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) result = instance.valid?(user, password)
expect(result).to be false expect(result).to be false

View file

@ -23,8 +23,10 @@ end
RSpec.shared_examples 'Import::BaseFactory extender' do RSpec.shared_examples 'Import::BaseFactory extender' do
it 'calls new on determined backend object' do it 'calls new on determined backend object' do
record = double() record = double()
expect(described_class).to receive(:backend_class).and_return(Class) allow(described_class).to receive(:backend_class).and_return(Class)
expect(Class).to receive(:new).with(record, any_args) allow(Class).to receive(:new)
described_class.import([record]) described_class.import([record])
expect(Class).to have_received(:new).with(record, any_args)
end end
end end

View file

@ -7,12 +7,14 @@ RSpec.describe Import::Helper do
context 'import mode' do context 'import mode' do
it 'checks if import_mode is active' 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 expect( described_class.check_import_mode ).to be true
end end
it 'throws an exception if import_mode is disabled' do 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) expect { described_class.check_import_mode }.to raise_error(RuntimeError)
end end
end end
@ -20,12 +22,14 @@ RSpec.describe Import::Helper do
context 'system init' do context 'system init' do
it 'checks if system_init_done is active' 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 expect( described_class.check_system_init_done ).to be true
end end
it 'throws an exception if system_init_done is disabled' do 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) expect { described_class.check_system_init_done }.to raise_error(RuntimeError)
end end
end end

View file

@ -31,7 +31,7 @@ RSpec.describe Import::OTRS::Article::AttachmentFactory do
end end
def article_attachment_expectations(article_attachments) 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 end
it_behaves_like 'Import factory' 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) } let(:start_import_test) { described_class.new(object_structure) }
it 'finds customers by email' do 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) expect(import_object).not_to receive(:create)
start_import_test start_import_test
end end
it 'finds customers by login' do it 'finds customers by login' do
expect(import_object).to receive(:find_by).with(email: 'kunde2@kunde.de') allow(import_object).to receive(:find_by)
expect(import_object).to receive(:find_by).with(login: 'kunde2@kunde.de').and_return(existing_object) allow(import_object).to receive(:find_by).with(login: 'kunde2@kunde.de').and_return(existing_object)
expect(import_object).not_to receive(:create) expect(import_object).not_to receive(:create)
start_import_test start_import_test
end end
it 'creates customers' do 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(:find_by).at_least(:once)
expect(import_object).to receive(:create).and_return(existing_object)
start_import_test start_import_test
end end

View file

@ -3,14 +3,16 @@ require 'rails_helper'
RSpec.describe Import::OTRS::Article do RSpec.describe Import::OTRS::Article do
def creates_with(zammad_structure) 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(import_object).to receive(:save)
expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence)
start_import_test start_import_test
end end
def updates_with(zammad_structure) 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(existing_object).to receive(:update!).with(zammad_structure)
expect(import_object).not_to receive(:new) expect(import_object).not_to receive(:new)
start_import_test start_import_test

View file

@ -3,13 +3,15 @@ require 'rails_helper'
RSpec.describe Import::OTRS::Customer do RSpec.describe Import::OTRS::Customer do
def creates_with(zammad_structure) 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) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence)
start_import_test start_import_test
end end
def updates_with(zammad_structure) 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(existing_object).to receive(:update!).with(zammad_structure)
expect(import_object).not_to receive(:new) expect(import_object).not_to receive(:new)
start_import_test start_import_test
@ -62,8 +64,8 @@ RSpec.describe Import::OTRS::Customer do
end end
it 'finds Organizations by OTRS CustomerID' do it 'finds Organizations by OTRS CustomerID' do
expect(Import::OTRS::Requester).to receive(:load).and_return(otrs_dummy_response) allow(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_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) expect(described_class.by_customer_id(customer_id)).to be(existing_object)
end end

View file

@ -3,28 +3,30 @@ require 'rails_helper'
RSpec.describe Import::OTRS::CustomerUser do RSpec.describe Import::OTRS::CustomerUser do
def creates_with(zammad_structure) def creates_with(zammad_structure)
expect_organization_lookup allow_organization_lookup
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(import_object).to receive(:save)
expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence)
start_import_test start_import_test
end end
def updates_with(zammad_structure) def updates_with(zammad_structure)
expect_organization_lookup allow_organization_lookup
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 # we delete the :role_ids from the zammad_structure to make sure that
# a) role_ids call returns the initial role_ids # a) role_ids call returns the initial role_ids
# b) and update! gets called without them # 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(existing_object).to receive(:update!).with(zammad_structure)
expect(import_object).not_to receive(:new) expect(import_object).not_to receive(:new)
start_import_test start_import_test
end end
def expect_organization_lookup def allow_organization_lookup
expect(Import::OTRS::Customer).to receive(:by_customer_id).and_return(organization) allow(Import::OTRS::Customer).to receive(:by_customer_id).and_return(organization)
expect(organization).to receive(:id).and_return(organization_id) allow(organization).to receive(:id).and_return(organization_id)
end end
def load_customer_json(file) def load_customer_json(file)

View file

@ -8,7 +8,7 @@ RSpec.describe Import::OTRS::DynamicField do
it_behaves_like 'Import::OTRS::DynamicField' it_behaves_like 'Import::OTRS::DynamicField'
it 'requires an implementation of init_callback' do 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 expect do
start_import_test start_import_test
end.to raise_error(RuntimeError) end.to raise_error(RuntimeError)

View file

@ -9,8 +9,10 @@ RSpec.describe Import::OTRS::PriorityFactory do
import_data = { import_data = {
name: 'test', name: 'test',
} }
expect(::Import::OTRS::Priority).to receive(:new).with(import_data) allow(::Import::OTRS::Priority).to receive(:new)
described_class.import([import_data]) described_class.import([import_data])
expect(::Import::OTRS::Priority).to have_received(:new).with(import_data)
end end
it 'sets default create Priority' do it 'sets default create Priority' do
@ -19,7 +21,7 @@ RSpec.describe Import::OTRS::PriorityFactory do
priority.callback_loop = true priority.callback_loop = true
priority.save 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 described_class.update_attribute_settings
priority.reload priority.reload
@ -33,7 +35,7 @@ RSpec.describe Import::OTRS::PriorityFactory do
priority.callback_loop = true priority.callback_loop = true
priority.save 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 described_class.update_attribute_settings
priority.reload priority.reload

View file

@ -3,14 +3,16 @@ require 'rails_helper'
RSpec.describe Import::OTRS::Priority do RSpec.describe Import::OTRS::Priority do
def creates_with(zammad_structure) 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(import_object).to receive(:save)
expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence)
start_import_test start_import_test
end end
def updates_with(zammad_structure) 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(existing_object).to receive(:update!).with(zammad_structure)
expect(import_object).not_to receive(:new) expect(import_object).not_to receive(:new)
start_import_test start_import_test

View file

@ -3,14 +3,16 @@ require 'rails_helper'
RSpec.describe Import::OTRS::Queue do RSpec.describe Import::OTRS::Queue do
def creates_with(zammad_structure) 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(import_object).to receive(:save)
expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence)
start_import_test start_import_test
end end
def updates_with(zammad_structure) 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(existing_object).to receive(:update!).with(zammad_structure)
expect(import_object).not_to receive(:new) expect(import_object).not_to receive(:new)
start_import_test start_import_test

View file

@ -19,20 +19,20 @@ RSpec.describe Import::OTRS::Requester do
let(:response) do let(:response) do
response = double() response = double()
response_body = double() response_body = double()
expect(response_body).to receive(:to_s).at_least(:once).and_return('{"Result": {}}') allow(response_body).to receive(:to_s).at_least(:once).and_return('{"Result": {}}')
expect(response).to receive('success?').at_least(:once).and_return(true) allow(response).to receive('success?').at_least(:once).and_return(true)
expect(response).to receive('body').at_least(:once).and_return(response_body) allow(response).to receive('body').at_least(:once).and_return(response_body)
response response
end end
it 'is active if no args are given' do 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')
described_class.load('Ticket') described_class.load('Ticket')
end end
it 'is not active if args are given' do 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: 10)
described_class.load('Ticket', offset: 20) described_class.load('Ticket', offset: 20)
end end

View file

@ -57,7 +57,7 @@ RSpec.describe Import::OTRS::StateFactory do
name: 'pending_time', name: 'pending_time',
) )
expect(Import::OTRS).to receive(:diff?).and_return(true) allow(Import::OTRS).to receive(:diff?).and_return(true)
expect do expect do
described_class.update_attribute_settings described_class.update_attribute_settings
@ -81,8 +81,8 @@ RSpec.describe Import::OTRS::StateFactory do
state.callback_loop = true state.callback_loop = true
state.save state.save
expect(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_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_follow_up).and_return(state.name)
described_class.update_attribute described_class.update_attribute
state.reload state.reload
@ -98,7 +98,7 @@ RSpec.describe Import::OTRS::StateFactory do
state.callback_loop = true state.callback_loop = true
state.save 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 described_class.update_attribute_settings
state.reload state.reload

View file

@ -3,15 +3,17 @@ require 'rails_helper'
RSpec.describe Import::OTRS::State do RSpec.describe Import::OTRS::State do
def creates_with(zammad_structure) def creates_with(zammad_structure)
expect(import_object).to receive(:find_by).and_return(nil) allow(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(:new).with(zammad_structure).and_call_original
expect_any_instance_of(import_object).to receive(:save) expect_any_instance_of(import_object).to receive(:save)
expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence)
start_import_test start_import_test
end end
def updates_with(zammad_structure) 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(existing_object).to receive(:update!).with(zammad_structure)
expect(import_object).not_to receive(:new) expect(import_object).not_to receive(:new)
start_import_test start_import_test

View file

@ -3,15 +3,17 @@ require 'rails_helper'
RSpec.describe Import::OTRS::Ticket do RSpec.describe Import::OTRS::Ticket do
def creates_with(zammad_structure) 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(import_object).to receive(:save)
expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence)
start_import_test start_import_test
end end
def updates_with(zammad_structure) 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) allow(existing_object).to receive(:update!).with(zammad_structure)
expect(import_object).not_to receive(:new) expect(import_object).not_to receive(:new)
start_import_test start_import_test
end end

View file

@ -3,19 +3,21 @@ require 'rails_helper'
RSpec.describe Import::OTRS::User do RSpec.describe Import::OTRS::User do
def creates_with(zammad_structure) def creates_with(zammad_structure)
expect(import_object).to receive(:find_by).and_return(nil) allow(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(:new).with(zammad_structure).and_call_original
expect_any_instance_of(import_object).to receive(:save) expect_any_instance_of(import_object).to receive(:save)
expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence) expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence)
start_import_test start_import_test
end end
def updates_with(zammad_structure) 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 # we delete the :role_ids from the zammad_structure to make sure that
# a) role_ids call returns the initial role_ids # a) role_ids call returns the initial role_ids
# b) and update! gets called without them # 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(existing_object).to receive(:update!).with(zammad_structure)
expect(import_object).not_to receive(:new) expect(import_object).not_to receive(:new)
start_import_test start_import_test
@ -33,7 +35,7 @@ RSpec.describe Import::OTRS::User do
end end
def user_expectations def user_expectations
expect(User).to receive(:where).and_return([]) allow(User).to receive(:where).and_return([])
end end
# this is really bad and should get improved! # 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 it 'returns a Hash of groups' do
ldap_entry = build(:ldap_entry) 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) expect(instance.list).to be_a(Hash)
end end
end end
@ -99,7 +99,7 @@ RSpec.describe Ldap::Group do
end end
it 'tries filters and returns first one with entries' do 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) expect(instance.filter).to be_a(String)
end end

View file

@ -28,12 +28,13 @@ RSpec.describe Ldap::Guid do
end end
it 'tunnels to instance method' do it 'tunnels to instance method' do
instance = double() instance = double()
expect(instance).to receive(:hex) allow(instance).to receive(:hex)
expect(described_class).to receive(:new).with(string).and_return(instance) allow(described_class).to receive(:new).with(string).and_return(instance)
described_class.hex(string) described_class.hex(string)
expect(instance).to have_received(:hex)
end end
end end
@ -46,10 +47,11 @@ RSpec.describe Ldap::Guid do
it 'tunnels to instance method' do it 'tunnels to instance method' do
instance = double() instance = double()
expect(instance).to receive(:string) allow(instance).to receive(:string)
expect(described_class).to receive(:new).with(hex).and_return(instance) allow(described_class).to receive(:new).with(hex).and_return(instance)
described_class.string(hex) described_class.string(hex)
expect(instance).to have_received(:string)
end end
end end

View file

@ -94,24 +94,24 @@ RSpec.describe Ldap::User do
it 'validates username and password' do it 'validates username and password' do
connection = double() connection = double()
expect(mocked_ldap).to receive(:connection).and_return(connection) allow(mocked_ldap).to receive(:connection).and_return(connection)
build(:ldap_entry) build(:ldap_entry)
expect(mocked_ldap).to receive(:base_dn) allow(mocked_ldap).to receive(:base_dn)
expect(connection).to receive(:bind_as).and_return(true) allow(connection).to receive(:bind_as).and_return(true)
expect(instance.valid?('example_username', 'password')).to be true expect(instance.valid?('example_username', 'password')).to be true
end end
it 'fails for invalid credentials' do it 'fails for invalid credentials' do
connection = double() connection = double()
expect(mocked_ldap).to receive(:connection).and_return(connection) allow(mocked_ldap).to receive(:connection).and_return(connection)
build(:ldap_entry) build(:ldap_entry)
expect(mocked_ldap).to receive(:base_dn) allow(mocked_ldap).to receive(:base_dn)
expect(connection).to receive(:bind_as).and_return(false) allow(connection).to receive(:bind_as).and_return(false)
expect(instance.valid?('example_username', 'wrong_password')).to be false expect(instance.valid?('example_username', 'wrong_password')).to be false
end end
@ -132,7 +132,7 @@ RSpec.describe Ldap::User do
# blacklisted attribute # blacklisted attribute
ldap_entry['lastlogon'] = DateTime.current 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 attributes = instance.attributes
@ -159,7 +159,7 @@ RSpec.describe Ldap::User do
end end
it 'tries filters and returns first one with entries' do 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) expect(instance.filter).to be_a(String)
end end
@ -187,7 +187,7 @@ RSpec.describe Ldap::User do
# selectable attribute # selectable attribute
ldap_entry['objectguid'] = 'f742b361-32c6-4a92-baaa-eaae7df657ee' 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) expect(instance.uid_attribute).to be_a(String)
end end

View file

@ -10,7 +10,7 @@ RSpec.describe Ldap do
let(:mocked_ldap) { double(bind: true) } let(:mocked_ldap) { double(bind: true) }
def mock_initialization(given:, expected:) 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) described_class.new(given)
end end
@ -43,7 +43,7 @@ RSpec.describe Ldap do
port: 1337, 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( mock_initialization(
given: config, given: config,
@ -64,12 +64,13 @@ RSpec.describe Ldap do
port: 1337, port: 1337,
} }
expect(mocked_ldap).not_to receive(:auth).with(config[:bind_user], config[:bind_pw]) allow(mocked_ldap).to receive(:auth)
mock_initialization( mock_initialization(
given: config, given: config,
expected: params, expected: params,
) )
expect(mocked_ldap).not_to have_received(:auth).with(config[:bind_user], config[:bind_pw])
end end
it 'requires bind_pw' do it 'requires bind_pw' do
@ -85,12 +86,13 @@ RSpec.describe Ldap do
port: 1337, port: 1337,
} }
expect(mocked_ldap).not_to receive(:auth).with(config[:bind_user], config[:bind_pw]) allow(mocked_ldap).to receive(:auth)
mock_initialization( mock_initialization(
given: config, given: config,
expected: params, expected: params,
) )
expect(mocked_ldap).not_to have_received(:auth).with(config[:bind_user], config[:bind_pw])
end end
end end
@ -191,7 +193,8 @@ RSpec.describe Ldap do
port: 1337, 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( mock_initialization(
given: nil, given: nil,
@ -207,7 +210,7 @@ RSpec.describe Ldap do
# as return param of Net::LDAP.new # as return param of Net::LDAP.new
let(:mocked_ldap) { double(bind: true) } let(:mocked_ldap) { double(bind: true) }
let(:instance) do 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( described_class.new(
host: 'localhost', host: 'localhost',
port: 1337, port: 1337,
@ -221,12 +224,11 @@ RSpec.describe Ldap do
end end
it 'returns preferences' do it 'returns preferences' do
attributes = { attributes = {
namingcontexts: ['ou=dep1,ou=org', 'ou=dep2,ou=org'] 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) expect(instance.preferences).to eq(attributes)
end end
end end
@ -256,7 +258,7 @@ RSpec.describe Ldap do
} }
yield_entry = build(:ldap_entry) 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 check_entry = nil
instance.search(filter, additional) { |entry| check_entry = entry } instance.search(filter, additional) { |entry| check_entry = entry }
@ -276,7 +278,7 @@ RSpec.describe Ldap do
} }
yield_entry = build(:ldap_entry) 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 check_entry = nil
instance.search(filter, additional) { |entry| check_entry = entry } instance.search(filter, additional) { |entry| check_entry = entry }
@ -291,7 +293,7 @@ RSpec.describe Ldap do
scope: Net::LDAP::SearchScope_WholeSubtree, 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( instance = described_class.new(
host: 'localhost', host: 'localhost',
port: 1337, port: 1337,
@ -299,7 +301,7 @@ RSpec.describe Ldap do
) )
yield_entry = build(:ldap_entry) 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 check_entry = nil
instance.search(filter) { |entry| check_entry = entry } instance.search(filter) { |entry| check_entry = entry }
@ -316,22 +318,20 @@ RSpec.describe Ldap do
end end
it 'returns true if entries are present' do it 'returns true if entries are present' do
params = { params = {
filter: filter 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 expect(instance.entries?(filter)).to be true
end end
it 'returns false if no entries are present' do it 'returns false if no entries are present' do
params = { params = {
filter: filter 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 expect(instance.entries?(filter)).to be false
end end

View file

@ -3,27 +3,29 @@ require 'rails_helper'
RSpec.describe MigrationJob::LdapSamaccountnameToUid do RSpec.describe MigrationJob::LdapSamaccountnameToUid do
it 'performs no changes if no LDAP config present' do it 'performs no changes if no LDAP config present' do
expect(Setting).not_to receive(:set) allow(Setting).to receive(:set)
expect(Import::Ldap).to receive(:config).and_return(nil) allow(Import::Ldap).to receive(:config).and_return(nil)
described_class.new.perform described_class.new.perform
expect(Setting).not_to have_received(:set)
end end
it 'performs no changes if uid attributes equals' do it 'performs no changes if uid attributes equals' do
expect(Setting).not_to receive(:set) allow(Setting).to receive(:set)
ldap_config = { ldap_config = {
'user_uid' => 'samaccountname' '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() ldap_user = double()
expect(ldap_user).to receive(:uid_attribute).and_return('samaccountname') allow(ldap_user).to receive(:uid_attribute).and_return('samaccountname')
expect(::Ldap::User).to receive(:new).and_return(ldap_user) allow(::Ldap::User).to receive(:new).and_return(ldap_user)
allow(::Ldap).to receive(:new) allow(::Ldap).to receive(:new)
described_class.new.perform described_class.new.perform
expect(Setting).not_to have_received(:set)
end end
it 'performs Setting change if uid attribute differ' do it 'performs Setting change if uid attribute differ' do
@ -34,16 +36,18 @@ RSpec.describe MigrationJob::LdapSamaccountnameToUid do
'user_uid' => 'samaccountname' '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() ldap_user = double()
expect(ldap_user).to receive(:uid_attribute).and_return('objectguid') allow(ldap_user).to receive(:uid_attribute).and_return('objectguid')
expect(::Ldap::User).to receive(:new).and_return(ldap_user) allow(::Ldap::User).to receive(:new).and_return(ldap_user)
allow(::Ldap).to receive(:new) allow(::Ldap).to receive(:new)
described_class.new.perform described_class.new.perform
expect(Setting).to have_received(:set).with('ldap_config', ldap_config_new)
end end
end end

View file

@ -40,14 +40,14 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence
) )
# LDAP::Group # LDAP::Group
expect(connection).to receive(:search).and_yield(group_entry) allow(connection).to receive(:search).and_yield(group_entry)
expect(connection).to receive(:entries?).and_return(true) allow(connection).to receive(:entries?).and_return(true)
# Sequencer::Unit::Import::Ldap::Users::Total # 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 # 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 expect do
process( process(
@ -70,15 +70,8 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence
group_entry['member'] = ['some.other.dn'] group_entry['member'] = ['some.other.dn']
# LDAP::Group # LDAP::Group
expect(connection).to receive(:search).and_yield(group_entry) allow(connection).to receive(:search).and_yield(group_entry)
expect(connection).to receive(:entries?).and_return(true) 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)
expect do expect do
process( process(
@ -129,15 +122,12 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence
base_dn: 'test' base_dn: 'test'
) )
# LDAP::Group # LDAP::Group and Sequencer::Unit::Import::Ldap::Users::SubSequence
expect(connection).to receive(:search).and_yield(group_entry) allow(connection).to receive(:search).and_yield(group_entry).and_yield(user_entry)
expect(connection).to receive(:entries?).and_return(true) allow(connection).to receive(:entries?).and_return(true)
# Sequencer::Unit::Import::Ldap::Users::Total # 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)
expect do expect do
process( process(
@ -160,15 +150,15 @@ RSpec.describe ::Sequencer::Sequence::Import::Ldap::Users, sequencer: :sequence
group_entry['member'] = ['some.other.dn'] group_entry['member'] = ['some.other.dn']
# LDAP::Group # LDAP::Group
expect(connection).to receive(:search).and_yield(group_entry) allow(connection).to receive(:search).and_yield(group_entry)
expect(connection).to receive(:entries?).and_return(true) allow(connection).to receive(:entries?).and_return(true)
# Sequencer::Unit::Import::Ldap::Users::Total # Sequencer::Unit::Import::Ldap::Users::Total
# cached # cached
# expect(connection).to receive(:count).and_return(1) # expect(connection).to receive(:count).and_return(1)
# Sequencer::Unit::Import::Ldap::Users::SubSequence # 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 expect do
process( process(

View file

@ -16,12 +16,12 @@ RSpec.describe Sequencer::Unit::Common::AttributeMapper, sequencer: :unit do
end end
it 'declares uses from map keys' do 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) expect(described_class.uses).to eq(map.keys)
end end
it 'declares provides from map values' do 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) expect(described_class.provides).to eq(map.values)
end end

View file

@ -25,7 +25,7 @@ RSpec.describe Sequencer::Unit::Import::Common::Mapping::FlatKeys, sequencer: :u
} }
provided = process(parameters) do |instance| provided = process(parameters) do |instance|
expect(instance).to receive(:mapping).and_return(mapping) allow(instance).to receive(:mapping).and_return(mapping)
end end
expect(provided).to eq( 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| provided = process(parameters) do |instance|
expect(instance).to receive(:attribute).and_return(:other_attribute) allow(instance).to receive(:attribute).and_return(:other_attribute)
end end
expect(provided).to include(remote_id: '123abc') 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 it 'replaces whitespaces' do
provided = process do |instance| 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 end
expect(provided[:sanitized_name]).to eq('model_name') expect(provided[:sanitized_name]).to eq('model_name')
@ -21,7 +21,7 @@ RSpec.describe Sequencer::Unit::Import::Common::ObjectAttribute::SanitizedName,
it 'replaces dashes' do it 'replaces dashes' do
provided = process do |instance| 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 end
expect(provided[:sanitized_name]).to eq('model_name') 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 it 'replaces ids suffix' do
provided = process do |instance| 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 end
expect(provided[:sanitized_name]).to eq('model_nos') 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 it 'replaces id suffix' do
provided = process do |instance| 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 end
expect(provided[:sanitized_name]).to eq('model_no') 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 it 'replaces non-ASCII characters' do
provided = process do |instance| 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 end
expect(provided[:sanitized_name]).to eq('a_eroskobing_at_model') 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 it 'queues registered import jobs' do
allow(Setting).to receive(:get) 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 expect do
described_class.queue_registered described_class.queue_registered
@ -89,8 +89,8 @@ RSpec.describe ImportJob do
it "doesn't queue if backend isn't #queueable?" do it "doesn't queue if backend isn't #queueable?" do
allow(Setting).to receive(:get) 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(test_backend_class).to receive(:queueable?).and_return(false) allow(test_backend_class).to receive(:queueable?).and_return(false)
expect do expect do
described_class.queue_registered described_class.queue_registered
@ -100,11 +100,10 @@ RSpec.describe ImportJob do
end end
it "doesn't queue if unfinished job entries exist" do it "doesn't queue if unfinished job entries exist" do
create(:import_job) create(:import_job)
allow(Setting).to receive(:get) 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 expect do
described_class.queue_registered described_class.queue_registered
@ -115,9 +114,11 @@ RSpec.describe ImportJob do
it 'logs errors for invalid registered backends' do it 'logs errors for invalid registered backends' do
allow(Setting).to receive(:get) allow(Setting).to receive(:get)
expect(Setting).to receive(:get).with('import_backends').and_return(['InvalidBackend']) allow(Setting).to receive(:get).with('import_backends').and_return(['InvalidBackend'])
expect(described_class.logger).to receive(:error)
allow(described_class.logger).to receive(:error)
described_class.queue_registered described_class.queue_registered
expect(described_class.logger).to have_received(:error)
end end
end end
@ -149,7 +150,7 @@ RSpec.describe ImportJob do
describe '#start_registered' do describe '#start_registered' do
it 'queues and starts registered import backends' do it 'queues and starts registered import backends' do
allow(Setting).to receive(:get) 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 expect do
described_class.start_registered described_class.start_registered
@ -173,8 +174,8 @@ RSpec.describe ImportJob do
describe '#backends' do describe '#backends' do
it 'returns list of backend namespaces' do it 'returns list of backend namespaces' do
expect(Setting).to receive(:get).with('import_backends').and_return(['Import::Ldap']) allow(Setting).to receive(:get).with('import_backends').and_return(['Import::Ldap'])
expect(Import::Ldap).to receive(:active?).and_return(true) allow(Import::Ldap).to receive(:active?).and_return(true)
backends = described_class.backends backends = described_class.backends
@ -183,18 +184,21 @@ RSpec.describe ImportJob do
end end
it 'returns blank array if none are found' do 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([]) expect(described_class.backends).to eq([])
end end
it "doesn't return invalid backends" do 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([]) expect(described_class.backends).to eq([])
end end
it "doesn't return inactive backends" do it "doesn't return inactive backends" do
expect(Setting).to receive(:get).with('import_backends').and_return(['Import::Ldap']) allow(Setting).to receive(:get).with('import_backends').and_return(['Import::Ldap'])
expect(Import::Ldap).to receive(:active?).and_return(false) allow(Import::Ldap).to receive(:active?).and_return(false)
expect(described_class.backends).to eq([]) expect(described_class.backends).to eq([])
end end
end end
@ -221,7 +225,7 @@ RSpec.describe ImportJob do
instance = create(:import_job) instance = create(:import_job)
error_message = 'Some horrible error' 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 expect do
instance.start instance.start

View file

@ -68,7 +68,7 @@ RSpec.describe ObjectManager::Attribute::Validation, application_handle: 'applic
end end
it 'is skipped because of import_mode is active' do 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) subject.validate(record)
expect(backend).not_to have_received(:validate) expect(backend).not_to have_received(:validate)
end end

View file

@ -67,7 +67,7 @@ RSpec.describe Scheduler do
describe '.cleanup' do describe '.cleanup' do
it 'gets called by .threads' 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 expect do
described_class.threads described_class.threads
end.to throw_symbol(:called) end.to throw_symbol(:called)

View file

@ -1,7 +1,5 @@
require 'rails_helper' require 'rails_helper'
# rubocop:disable Style/CombinableLoops
RSpec.describe 'Integration Placetel', type: :request do RSpec.describe 'Integration Placetel', type: :request do
let(:agent) do let(:agent) do
@ -618,5 +616,3 @@ RSpec.describe 'Integration Placetel', type: :request do
end end
end end
end end
# rubocop:enable Style/CombinableLoops

View file

@ -1,7 +1,5 @@
require 'rails_helper' require 'rails_helper'
# rubocop:disable Style/CombinableLoops
RSpec.describe 'Integration Sipgate', type: :request do RSpec.describe 'Integration Sipgate', type: :request do
let(:agent) do let(:agent) do
@ -490,5 +488,3 @@ RSpec.describe 'Integration Sipgate', type: :request do
end end
end 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 it 'when clicking "Get latest translations" fetches all translations' do
visit 'system/translation' visit 'system/translation'
expect(Translation).to receive(:load).with('de-de').and_return(true) allow(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('en-us').and_return(true)
click '.js-syncChanges' click '.js-syncChanges'

View file

@ -983,7 +983,7 @@ class TestCase < ActiveSupport::TestCase
if params[:css] if params[:css]
element = instance.find_elements(css: params[:css])[0] element = instance.find_elements(css: params[:css])[0]
end end
if params[:value].class == Array if params[:value].instance_of?(Array)
params[:value].each do |key| params[:value].each do |key|
if element if element
element.send_keys(key) element.send_keys(key)