Sha256: ad79e99e9dcfeb858e76ce2e698a26826cf7a337380a6501323fb6d0f8421b7f

Contents?: true

Size: 1.96 KB

Versions: 11

Compression:

Stored size: 1.96 KB

Contents

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

describe GovDelivery::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'
      expect(@instance_resource.post).to be_truthy
    end

    it 'should correctly reflect on collection resources' do
      expect(@instance_resource.blah.class).to eq(GovDelivery::TMS::EmailMessage)
      expect(@instance_resource.shah.class).to eq(GovDelivery::TMS::EmailMessage)
    end

    it 'should ignore nils in to_json' do
      @instance_resource.bar = nil
      expect(@instance_resource.to_json).to eq({blah: {recipients: [], opened: [], clicked: [], sent: [], failed: []}})
    end

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

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

    %w(get post put delete).each do |verb|
      it "should blow up on invalid #{verb}!" do
        expect(client).to(receive(verb)).and_return(double('response', status: 404, body: '{}'))
        foo = Foo.new(client, 'https://example.com/foos/1')
        expect do
          foo.send("#{verb}!")
        end.to raise_error("GovDelivery::TMS::Errors::Invalid#{verb.capitalize}".constantize)
      end
    end

    it 'it exposes its attributes hash' do
      expect(@instance_resource.attributes).to eq({})
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
govdelivery-tms-0.9.3 spec/instance_resource_spec.rb
govdelivery-tms-0.9.2 spec/instance_resource_spec.rb
govdelivery-tms-0.9.0 spec/instance_resource_spec.rb
govdelivery-tms-0.8.14 spec/instance_resource_spec.rb
govdelivery-tms-0.8.13 spec/instance_resource_spec.rb
govdelivery-tms-0.8.12 spec/instance_resource_spec.rb
govdelivery-tms-0.8.11 spec/instance_resource_spec.rb
govdelivery-tms-0.8.10 spec/instance_resource_spec.rb
govdelivery-tms-0.8.9 spec/instance_resource_spec.rb
govdelivery-tms-0.8.8 spec/instance_resource_spec.rb
govdelivery-tms-0.8.7 spec/instance_resource_spec.rb