Sha256: d4eed463d88c00ecb76dd92cf6cee9fcd3d40e9d82fea54ddd11d36bbb066dbc

Contents?: true

Size: 1.72 KB

Versions: 7

Compression:

Stored size: 1.72 KB

Contents

require 'spec/helper'

SPEC_WRAP_LOG = []

class SpecWrapActionCall
  Innate.node '/'

  def first; end
  def second; end
  def third; end

  private

  def wrap_before(action)
    SPEC_WRAP_LOG << [:before, action.name]
    yield
  end

  def wrap_after(action)
    SPEC_WRAP_LOG << [:after, action.name]
    yield
  end
end

class SpecWrapActionCallStop
  Innate.node '/stop'

  def index; 'Hello'; end

  def wrap_pass(action)
    yield
  end

  def wrap_stop(action)
    'No Hello'
  end
end


describe 'Node#wrap_action_call' do
  behaves_like :rack_test

  it 'executes our wrapper' do
    SPEC_WRAP_LOG.clear
    SpecWrapActionCall.add_action_wrapper(2.0, :wrap_after)

    get('/first')
    SPEC_WRAP_LOG.should == [[:after, 'first']]

    get('/second')
    SPEC_WRAP_LOG.should == [[:after, 'first'], [:after, 'second']]

    get('/third')
    SPEC_WRAP_LOG.should == [[:after, 'first'], [:after, 'second'], [:after, 'third']]
  end

  it 'executes wrappers in correct order' do
    SPEC_WRAP_LOG.clear
    SpecWrapActionCall.add_action_wrapper(1.0, :wrap_before)

    get('/first')
    SPEC_WRAP_LOG.should == [[:before, 'first'], [:after, 'first']]

    get('/second')
    SPEC_WRAP_LOG.should == [
      [:before, 'first'], [:after, 'first'],
      [:before, 'second'], [:after, 'second']]

    get('/third')
    SPEC_WRAP_LOG.should == [
      [:before, 'first'], [:after, 'first'],
      [:before, 'second'], [:after, 'second'],
      [:before, 'third'], [:after, 'third']]
  end

  it 'stops in the chain when not yielded' do
    SpecWrapActionCallStop.add_action_wrapper(1.0, :wrap_pass)
    get('/stop').body.should == 'Hello'

    SpecWrapActionCallStop.add_action_wrapper(2.0, :wrap_stop)
    get('/stop').body.should == 'No Hello'
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
manveru-innate-2009.06.12 spec/innate/node/wrap_action_call.rb
manveru-innate-2009.06 spec/innate/node/wrap_action_call.rb
rjspotter-innate-2009.06.29 spec/innate/node/wrap_action_call.rb
rjspotter-innate-2009.06.30 spec/innate/node/wrap_action_call.rb
rjspotter-innate-2009.06.31 spec/innate/node/wrap_action_call.rb
innate-2009.06 spec/innate/node/wrap_action_call.rb
innate-2009.06.12 spec/innate/node/wrap_action_call.rb