Skip to content

Commit 041de49

Browse files
committed
Remove usage of OpenStruct
1 parent 8feeab2 commit 041de49

File tree

14 files changed

+23
-36
lines changed

14 files changed

+23
-36
lines changed

.rubocop.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ Style/RedundantCondition:
316316
Style/RedundantDoubleSplatHashBraces:
317317
Enabled: true
318318

319+
Style/OpenStructUse:
320+
Enabled: true
321+
319322
Style/ArrayIntersect:
320323
Enabled: true
321324

@@ -355,9 +358,6 @@ Performance/DeletePrefix:
355358
Performance/DeleteSuffix:
356359
Enabled: true
357360

358-
Performance/OpenStruct:
359-
Enabled: true
360-
361361
Performance/InefficientHashSearch:
362362
Enabled: true
363363

Gemfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ gem "cgi", ">= 0.3.6", require: false
3838

3939
gem "prism"
4040

41-
# Became a bundled gem in Ruby 3.5
42-
gem "ostruct"
43-
4441
group :lint do
4542
gem "syntax_tree", "6.1.1", require: false
4643
end

Gemfile.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ GEM
368368
nokogiri (1.16.0-x86_64-linux)
369369
racc (~> 1.4)
370370
os (1.1.4)
371-
ostruct (0.6.0)
372371
parallel (1.24.0)
373372
parser (3.2.2.4)
374373
ast (~> 2.4.1)
@@ -624,7 +623,6 @@ DEPENDENCIES
624623
msgpack (>= 1.7.0)
625624
mysql2 (~> 0.5)
626625
nokogiri (>= 1.8.1, != 1.11.0)
627-
ostruct
628626
pg (~> 1.3)
629627
prism
630628
propshaft (>= 0.1.7)

actionmailer/test/url_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
require "abstract_unit"
44
require "action_controller"
5-
require "ostruct"
65

76
class WelcomeController < ActionController::Base
87
end
@@ -42,7 +41,7 @@ def exercise_url_for(options)
4241
class ActionMailerUrlTest < ActionMailer::TestCase
4342
class DummyModel
4443
def self.model_name
45-
OpenStruct.new(route_key: "dummy_model")
44+
Struct.new(:route_key, :name).new("dummy_model", nil)
4645
end
4746

4847
def persisted?

actionpack/test/controller/http_token_authentication_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# frozen_string_literal: true
22

3-
require "ostruct"
43
require "abstract_unit"
54

65
class HttpTokenAuthenticationTest < ActionController::TestCase
@@ -240,7 +239,7 @@ def sample_request_without_token_key(token)
240239
end
241240

242241
def mock_authorization_request(authorization)
243-
OpenStruct.new(authorization: authorization)
242+
Struct.new(:authorization).new(authorization)
244243
end
245244

246245
def encode_credentials(token, options = {})

actionview/test/lib/controller/fake_models.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class Plane
207207

208208
class << self
209209
def model_name
210-
OpenStruct.new param_key: "airplane"
210+
Struct.new(:param_key).new("airplane")
211211
end
212212
end
213213

actionview/test/template/controller_helper_test.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
# frozen_string_literal: true
22

33
require "abstract_unit"
4-
require "ostruct"
54

65
class ControllerHelperTest < ActionView::TestCase
76
tests ActionView::Helpers::ControllerHelper
87

98
class SpecializedFormBuilder < ActionView::Helpers::FormBuilder ; end
109

1110
def test_assign_controller_sets_default_form_builder
12-
@controller = OpenStruct.new(default_form_builder: SpecializedFormBuilder)
11+
@controller = Struct.new(:default_form_builder).new(SpecializedFormBuilder)
1312
assign_controller(@controller)
1413

1514
assert_equal SpecializedFormBuilder, default_form_builder
1615
end
1716

1817
def test_assign_controller_skips_default_form_builder
19-
@controller = OpenStruct.new
18+
@controller = Object.new
2019
assign_controller(@controller)
2120

2221
assert_nil default_form_builder
2322
end
2423

2524
def test_respond_to
26-
@controller = OpenStruct.new
25+
@controller = Object.new
2726
assign_controller(@controller)
2827
assert_not respond_to?(:params)
2928
assert respond_to?(:assign_controller)
3029

31-
@controller.params = {}
30+
def @controller.params
31+
{}
32+
end
3233
assert respond_to?(:params)
3334
assert respond_to?(:assign_controller)
3435
end

actionview/test/template/form_helper_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
require "abstract_unit"
44
require "controller/fake_models"
5-
require "ostruct"
65

76
class FormHelperTest < ActionView::TestCase
87
include RenderERBUtils
@@ -280,7 +279,7 @@ def test_label_with_locales_fallback_and_nested_attributes
280279
end
281280

282281
def test_label_with_non_active_record_object
283-
form_for(OpenStruct.new(name: "ok"), as: "person", url: "/an", html: { id: "create-person" }) do |f|
282+
form_for(Struct.new(:name).new("ok"), as: "person", url: "/an", html: { id: "create-person" }) do |f|
284283
f.label(:name)
285284
end
286285

actionview/test/template/record_identifier_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
require "abstract_unit"
44
require "controller/fake_models"
5-
require "ostruct"
65

76
class RecordIdentifierTest < ActiveSupport::TestCase
87
include ActionView::RecordIdentifier

activejob/test/support/delayed_job/delayed/backend/test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
# copied from https://github.com/collectiveidea/delayed_job/blob/master/spec/delayed/backend/test.rb
4-
require "ostruct"
54

65
# An in-memory backend suitable only for testing. Tries to behave as if it were an ORM.
76
module Delayed

0 commit comments

Comments
 (0)