Sha256: 88606beae98060f1dc51fa991b3f538f1fd6f65d6e5a0486e44598743d4d11a4

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

require 'spec_helper'

describe InsalesApi::ActiveResourceProxy do
  let(:proxy) { described_class.new(configurer, object) }
  let(:configurer) { Object.new.tap { |x| x.stub(:init_api).and_yield } }

  describe '#method_missing' do
    let(:object) { {} }
    let(:method_name) { :some_method }
    subject { proxy.send(method_name) }

    it 'should proxy method to object & pass result through #proxy_for' do
      result1 = {test: :resut1}
      result2 = {test: :resut2}
      object.should_receive(method_name).and_return(result1)
      proxy.should_receive(:proxy_for).with(result1).and_return(result2)
      subject.should eq(result2)
    end
  end

  describe '::need_proxy?' do
    subject { described_class.need_proxy?(object) }

    context 'for scalar' do
      let(:object) { true }
      it { should be false }
    end

    context 'for InsalesApi::Base class' do
      let(:object) { InsalesApi::Account }
      it { should be true }
    end

    context 'for InsalesApi::Base object' do
      let(:object) { InsalesApi::Account.new }
      it { should be true }
    end

    context 'for ActiveResource::Collection object' do
      let(:object) { ActiveResource::Collection.new }
      it { should be true }
    end

    context 'for ActiveResource::Base object' do
      let(:object) { ActiveResource::Base.new }
      it { should be false }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
insales_api-0.1.3 spec/lib/insales_api/active_resource_proxy_spec.rb
insales_api-0.1.2 spec/lib/insales_api/active_resource_proxy_spec.rb
insales_api-0.1.1 spec/lib/insales_api/active_resource_proxy_spec.rb