Sha256: 2df3fa20a6269d470d15f4d63f7484de36dd7ab51275e6e60c95adb8c9cdbf14

Contents?: true

Size: 1.72 KB

Versions: 17

Compression:

Stored size: 1.72 KB

Contents

if RUBY_PLATFORM != 'opal'
  class TestTask < Volt::Task
    def allowed_method(arg1, arg2)
      return 'yes' + arg1 + arg2
    end
  end

  describe Volt::Dispatcher do
    before do
      Volt.logger = spy('Volt::VoltLogger')
    end

    it 'should only allow method calls on Task or above in the inheritance chain' do
      channel = double('channel')

      expect(channel).to receive(:send_message).with('response', 0, 'yes it works', nil)

      Volt::Dispatcher.new.dispatch(channel, [0, 'TestTask', :allowed_method, {}, ' it', ' works'])
    end

    it 'should not allow eval' do
      channel = double('channel')

      expect(channel).to receive(:send_message).with('response', 0, nil, RuntimeError.new('unsafe method: eval'))

      Volt::Dispatcher.new.dispatch(channel, [0, 'TestTask', :eval, '5 + 10'])
    end

    it 'should not allow instance_eval' do
      channel = double('channel')

      expect(channel).to receive(:send_message).with('response', 0, nil, RuntimeError.new('unsafe method: instance_eval'))

      Volt::Dispatcher.new.dispatch(channel, [0, 'TestTask', :instance_eval, '5 + 10'])
    end

    it 'should not allow #methods' do
      channel = double('channel')

      expect(channel).to receive(:send_message).with('response', 0, nil, RuntimeError.new('unsafe method: methods'))

      Volt::Dispatcher.new.dispatch(channel, [0, 'TestTask', :methods])
    end

    it 'should log an info message before and after the dispatch' do
      channel = double('channel')

      allow(channel).to receive(:send_message).with('response', 0, 'yes it works', nil)
      expect(Volt.logger).to receive(:log_dispatch)

      Volt::Dispatcher.new.dispatch(channel, [0, 'TestTask', :allowed_method, {}, ' it', ' works'])
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
volt-0.9.1 spec/tasks/dispatcher_spec.rb
volt-0.9.1.pre5 spec/tasks/dispatcher_spec.rb
volt-0.9.1.pre4 spec/tasks/dispatcher_spec.rb
volt-0.9.1.pre3 spec/tasks/dispatcher_spec.rb
volt-0.9.1.pre2 spec/tasks/dispatcher_spec.rb
volt-0.9.1.pre1 spec/tasks/dispatcher_spec.rb
volt-0.9.0 spec/tasks/dispatcher_spec.rb
volt-0.9.0.pre7 spec/tasks/dispatcher_spec.rb
volt-0.9.0.pre6 spec/tasks/dispatcher_spec.rb
volt-0.9.0.pre5 spec/tasks/dispatcher_spec.rb
volt-0.9.0.pre4 spec/tasks/dispatcher_spec.rb
volt-0.9.0.pre3 spec/tasks/dispatcher_spec.rb
volt-0.9.0.pre2 spec/tasks/dispatcher_spec.rb
volt-0.9.0.pre1 spec/tasks/dispatcher_spec.rb
volt-0.8.27.beta9 spec/tasks/dispatcher_spec.rb
volt-0.8.27.beta8 spec/tasks/dispatcher_spec.rb
volt-0.8.27.beta7 spec/tasks/dispatcher_spec.rb