Sha256: cef891e281b038be6e2cd70c15f6ce5e3618b942e495fc000a4e53cd6a3d1201

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

require "spec_helper"
require "savon/model"

describe Savon::Model do
  let :model do
    Class.new { include Savon::Model }
  end

  describe ".client" do
    it "should should pass a given block to a new Savon::Client"

    it "should memoize the Savon::Client" do
      model.client.should equal(model.client)
    end

    it "should memoize the Savon::Client when inherited" do
      supermodel = Class.new model
      supermodel.client.should equal(model.client)
    end
  end

  describe ".endpoint" do
    it "should set the SOAP endpoint" do
      model.endpoint "http://example.com"
      model.client.wsdl.endpoint.should == "http://example.com"
    end
  end

  describe ".namespace" do
    it "should set the target namespace" do
      model.namespace "http://v1.example.com"
      model.client.wsdl.namespace.should == "http://v1.example.com"
    end
  end

  describe ".actions" do
    before(:all) { model.actions :get_user, :get_all_users }

    it "should define class methods each action" do
      model.should respond_to(:get_user, :get_all_users)
    end

    it "should define instance methods each action" do
      model.new.should respond_to(:get_user, :get_all_users)
    end

    context "(class-level)" do
      it "should execute SOAP requests with a given body" do
        model.client.expects(:request).with(:wsdl, :get_user, :body => { :id => 1 })
        model.get_user :id => 1
      end
    end

    context "(instance-level)" do
      it "should delegate to the corresponding class method" do
        model.expects(:get_all_users).with(:active => true)
        model.new.get_all_users :active => true
      end
    end
  end

  describe "#client" do
    it "should return the class-level Savon::Client" do
      model.new.client.should == model.client
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
savon_model-0.1.2 spec/savon/model_spec.rb