Sha256: 355f66a0525e20f2bd5da4c1e3c0bc72fe326ca8a80279e646578cc4cdb52bfb

Contents?: true

Size: 1.53 KB

Versions: 33

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'

module Startback
  describe Event do

    subject{
      Event.new("User::Changed", { "foo" => "bar" })
    }

    it 'presents an ostruct on top of its data' do
      expect(subject.data.foo).to eql("bar")
    end

    describe "the json information contract" do

      JSON_SRC = <<-JSON.gsub(/\s+/, "")
        {
          "type": "User::Changed",
          "data": {
            "foo": "bar"
          }
        }
      JSON

      it 'has a to_json method that works as expected' do
        expect(subject.to_json).to eql(JSON_SRC)
      end

      it 'has a to_json that dumps the context if any' do
        evt = Event.new("User::Changed", { "foo" => "bar" }, { "baz": "context" })
        expect(evt.to_json).to eql(<<-JSON.gsub(/\s+/, ""))
          {
            "type": "User::Changed",
            "data": {
              "foo": "bar"
            },
            "context": {
              "baz": "context"
            }
          }
        JSON
      end


      it 'has a json class method that works as expected' do
        evt = Event.json(JSON_SRC, nil)
        expect(evt).to be_a(Event)
        expect(evt.type).to eql("User::Changed")
        expect(evt.data).to eql(subject.data)
      end

      it 'accepts an explicit context as second argument' do
        c = SubContext.new.tap{|x| x.foo = 'hello' }
        evt = Event.json(JSON_SRC, c)
        expect(evt.context).not_to be(c)
        expect(evt.context).to be_a(SubContext)
        expect(evt.context.foo).to eql('hello')
      end
    end

  end
end # module Startback

Version data entries

33 entries across 33 versions & 3 rubygems

Version Path
startback-1.0.3 spec/unit/test_event.rb
startback-1.0.2 spec/unit/test_event.rb
startback-1.0.1 spec/unit/test_event.rb
startback-1.0.0 spec/unit/test_event.rb
startback-0.19.4 spec/unit/test_event.rb
startback-0.19.3 spec/unit/test_event.rb
startback-0.19.1 spec/unit/test_event.rb
startback-0.19.0 spec/unit/test_event.rb
startback-0.18.2 spec/unit/test_event.rb
startback-0.18.1 spec/unit/test_event.rb
startback-0.18.0 spec/unit/test_event.rb
startback-0.17.4 spec/unit/test_event.rb
startback-0.17.3 spec/unit/test_event.rb
startback-0.17.2 spec/unit/test_event.rb
startback-0.17.1 spec/unit/test_event.rb
startback-0.17.0 spec/unit/test_event.rb
startback-0.16.0 spec/unit/test_event.rb
startback-0.15.5 spec/unit/test_event.rb
startback-0.15.4 spec/unit/test_event.rb
startback-0.15.3 spec/unit/test_event.rb