Sha256: 45255bad81a0984a67b288d26d7e5e4725217616324813cf89d4f1355e1aab72

Contents?: true

Size: 1.52 KB

Versions: 16

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'

describe HelloSign::Resource::BaseResource do
  let(:data){
    { :body => {
        :a => :a1,
        :b => :b1,
        :c => { :c1 => :c2 },
        :d => [:d1, :d2, :d3],
        :e => [{ :e1 => :e11 }, { :e2 => :e21 }, { :e3 => :e31 }]
      }
    }
  }

  describe 'methods' do
    subject(:resource) { HelloSign::Resource::BaseResource.new data }

    it 'can access attributes by calling method with the same name' do
      data.keys.each do |key|
        expect(resource.send key).not_to be_nil
      end
    end

    it 'make a hash value into a new HelloSign::Resource::BaseResource' do
      expect(resource.data["body"].data["c"]).to be_an HelloSign::Resource::BaseResource
    end

    it 'do not touch array value with basic type' do
      expect(resource.d).to eql(data[:d])
    end

    it 'make a array value with each item is a hash into array of HelloSign::Resource::BaseResource' do
      expect(resource.data["body"].data["e"]).to be_an Array
      expect(resource.data["body"].data["e"][0]).to be_an HelloSign::Resource::BaseResource
    end
  end

  describe '#initialize' do
    context 'without key params' do
      subject(:resource) { HelloSign::Resource::BaseResource.new data }
      it 'have correct data' do
        expect(resource.raw_data).to eql(data)
      end
    end

    context 'with key params' do
      subject(:resource) { HelloSign::Resource::BaseResource.new data, :e }
      it 'have correct data' do
        expect(resource.raw_data).to eql(data[:body][:e])
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
hellosign-api-1.0.7 spec/hello_sign/resource/base_resource_spec.rb
hellosign-api-1.0.6 spec/hello_sign/resource/base_resource_spec.rb
hellosign-api-1.0.5 spec/hello_sign/resource/base_resource_spec.rb
hellosign-api-1.0.4 spec/hello_sign/resource/base_resource_spec.rb
hellosign-api-1.0.3 spec/hello_sign/resource/base_resource_spec.rb
hellosign-api-1.0.2 spec/hello_sign/resource/base_resource_spec.rb
hellosign-api-1.0.1 spec/hello_sign/resource/base_resource_spec.rb
hellosign-api-1.0.0 spec/hello_sign/resource/base_resource_spec.rb
hellosign-ruby-sdk-3.7.7 spec/hello_sign/resource/base_resource_spec.rb
hellosign-ruby-sdk-3.7.6 spec/hello_sign/resource/base_resource_spec.rb
hellosign-ruby-sdk-3.7.5 spec/hello_sign/resource/base_resource_spec.rb
hellosign-ruby-sdk-3.7.4 spec/hello_sign/resource/base_resource_spec.rb
hellosign-ruby-sdk-3.7.3 spec/hello_sign/resource/base_resource_spec.rb
hellosign-ruby-sdk-3.7.2 spec/hello_sign/resource/base_resource_spec.rb
hellosign-ruby-sdk-3.7.1 spec/hello_sign/resource/base_resource_spec.rb
hellosign-ruby-sdk-3.7.0 spec/hello_sign/resource/base_resource_spec.rb