Sha256: d930f7335f8ce8742e96f486fcedd01cb67e728e827eef565a7129bee343d491

Contents?: true

Size: 1.56 KB

Versions: 8

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

class LifecycleNotificationPlugin < Killbill::Plugin::PluginBase
  attr_accessor :lifecycled

  def start_plugin
    @lifecycled = true
    super
  end

  def stop_plugin
    @lifecycled = true
    super
  end
end

describe Killbill::Plugin::PluginBase do
  it 'should be able to register Killbill API instances' do
    plugin = Killbill::Plugin::PluginBase.new(:account_user_api => MockAccountUserApi.new)

    plugin.account_user_api.get_accounts(nil).size.should == 0
    # Existing API, present
    lambda { plugin.account_user_api.do_foo('with my bar') }.should_not raise_error Killbill::Plugin::PluginBase::APINotAvailableError
    # Existing API, absent
    lambda { plugin.payment_api.do_foo('with my bar') }.should raise_error Killbill::Plugin::PluginBase::APINotAvailableError
    # Non-existing API
    lambda { plugin.foobar_user_api.do_foo('with my bar') }.should raise_error Killbill::Plugin::PluginBase::APINotAvailableError
    # Default method missing behavior
    lambda { plugin.blablabla }.should raise_error NoMethodError
  end

  it 'should be able to add custom code in the startup/shutdown sequence' do
    plugin = LifecycleNotificationPlugin.new

    plugin.lifecycled = false
    plugin.lifecycled.should be_false
    plugin.active.should be_false

    plugin.start_plugin
    plugin.lifecycled.should be_true
    plugin.active.should be_true

    plugin.lifecycled = false
    plugin.lifecycled.should be_false
    plugin.active.should be_true

    plugin.stop_plugin
    plugin.lifecycled.should be_true
    plugin.active.should be_false
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
killbill-1.0.8 spec/killbill/base_plugin_spec.rb
killbill-1.0.7 spec/killbill/base_plugin_spec.rb
killbill-1.0.6 spec/killbill/base_plugin_spec.rb
killbill-1.0.5 spec/killbill/base_plugin_spec.rb
killbill-1.0.4 spec/killbill/base_plugin_spec.rb
killbill-1.0.3 spec/killbill/base_plugin_spec.rb
killbill-1.0.2 spec/killbill/base_plugin_spec.rb
killbill-1.0.1 spec/killbill/base_plugin_spec.rb