Sha256: 1c839e9f56f1d7ff1077062ffbd621b9dc0ff3e673570778e75add204c8e4177

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

#encoding:utf-8

require 'spec_helper'

describe WashOut::Dispatcher do

  class Dispatcher < ApplicationController
    include WashOut::SOAP

    def self.mock(text="")
      dispatcher = self.new
      dispatcher.request = OpenStruct.new(:body => OpenStruct.new(:read => text))
      dispatcher
    end

    def params
      @_params
    end
  end

  it "finds nested hashes" do
    WashOut::Dispatcher.deep_select(:foo => 1){|k,v| k == :foo}.should == [1]
    WashOut::Dispatcher.deep_select({:foo => {:foo => 1}}){|k,v| k == :foo}.should == [{:foo => 1}, 1]
  end

  it "replaces nested hashed" do
    WashOut::Dispatcher.deep_replace_href({:foo => {:@href => 1}}, {1 => 2}).should == {:foo => 2}
    WashOut::Dispatcher.deep_replace_href({:bar => {:foo => {:@href => 1}}}, {1 => 2}).should == {:bar => {:foo => 2}}
  end

  it "parses typical request" do
    dispatcher = Dispatcher.mock("<foo>1</foo>")
    dispatcher._parse_soap_parameters
    dispatcher.params.should == {:foo => "1"}
  end

  it "parses href request" do
    dispatcher = Dispatcher.mock <<-XML
      <root>
        <request>
          <entities href="#id1">
          </entities>
        </request>
        <entity id="id1">
          <foo><bar>1</bar></foo>
          <sub href="#id2" />
        </entity>
        <ololo id="id2">
          <foo>1</foo>
        </ololo>
      </root>
    XML
    dispatcher._parse_soap_parameters
    dispatcher.params[:root][:request][:entities].should == {
      :foo => {:bar=>"1"},
      :sub => {:foo=>"1", :@id=>"id2"},
      :@id => "id1"
    }
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wash_out-0.6.1 spec/lib/wash_out/dispatcher_spec.rb
wash_out-0.6.0 spec/lib/wash_out/dispatcher_spec.rb