Sha256: d493cd6a039ff7324015acf3eb32933d038d9fb112420dbcfec5d5bbfa5c20d1

Contents?: true

Size: 1.75 KB

Versions: 18

Compression:

Stored size: 1.75 KB

Contents

require File.expand_path('../../../helper', __FILE__)

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

18 entries across 18 versions & 2 rubygems

Version Path
innate-2023.01.06 spec/innate/node/wrap_action_call.rb
innate-2015.10.28 spec/innate/node/wrap_action_call.rb
manveru-innate-2009.07 spec/innate/node/wrap_action_call.rb
innate-2013.02.21 spec/innate/node/wrap_action_call.rb
innate-2013.02 spec/innate/node/wrap_action_call.rb
innate-2012.12 spec/innate/node/wrap_action_call.rb
innate-2012.03 spec/innate/node/wrap_action_call.rb
innate-2011.12 spec/innate/node/wrap_action_call.rb
innate-2011.10 spec/innate/node/wrap_action_call.rb
innate-2011.04 spec/innate/node/wrap_action_call.rb
innate-2011.01 spec/innate/node/wrap_action_call.rb
innate-2010.07 spec/innate/node/wrap_action_call.rb
innate-2010.06.18 spec/innate/node/wrap_action_call.rb
innate-2010.04 spec/innate/node/wrap_action_call.rb
innate-2010.03 spec/innate/node/wrap_action_call.rb
innate-2010.01 spec/innate/node/wrap_action_call.rb
innate-2009.10 spec/innate/node/wrap_action_call.rb
innate-2009.07 spec/innate/node/wrap_action_call.rb