Skip to content

Commit

Permalink
Consistently use strings for Spec keys
Browse files Browse the repository at this point in the history
As it turns out we'd inconsistently used symbols (in #parse) and
strings (largely from iknow_view_models) interchangeably, which was not only
ugly but also prevented correct `merge!`ing. The string convention is used in
many more places, so settle on that.
  • Loading branch information
chrisandreae committed Apr 6, 2023
1 parent a072f85 commit a70e71e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/deep_preloader/polymorphic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.parse(data)
end

def initialize(specs_by_type = {})
@specs_by_type = specs_by_type
@specs_by_type = specs_by_type.transform_keys(&:to_s)
end

def polymorphic?
Expand Down
6 changes: 3 additions & 3 deletions lib/deep_preloader/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def self.parse(data)
end
when Hash
assoc_specs = data.each_with_object({}) do |(k, v), h|
h[k.to_sym] = parse(v)
h[k.to_s] = parse(v)
end
self.new(assoc_specs)
when String, Symbol
self.new({ data.to_sym => nil })
self.new({ data.to_s => nil })
when DeepPreloader::AbstractSpec
data
when nil
Expand All @@ -26,7 +26,7 @@ def self.parse(data)
end

def initialize(association_specs = {})
@association_specs = association_specs
@association_specs = association_specs.transform_keys(&:to_s)
end

def merge!(other)
Expand Down
2 changes: 1 addition & 1 deletion lib/deep_preloader/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class DeepPreloader
VERSION = '1.0.2'
VERSION = '1.1.0'
end
6 changes: 3 additions & 3 deletions spec/unit/deep_preloader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

it 'can parse a hash spec' do
spec = { a: [:b, { c: :d, e: nil }] }
expected_spec = DeepPreloader::Spec.new(a: DeepPreloader::Spec.new(b: nil, c: DeepPreloader::Spec.new(d: nil), e: nil))
expected_spec = DeepPreloader::Spec.new('a' => DeepPreloader::Spec.new('b' => nil, 'c' => DeepPreloader::Spec.new('d' => nil), 'e' => nil))

expect(DeepPreloader::Spec.parse(spec)).to eq(expected_spec)
end
Expand All @@ -38,8 +38,8 @@
with_temporary_table(:model)

it 'can parse a polymorphic hash spec' do
parsed_spec = DeepPreloader::Spec.parse(a: DeepPreloader::PolymorphicSpec.parse('Model' => { b: :c }))
expected_spec = DeepPreloader::Spec.new(a: DeepPreloader::PolymorphicSpec.new('Model' => DeepPreloader::Spec.new(b: DeepPreloader::Spec.new(c: nil))))
parsed_spec = DeepPreloader::Spec.parse(a: DeepPreloader::PolymorphicSpec.parse('Model': { b: :c }))
expected_spec = DeepPreloader::Spec.new('a' => DeepPreloader::PolymorphicSpec.new('Model' => DeepPreloader::Spec.new('b' => DeepPreloader::Spec.new('c' => nil))))

expect(parsed_spec).to eq(expected_spec)
end
Expand Down

0 comments on commit a70e71e

Please sign in to comment.