Sha256: 5e6bb7b536d9d10be0941c3248bd9757d22997ef8b86f3b6c46c388cd18b3c9b

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

require 'spec_helper'
class Foo
  include TMS::InstanceResource
  writeable_attributes :bar
  collection_attribute :blah, 'EmailMessage'
  readonly_collection_attribute :shah, 'EmailMessage'
end

describe TMS::InstanceResource do
  context "creating a new inbound messages list" do
    let(:happy_response) do
      double(:status => 201,  :body => {})
    end

    let(:client) do
      double('client', :post => happy_response, :get => happy_response)
    end


    before do
      @instance_resource = Foo.new(client)
    end

    it 'should POST' do
      @instance_resource.bar = "OMG"
      @instance_resource.post.should be_truthy
    end

    it 'should correctly reflect on collection resources' do
      @instance_resource.blah.class.should == TMS::EmailMessage
      @instance_resource.shah.class.should == TMS::EmailMessage
    end

    it 'should not GET on initialization' do
      client.should_not receive(:get)
      Foo.new(client, 'https://example.com/foos/1')
    end

    it 'should return self on successful get' do
      client.should receive(:get)
      foo = Foo.new(client, 'https://example.com/foos/1')
      foo.should_not be_new_record
      foo.get.should == foo
    end

    it 'it exposes its attributes hash' do
      @instance_resource.attributes.should == {}
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tms_client-0.5.3 spec/instance_resource_spec.rb
tms_client-0.5.2 spec/instance_resource_spec.rb
tms_client-0.5.1 spec/instance_resource_spec.rb