Sha256: 5eb006abc148fef3dfdb6edca4427a46de07ca5d34aa194212005c9a0aa91b9f

Contents?: true

Size: 1.35 KB

Versions: 5

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'

module Untied
  describe Event do
    before(:all) do
      module PostRepresenter
        include Representable::JSON

        property :title
      end
    end
    let(:post) { Post.create(:title => "DIY") }

    context "#to_json" do
      it "should serialize according with EventRepresenter" do
        event = Event.new(:name => "foo", :payload => {}, :origin => :bar)
        JSON.parse(event.to_json).to_a.sort.should ==
          { "event" =>
            { "name" => "foo", "origin" => "bar", "payload" => {  } } }.to_a.sort
      end

      it "should represent payload" do
        event = Event.new(:name => "foo", :payload => post, :origin => :bar,
                         :payload_representer => PostRepresenter)

        JSON.parse(event.to_json).to_a.sort.should ==
          { "event" =>
            { "name" => "foo", "origin" => "bar",
              "payload" => { "title" => "DIY" } } }.to_a.sort
      end

      it "should fallback to default to_json when there is no representer" do
        person = User.create(:name => "Guila")
        event = Event.new(:name => "foo", :payload => person, :origin => :bar)

        JSON.parse(event.to_json).to_a.sort.should ==
          { "event" =>
            { "name" => "foo", "origin" => "bar",
              "payload" => JSON.parse(person.to_json) } }.to_a.sort
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
untied-publisher-0.0.7.pre3 spec/event_representer_spec.rb
untied-publisher-0.0.7.pre2 spec/event_representer_spec.rb
untied-publisher-0.0.7.pre1 spec/event_representer_spec.rb
untied-publisher-0.0.7.pre spec/event_representer_spec.rb
untied-publisher-0.0.6 spec/event_representer_spec.rb