Sha256: d4f16af71d74feaba2b2b9d3db25e642d02267965763a0a877ecc45f11d0bcf7

Contents?: true

Size: 1.47 KB

Versions: 11

Compression:

Stored size: 1.47 KB

Contents

# Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'spec_helper'
require 'google/apis/core/hashable'

RSpec.describe Google::Apis::Core::Hashable do
  let(:child_class) do
    Class.new do
      include Google::Apis::Core::Hashable
      attr_accessor :value
    end
  end

  let(:model_class) do
    Class.new do
      include Google::Apis::Core::Hashable
      attr_accessor :value
      attr_accessor :value2
      attr_accessor :children
    end
  end

  let(:model) do
    obj = model_class.new
    obj.value = 'hello'
    obj.value2 = {
      a: 'a'
    }
    child = child_class.new
    child.value = 'goodbye'
    obj.children = [child]
    obj
  end

  let(:hash) { model.to_h }

  it 'should serialize attributes' do
    expect(hash).to include(value: 'hello')
  end

  it 'should serialize collections' do
    expect(hash).to include(children: [{ value: 'goodbye' }])
  end

  it 'should serialize hashes' do
    expect(hash[:value2]).to include(a: 'a')
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
google-api-client-0.9.5 spec/google/apis/core/hashable_spec.rb
google-api-client-0.9.4 spec/google/apis/core/hashable_spec.rb
google-api-client-0.9.3 spec/google/apis/core/hashable_spec.rb
google-api-client-0.9.2 spec/google/apis/core/hashable_spec.rb
google-api-client-0.9.1 spec/google/apis/core/hashable_spec.rb
google-api-client-0.9 spec/google/apis/core/hashable_spec.rb
google-api-client-0.9.pre5 spec/google/apis/core/hashable_spec.rb
google-api-client-0.9.pre4 spec/google/apis/core/hashable_spec.rb
google-api-client-0.9.pre3 spec/google/apis/core/hashable_spec.rb
google-api-client-0.9.pre2 spec/google/apis/core/hashable_spec.rb
google-api-client-0.9.pre1 spec/google/apis/core/hashable_spec.rb