Sha256: 984134c8dd158f76d27dc45b110215a5454bb6a240bc3d305d71834b2971349c

Contents?: true

Size: 1.76 KB

Versions: 3

Compression:

Stored size: 1.76 KB

Contents

require "spec_helper"

describe ShippingEasy::Resources::Base do

  class GenericResource < ShippingEasy::Resources::Base; end

  describe ".command" do
    before { GenericResource.command(:create, method: :post) }

    it "defines a method on the class" do
      GenericResource.should respond_to(:create)
    end

    it "extracts options to send to a request" do
      GenericResource.command(:find_all, http_method: :get) do |args|
        "/orders"
      end
      GenericResource.should_receive(:execute_request!).with({:relative_path=>"/orders",
                                                              :http_method=>:get,
                                                              :params => {:page => 2,
                                                                          :per_page => 3,
                                                                          :status => [:shipped]}})

      GenericResource.find_all(:page => 2, :per_page => 3, :status => [:shipped] )
    end

    context "when a block is provided" do
      it "uses it as the value for the path" do
        GenericResource.command(:create, http_method: :post) do |args|
          "/this/is/the/path"
        end
        GenericResource.should_receive(:execute_request!).with({:relative_path=>"/this/is/the/path", :http_method=>:post})
        GenericResource.create
      end

      context "and an argument is passed in" do
        it "interpolates it" do
          GenericResource.command(:create, http_method: :post) do |args|
            "/this/is/the/#{args.delete(:name)}"
          end
          GenericResource.should_receive(:execute_request!).with({:relative_path=>"/this/is/the/ABC123", :http_method=>:post})
          GenericResource.create(name: "ABC123")
        end
      end
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shipping_easy-0.3.2 spec/resources/base_spec.rb
shipping_easy-0.3.1 spec/resources/base_spec.rb
shipping_easy-0.3.0 spec/resources/base_spec.rb