-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix Settable: allow setting a nested value to a non-string (for 6.4 stable) #4510
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -315,6 +315,25 @@ | |
end | ||
end | ||
|
||
context 'when a leaf value in the nested hash is updated to a number' do | ||
|
||
let(:church) do | ||
Church.new.tap do |a| | ||
a.location = {'address' => {'city' => 'Berlin', 'street' => 'Yorckstr'}} | ||
a.name = 'Church1' | ||
a.save | ||
end | ||
end | ||
|
||
before do | ||
church.set('location.address.city' => 12345) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm understanding correctly, this is where the exception would have occurred before the change? If so, let's put this inside a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can do, but this way it's more consistent with all the examples around it. I think an exception raised anywhere in the spec is fine for failing a test; it doesn't necessarily need to be raised in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough; I don't feel strongly enough to block merging on this, so it's fine to leave as-is. |
||
end | ||
|
||
it 'updates the nested value to the correct value' do | ||
expect(church.name).to eq('Church1') | ||
expect(church.location).to eql({'address' => {'city' => 12345, 'street' => 'Yorckstr'}}) | ||
end | ||
end | ||
|
||
context 'when the nested hash is many levels deep' do | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think
respond_to?(:empty?)
would make more sense here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think we specifically want to check for a
Hash
... for example we don't want to enter this block for aString
, even thoughString
implementsempty?
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK that makes sense. Is this behavior documented somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. The behavior in this PR seems to make sense: only merge an existing Hash with a new value if that value is a non-empty Hash. The PR that introduced the regression intended to support setting field values to an empty Hash, which remains supported.