Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(Style/OpenStructUse): manual #98

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -823,13 +823,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?
Expand Down
4 changes: 3 additions & 1 deletion lib/mongoid/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion spec/rails/controller_extension/controller_runtime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions spec/support/rails_mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']) }
)
Loading