Sha256: de4d80c57d1fd07a7bdcbf07b76527b81f06d98f7dce85cf1d50abcfca9a52b2

Contents?: true

Size: 1.94 KB

Versions: 6

Compression:

Stored size: 1.94 KB

Contents

# -*- encoding: utf-8 -*-
require 'spec_helper'

module Stomper::Scopes
  describe HeaderScope do
    before(:each) do
      @connection = mock("connection", :is_a? => true, :version => '1.1')
      @headers = { :global_1 => 'turbo', 'global_2' => 'is me', :persistent => true }
      @connection.stub!(:subscription_manager).and_return(mock('subscription manager', {
        :remove => ['no-real-destination']
      }))
      @scope = HeaderScope.new(@connection, @headers)
    end
    
    it "should apply the headers to any frame generated on its Common interface" do
      @connection.should_receive(:transmit).with(stomper_frame_with_headers(@headers, 'SEND'))
      @connection.should_receive(:transmit).with(stomper_frame_with_headers(@headers, 'BEGIN'))
      @connection.should_receive(:transmit).with(stomper_frame_with_headers(@headers, 'UNSUBSCRIBE'))
      @scope.send("/queue/test", "body of message", { :local_1 => 'my header' })
      @scope.begin("transaction-1234", { :local_2 => 'other header'})
      @scope.unsubscribe('no-real-destination')
    end
    
    it "should evaluate a proc through itself if one is provided" do
      scope_block = lambda do |h|
        h.abort('transaction-1234')
        h.subscribe('/queue/test')
        h.commit('transaction-1234')
      end
      @connection.should_receive(:transmit).with(stomper_frame_with_headers(@headers, 'ABORT'))
      @connection.should_receive(:transmit).with(stomper_frame_with_headers(@headers, 'SUBSCRIBE'))
      @connection.should_receive(:transmit).with(stomper_frame_with_headers(@headers, 'COMMIT'))
      @scope.apply_to(scope_block)
    end
    
    it "should override its headers with those passed through the frame methods" do
      overridden_headers = @headers.merge(:persistent => 'false')
      @connection.should_receive(:transmit).with(stomper_frame_with_headers(overridden_headers, 'SEND'))
      @scope.send('/queue/test', 'body of message', { :persistent => false })
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
stomper-2.0.6 spec/stomper/scopes/header_scope_spec.rb
stomper-2.0.5 spec/stomper/scopes/header_scope_spec.rb
stomper-2.0.4 spec/stomper/scopes/header_scope_spec.rb
stomper-2.0.3 spec/stomper/scopes/header_scope_spec.rb
stomper-2.0.2 spec/stomper/scopes/header_scope_spec.rb
stomper-2.0.1 spec/stomper/scopes/header_scope_spec.rb