Sha256: 4c8dffaae5e088e585637d628ba0ec8c1a49f9ec6658cc55d2059362ddd0ea68

Contents?: true

Size: 1.55 KB

Versions: 65

Compression:

Stored size: 1.55 KB

Contents

require 'spec_helper'
require 'active_admin/event'

describe ActiveAdmin::EventDispatcher do

  let(:test_event){ 'active_admin.test_event' }
  let(:dispatcher){ ActiveAdmin::EventDispatcher.new }

  it "should add a subscriber for an event" do
    dispatcher.subscribers(test_event).size.should == 0
    dispatcher.subscribe(test_event){ true }
    dispatcher.subscribers(test_event).size.should == 1
  end

  it "should add a subscriber for multiple events" do
    dispatcher.subscribe(test_event, test_event + "1"){ true }
    dispatcher.subscribers(test_event).size.should == 1
    dispatcher.subscribers(test_event + "1").size.should == 1
  end

  it "should call the dispatch block with no arguments" do
    dispatcher.subscribe(test_event){ raise StandardError, "From Event Handler" }
    lambda {
      dispatcher.dispatch(test_event)
    }.should raise_error(StandardError, "From Event Handler")
  end

  it "should call the dispatch block with one argument" do
    arg = nil
    dispatcher.subscribe(test_event){|passed_in| arg = passed_in }
    dispatcher.dispatch(test_event, "My Arg")
    arg.should == "My Arg"
  end

  it "should clear all subscribers" do
    dispatcher.subscribe(test_event){ false }
    dispatcher.subscribe(test_event + "_2"){ false }
    dispatcher.clear_all_subscribers!
    dispatcher.subscribers(test_event).size.should == 0
    dispatcher.subscribers(test_event + "_2").size.should == 0
  end

  it "should have a dispatcher available from ActiveAdmin::Event" do
    ActiveAdmin::Event.should be_an_instance_of(ActiveAdmin::EventDispatcher)
  end

end

Version data entries

65 entries across 65 versions & 3 rubygems

Version Path
activeadmin-0.6.0 spec/unit/event_spec.rb
lalala-4.0.0.dev.64 vendor/deps/active_admin/spec/unit/event_spec.rb
lalala-4.0.0.dev.63 vendor/deps/active_admin/spec/unit/event_spec.rb
lalala-4.0.0.dev.62 vendor/deps/active_admin/spec/unit/event_spec.rb
lalala-4.0.0.dev.61 vendor/deps/active_admin/spec/unit/event_spec.rb
lalala-4.0.0.dev.60 vendor/deps/active_admin/spec/unit/event_spec.rb
lalala-4.0.0.dev.59 vendor/deps/active_admin/spec/unit/event_spec.rb
lalala-4.0.0.dev.58 vendor/deps/active_admin/spec/unit/event_spec.rb
lalala-4.0.0.dev.57 vendor/deps/active_admin/spec/unit/event_spec.rb
lalala-4.0.0.dev.56 vendor/deps/active_admin/spec/unit/event_spec.rb
lalala-4.0.0.dev.50 vendor/deps/active_admin/spec/unit/event_spec.rb
lalala-4.0.0.dev.46 vendor/deps/active_admin/spec/unit/event_spec.rb
activeadmin-0.5.1 spec/unit/event_spec.rb
activeadmin-0.5.0 spec/unit/event_spec.rb
activeadmin-0.5.0.pre1 spec/unit/event_spec.rb
activeadmin-0.5.0.pre spec/unit/event_spec.rb
activeadmin-0.4.4 spec/unit/event_spec.rb
activeadmin-0.4.3 spec/unit/event_spec.rb
activeadmin-0.4.2 spec/unit/event_spec.rb
activeadmin-0.4.1 spec/unit/event_spec.rb