From df61a2c8a13345526adc21df3600984a04869348 Mon Sep 17 00:00:00 2001 From: Anton Savitskiy Date: Wed, 26 Apr 2023 15:34:28 +0300 Subject: [PATCH] style(Style/OpenStructUse): manual --- .rubocop_todo.yml | 7 ------- lib/mongoid/indexable.rb | 4 +++- spec/rails/controller_extension/controller_runtime_spec.rb | 6 +++++- spec/support/rails_mock.rb | 7 +++++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8d77ae1b0..c8ebd04c3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -828,13 +828,6 @@ Style/MultilineBlockChain: - 'spec/mongoid/changeable_spec.rb' - 'spec/mongoid/document_spec.rb' -# Offense count: 4 -Style/OpenStructUse: - Exclude: - - 'lib/mongoid/indexable.rb' - - 'spec/rails/controller_extension/controller_runtime_spec.rb' - - 'spec/support/rails_mock.rb' - # Offense count: 17 # Configuration parameters: AllowedMethods. # AllowedMethods: respond_to_missing? diff --git a/lib/mongoid/indexable.rb b/lib/mongoid/indexable.rb index 6dfeaa271..47f5261b5 100644 --- a/lib/mongoid/indexable.rb +++ b/lib/mongoid/indexable.rb @@ -17,6 +17,8 @@ module Indexable module ClassMethods + IndexSpec = Struct.new(:fields, :key, keyword_init: true) + # Send the actual index creation comments to the MongoDB driver # # @example Create the indexes for the class. @@ -109,7 +111,7 @@ def index(spec, options = nil) # # @return [ Specification ] The found specification. def index_specification(index_hash, index_name = nil) - index = OpenStruct.new(fields: index_hash.keys, key: index_hash) + index = IndexSpec.new(fields: index_hash.keys, key: index_hash) index_specifications.detect do |spec| spec == index || (index_name && index_name == spec.name) end diff --git a/spec/rails/controller_extension/controller_runtime_spec.rb b/spec/rails/controller_extension/controller_runtime_spec.rb index c61435dfa..c16a05805 100644 --- a/spec/rails/controller_extension/controller_runtime_spec.rb +++ b/spec/rails/controller_extension/controller_runtime_spec.rb @@ -41,6 +41,10 @@ def clear_metric! describe 'Collector' do + before do + stub_const('EventPayload', Struct.new(:duration, keyword_init: true)) + end + it 'stores the metric in thread-safe manner' do clear_metric! expect(collector.runtime).to eq(0) @@ -50,7 +54,7 @@ def clear_metric! it 'sets metric on both succeeded and failed' do instance = collector.new - event_payload = OpenStruct.new duration: 42 + event_payload = EventPayload.new(duration: 42) clear_metric! instance.succeeded event_payload diff --git a/spec/support/rails_mock.rb b/spec/support/rails_mock.rb index 7d4b1248b..8f3fb5192 100644 --- a/spec/support/rails_mock.rb +++ b/spec/support/rails_mock.rb @@ -19,11 +19,14 @@ def eager_load!; end end end +ConfigPaths = Struct.new(:expanded, keyword_init: true) +AppConfig = Struct.new(:paths, keyword_init: true) + Rails.env = 'development' Rails.root = Pathname.new('.') Rails.logger = Logger.new($stdout) Rails.application = Rails::Application -Rails.application.config = OpenStruct.new( - paths: { 'app/models' => OpenStruct.new(expanded: ['app/models']) } +Rails.application.config = AppConfig.new( + paths: { 'app/models' => ConfigPaths.new(expanded: ['app/models']) } )