Sha256: 5398569e56f7f41556a30fd5aa414e20f2032784f01c1fa664ffcd71829c068d

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

require 'spec_helper'

describe ZendeskAPI::ReadResource do
  context "find" do
    let(:id) { 1 }
    subject { ZendeskAPI::TestResource }

    context "normal request" do
      before(:each) do
        stub_json_request(:get, %r{test_resources/#{id}}, json("test_resource" => {}))
      end

      it "should return instance of resource" do
        subject.find(client, :id => id).should be_instance_of(subject)
      end
    end

    it "should blow up without an id which would build an invalid url" do
      expect{
        ZendeskAPI::User.find(client, :foo => :bar)
      }.to raise_error("No :id given")
    end

    context "with side loads" do
      before(:each) do
        stub_json_request(:get, %r{test_resources/#{id}\?include=nil_resource}, json(
          "test_resource" => { :id => 1, :nil_resource_id => 2 },
          "nil_resources" => [{ :id => 1, :name => :bye }, { :id => 2, :name => :hi }]
        ))

        subject.has :nil_resource
        @resource = subject.find(client, :id => id, :include => :nil_resource)
      end

      it "should side load nil resource" do
        @resource.nil_resource.name.should == "hi"
      end
    end

    context "with client error" do
      it "should handle 500 properly" do
        stub_request(:get, %r{test_resources/#{id}}).to_return(:status => 500)
        client.config.logger.should_receive(:warn).at_least(:once)
        subject.find(client, :id => id).should == nil
      end

      it "should handle 404 properly" do
        stub_request(:get, %r{test_resources/#{id}}).to_return(:status => 404)
        client.config.logger.should_receive(:warn).at_least(:once)
        subject.find(client, :id => id).should == nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zendesk_api-0.1.7 spec/read_resource_spec.rb
zendesk_api-0.1.6 spec/read_resource_spec.rb