diff options
author | Michael Herold <opensource@michaeljherold.com> | 2018-08-11 15:53:58 -0500 |
---|---|---|
committer | Michael Herold <opensource@michaeljherold.com> | 2018-08-11 15:53:58 -0500 |
commit | 91a5153fa3dd908dea19d4162253e4e45e2d6605 (patch) | |
tree | 9ad9681b3c1090f8c251a651c146aba434515f0f /spec/hashie/trash_spec.rb | |
parent | b7209f6f580816bc2d030e1c52f2f2c688454bdc (diff) | |
download | hashie-91a5153fa3dd908dea19d4162253e4e45e2d6605.tar.gz |
Make Dash greedier when creating getters
Dash, in its current form, was created to be very conservative in
creating the getters for its properties. It only creates them when the
accompanying setter has not already been created. This means that the
property translation capability that is layered on top of Dash to create
a Trash cannot have dependence between properties in an
order-independent way.
This change makes it so Dash now greedily creates a getter method for
each property. To ensure that we don't do this more than once for
a given Dash class, we track the getters we have previously created.
This keeps the number of warnings from Ruby down to the same number of
warnings that were emitted prior to this change.
Given that Dash users expect the getter to be set, this doesn't feel
like it should cause any backwards-compatibility issues.
Diffstat (limited to 'spec/hashie/trash_spec.rb')
-rw-r--r-- | spec/hashie/trash_spec.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/spec/hashie/trash_spec.rb b/spec/hashie/trash_spec.rb index a5e5d02..043cbfd 100644 --- a/spec/hashie/trash_spec.rb +++ b/spec/hashie/trash_spec.rb @@ -312,5 +312,17 @@ describe Hashie::Trash do expect(subject.to_h[:value]).to eq(nil) expect(subject.copy_of_value).to eq(0) end + + it 'is not order-dependent in definition' do + simple = Class.new(Hashie::Trash) do + property :copy_of_id, from: :id + property :id + end + + subject = simple.new(id: 1) + + expect(subject.id).to eq(1) + expect(subject.copy_of_id).to eq(1) + end end end |