Skip to content

Commit

Permalink
Fix potential issue with default serializer inheritance/overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
azimux committed Jan 29, 2025
1 parent d9ba173 commit b799e21
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.0.12] - 2025-01-28

- Fix potential issue with default serializer inheritance/overriding

## [0.0.11] - 2025-01-25

- Allow default_serializers to be changed
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
foobara-http-command-connector (0.0.11)
foobara-http-command-connector (0.0.12)
foobara

GEM
Expand Down Expand Up @@ -54,7 +54,7 @@ GEM
foobara-type-generator
foobara-typescript-react-command-form-generator
foobara-typescript-remote-command-generator
foobara (0.0.50)
foobara (0.0.51)
bigdecimal
foobara-util
foobara-autocrud-generator (0.0.1)
Expand All @@ -80,7 +80,7 @@ GEM
foobara-files-generator
foobara-files-generator (0.0.5)
foobara
foobara-local-files-crud-driver-generator (0.0.2)
foobara-local-files-crud-driver-generator (0.0.3)
foobara
foobara-files-generator
foobara-organization-generator (0.0.2)
Expand Down Expand Up @@ -141,7 +141,7 @@ GEM
rspec (>= 2.99.0, < 4.0)
hashdiff (1.1.2)
json (2.9.1)
language_server-protocol (3.17.0.3)
language_server-protocol (3.17.0.4)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down Expand Up @@ -198,7 +198,7 @@ GEM
rubocop-ast (>= 1.36.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.37.0)
rubocop-ast (1.38.0)
parser (>= 3.3.1.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
Expand Down
18 changes: 16 additions & 2 deletions spec/foobara/command_connectors_http/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def compute

let(:authenticator) { nil }
let(:default_serializers) do
[Foobara::CommandConnectors::Serializers::ErrorsSerializer, Foobara::CommandConnectors::Serializers::JsonSerializer]
[Foobara::CommandConnectors::Serializers::ErrorsSerializer,
Foobara::CommandConnectors::Serializers::JsonSerializer]
end
let(:default_pre_commit_transformer) { nil }

Expand Down Expand Up @@ -650,7 +651,9 @@ def execute

context "with AggregateSerializer" do
let(:serializers) { Foobara::CommandConnectors::Serializers::AggregateSerializer }
let(:pre_commit_transformers) { Foobara::CommandConnectors::Transformers::LoadAggregatesPreCommitTransformer }
let(:pre_commit_transformers) {
Foobara::CommandConnectors::Transformers::LoadAggregatesPreCommitTransformer
}

context "when user exists with a referral" do
let(:command_class) do
Expand Down Expand Up @@ -1320,6 +1323,17 @@ def transform(result)
expect(subclass.default_serializers).to be_an(Array)
expect(subclass.default_serializers).to_not be_empty
end

context "when subclass of a subclass" do
let(:subsubclass) do
stub_class :SomeSubsubclass, subclass
end

it "returns some serializers" do
expect(subsubclass.default_serializers).to be_an(Array)
expect(subsubclass.default_serializers).to_not be_empty
end
end
end
end
end
9 changes: 7 additions & 2 deletions src/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ class << self
def default_serializers
return @default_serializers if @default_serializers

if superclass.respond_to?(:default_serializers)
serializers = superclass.default_serializers
superklass = superclass
serializers = nil

while superklass.respond_to?(:default_serializers)
serializers = superclass.instance_variable_get(:@default_serializers)

return serializers if serializers

superklass = superklass.superclass
end

@default_serializers = [
Expand Down
2 changes: 1 addition & 1 deletion version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Foobara
module HttpCommandConnector
VERSION = "0.0.11".freeze
VERSION = "0.0.12".freeze

local_ruby_version = File.read("#{__dir__}/.ruby-version").chomp
local_ruby_version_minor = local_ruby_version[/\A(\d+\.\d+)\.\d+\z/, 1]
Expand Down

0 comments on commit b799e21

Please sign in to comment.