Merge pull request #367 from joker1007/fix-hash-assignment
Fix Hash value assignment in JsonSupport#getter_fn
This commit is contained in:
commit
7d00754d7f
|
@ -38,8 +38,8 @@ module Google
|
||||||
def getter_fn(name)
|
def getter_fn(name)
|
||||||
ivar_name = "@#{name}".to_sym
|
ivar_name = "@#{name}".to_sym
|
||||||
lambda do |_|
|
lambda do |_|
|
||||||
if respond_to?(:[])
|
if respond_to?(:fetch)
|
||||||
self[name] || instance_variable_get(ivar_name)
|
fetch(name, instance_variable_get(ivar_name))
|
||||||
else
|
else
|
||||||
instance_variable_get(ivar_name)
|
instance_variable_get(ivar_name)
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,7 +28,8 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do
|
||||||
attr_accessor :nil_value
|
attr_accessor :nil_value
|
||||||
attr_accessor :numeric_value
|
attr_accessor :numeric_value
|
||||||
attr_accessor :string_value
|
attr_accessor :string_value
|
||||||
attr_accessor :boolean_value
|
attr_accessor :boolean_value_true
|
||||||
|
attr_accessor :boolean_value_false
|
||||||
attr_accessor :date_value
|
attr_accessor :date_value
|
||||||
attr_accessor :bytes_value
|
attr_accessor :bytes_value
|
||||||
attr_accessor :items
|
attr_accessor :items
|
||||||
|
@ -44,7 +45,8 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do
|
||||||
property :nil_value, as: 'nilValue'
|
property :nil_value, as: 'nilValue'
|
||||||
property :numeric_value, as: 'numericValue'
|
property :numeric_value, as: 'numericValue'
|
||||||
property :string_value, as: 'stringValue'
|
property :string_value, as: 'stringValue'
|
||||||
property :boolean_value, as: 'booleanValue'
|
property :boolean_value_true, as: 'booleanValueTrue'
|
||||||
|
property :boolean_value_false, as: 'booleanValueFalse'
|
||||||
property :date_value, as: 'dateValue', type: DateTime
|
property :date_value, as: 'dateValue', type: DateTime
|
||||||
property :bytes_value, as: 'bytesValue', base64: true
|
property :bytes_value, as: 'bytesValue', base64: true
|
||||||
property :items
|
property :items
|
||||||
|
@ -75,7 +77,8 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'serializes boolean values' do
|
it 'serializes boolean values' do
|
||||||
expect(json).to be_json_eql(%(true)).at_path('booleanValue')
|
expect(json).to be_json_eql(%(true)).at_path('booleanValueTrue')
|
||||||
|
expect(json).to be_json_eql(%(false)).at_path('booleanValueFalse')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'serializes date values' do
|
it 'serializes date values' do
|
||||||
|
@ -107,7 +110,8 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do
|
||||||
model.numeric_value = 123
|
model.numeric_value = 123
|
||||||
model.string_value = 'test'
|
model.string_value = 'test'
|
||||||
model.date_value = DateTime.new(2015, 5, 1, 12)
|
model.date_value = DateTime.new(2015, 5, 1, 12)
|
||||||
model.boolean_value = true
|
model.boolean_value_true = true
|
||||||
|
model.boolean_value_false = false
|
||||||
model.bytes_value = 'Hello world'
|
model.bytes_value = 'Hello world'
|
||||||
model.items = [1, 2, 3]
|
model.items = [1, 2, 3]
|
||||||
model.child = child_class.new
|
model.child = child_class.new
|
||||||
|
@ -127,7 +131,8 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do
|
||||||
string_value: 'test',
|
string_value: 'test',
|
||||||
numeric_value: 123,
|
numeric_value: 123,
|
||||||
date_value: DateTime.new(2015, 5, 1, 12),
|
date_value: DateTime.new(2015, 5, 1, 12),
|
||||||
boolean_value: true,
|
boolean_value_true: true,
|
||||||
|
boolean_value_false: false,
|
||||||
bytes_value: 'Hello world',
|
bytes_value: 'Hello world',
|
||||||
items: [1, 2, 3],
|
items: [1, 2, 3],
|
||||||
child: {
|
child: {
|
||||||
|
@ -146,7 +151,8 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do
|
||||||
json = <<EOF
|
json = <<EOF
|
||||||
{ "stringValue": "test",
|
{ "stringValue": "test",
|
||||||
"nilValue": null,
|
"nilValue": null,
|
||||||
"booleanValue": true,
|
"booleanValueTrue": true,
|
||||||
|
"booleanValueFalse": false,
|
||||||
"numericValue": 123,
|
"numericValue": 123,
|
||||||
"dateValue": "2015-05-01T12:00:00+00:00",
|
"dateValue": "2015-05-01T12:00:00+00:00",
|
||||||
"bytesValue": "SGVsbG8gd29ybGQ=",
|
"bytesValue": "SGVsbG8gd29ybGQ=",
|
||||||
|
@ -170,7 +176,8 @@ EOF
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'deserializes boolean values' do
|
it 'deserializes boolean values' do
|
||||||
expect(model.boolean_value).to be_truthy
|
expect(model.boolean_value_true).to be_truthy
|
||||||
|
expect(model.boolean_value_false).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'deserializes date values' do
|
it 'deserializes date values' do
|
||||||
|
|
Loading…
Reference in New Issue