diff --git a/Gemfile.lock b/Gemfile.lock index 9b06b5e67..b51aa745c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -504,7 +504,7 @@ GEM rspec-support (~> 3.10) rspec-support (3.10.2) rszr (0.5.2) - rubocop (1.22.3) + rubocop (1.23.0) parallel (~> 1.10) parser (>= 3.0.0.0) rainbow (>= 2.2.2, < 4.0) diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index c6aa62a66..59583ccb2 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -8,6 +8,7 @@ class Channel::EmailParser RECIPIENT_FIELDS = %w[to cc delivered-to x-original-to envelope-to].freeze SENDER_FIELDS = %w[from reply-to return-path sender].freeze EXCESSIVE_LINKS_MSG = __('This message cannot be displayed because it contains over 5,000 links. Download the raw message below and open it via an Email client if you still wish to view it.').freeze + MESSAGE_STRUCT = Struct.new(:from_display_name, :subject, :msg_size).freeze =begin @@ -927,7 +928,7 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again parsed_incoming_mail = Channel::EmailParser.new.parse(raw_incoming_mail) # construct a dummy mail object - mail = OpenStruct.new + mail = MESSAGE_STRUCT.new mail.from_display_name = parsed_incoming_mail[:from_display_name] mail.subject = parsed_incoming_mail[:subject] mail.msg_size = format('%.2f', MB: raw_incoming_mail.size.to_f / 1024 / 1024) diff --git a/app/models/translation/synchronizes_from_po.rb b/app/models/translation/synchronizes_from_po.rb index d82ad31be..35ba40256 100644 --- a/app/models/translation/synchronizes_from_po.rb +++ b/app/models/translation/synchronizes_from_po.rb @@ -3,6 +3,8 @@ module Translation::SynchronizesFromPo extend ActiveSupport::Concern + TRANSLATION_FILE_STRUCT = Struct.new(:translation, :translation_file, keyword_init: true).freeze + class_methods do # rubocop:disable Metrics/BlockLength def sync @@ -64,7 +66,7 @@ module Translation::SynchronizesFromPo # For 'en-*' locales, treat source as translation as well, to indicate that nothing is missing. translation = source if translation.empty? && locale.start_with?('en') - result[source] = OpenStruct.new(translation: translation, translation_file: file) + result[source] = TRANSLATION_FILE_STRUCT.new(translation: translation, translation_file: file) end end result diff --git a/spec/lib/notification_factory/mailer_spec.rb b/spec/lib/notification_factory/mailer_spec.rb index 03b432ac9..b63b8b7f6 100644 --- a/spec/lib/notification_factory/mailer_spec.rb +++ b/spec/lib/notification_factory/mailer_spec.rb @@ -11,7 +11,7 @@ RSpec.describe NotificationFactory::Mailer do let(:parsed_incoming_mail) { Channel::EmailParser.new.parse raw_incoming_mail } let(:incoming_mail) do - mail = OpenStruct.new + mail = Channel::EmailParser::MESSAGE_STRUCT.new mail.from_display_name = parsed_incoming_mail[:from_display_name] mail.subject = parsed_incoming_mail[:subject] mail.msg_size = format('%.2f', MB: raw_incoming_mail.size.to_f / 1024 / 1024) diff --git a/spec/models/ticket_spec.rb b/spec/models/ticket_spec.rb index c3696d7f0..78da86d8b 100644 --- a/spec/models/ticket_spec.rb +++ b/spec/models/ticket_spec.rb @@ -438,11 +438,16 @@ RSpec.describe Ticket, type: :model do end describe '#perform_changes' do + before do + stub_const('PERFORMABLE_STRUCT', Struct.new(:id, :perform, keyword_init: true)) + end # a `performable` can be a Trigger or a Job # we use DuckTyping and expect that a performable # implements the following interface - let(:performable) { OpenStruct.new(id: 1, perform: perform) } + let(:performable) do + PERFORMABLE_STRUCT.new(id: 1, perform: perform) + end # Regression test for https://github.com/zammad/zammad/issues/2001 describe 'argument handling' do diff --git a/spec/models/translation/translation_synchronizes_from_po_spec.rb b/spec/models/translation/translation_synchronizes_from_po_spec.rb index 94631bbe3..6473e491c 100644 --- a/spec/models/translation/translation_synchronizes_from_po_spec.rb +++ b/spec/models/translation/translation_synchronizes_from_po_spec.rb @@ -48,21 +48,29 @@ RSpec.describe Translation do context 'when getting the en-us strings' do it 'contains the translation for "yes"' do - expect(described_class.strings_for_locale('en-us')).to include( - 'yes' => OpenStruct.new(translation: 'yes', translation_file: 'i18n/zammad.pot'), - 'FORMAT_DATE' => OpenStruct.new(translation: 'mm/dd/yyyy', translation_file: 'i18n/zammad.pot'), - 'FORMAT_DATETIME' => OpenStruct.new(translation: 'mm/dd/yyyy HH:MM', translation_file: 'i18n/zammad.pot'), - ) + expect(described_class.strings_for_locale('en-us')['yes']).to have_attributes(translation: 'yes', translation_file: 'i18n/zammad.pot') + end + + it 'contains the translation for "FORMAT_DATE"' do + expect(described_class.strings_for_locale('en-us')['FORMAT_DATE']).to have_attributes(translation: 'mm/dd/yyyy', translation_file: 'i18n/zammad.pot') + end + + it 'contains the translation for "FORMAT_DATE_TIME"' do + expect(described_class.strings_for_locale('en-us')['FORMAT_DATETIME']).to have_attributes(translation: 'mm/dd/yyyy HH:MM', translation_file: 'i18n/zammad.pot') end end context 'when getting the de-de strings' do it 'contains the translation for "yes"' do - expect(described_class.strings_for_locale('de-de')).to include( - 'yes' => OpenStruct.new(translation: 'ja', translation_file: 'i18n/zammad.de-de.po'), - 'FORMAT_DATE' => OpenStruct.new(translation: 'dd.mm.yyyy', translation_file: 'i18n/zammad.de-de.po'), - 'FORMAT_DATETIME' => OpenStruct.new(translation: 'dd.mm.yyyy HH:MM', translation_file: 'i18n/zammad.de-de.po'), - ) + expect(described_class.strings_for_locale('de-de')['yes']).to have_attributes(translation: 'ja', translation_file: 'i18n/zammad.de-de.po') + end + + it 'contains the translation for "FORMAT_DATE"' do + expect(described_class.strings_for_locale('de-de')['FORMAT_DATE']).to have_attributes(translation: 'dd.mm.yyyy', translation_file: 'i18n/zammad.de-de.po') + end + + it 'contains the translation for "FORMAT_DATE_TIME"' do + expect(described_class.strings_for_locale('de-de')['FORMAT_DATETIME']).to have_attributes(translation: 'dd.mm.yyyy HH:MM', translation_file: 'i18n/zammad.de-de.po') end end end