Sha256: ba2e68c5345869002b5b516d86cacf51f33ace946e383c0faa8dc9cff072c920

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper'

describe Yaps::Publisher do
  describe 'active record' do
    describe 'when a model was created ' do
      it "it should call publish" do
        user = User.new(:name => 'John')
        expect(user).to receive(:publish).once.with(:user_created, user)
        user.save
      end
    end

    describe 'when a model was updated ' do
      it "it should call publish" do
        user = User.create(:name => 'John')
        user.name = 'Jack'
        expect(user).to receive(:publish).once.with(:user_updated, user)
        user.save
      end
    end

    describe 'when a model was deleted ' do
      it "it should call publish" do
        user = User.create(:name => 'John')
        expect(user).to receive(:publish).once.with(:user_deleted, user)
        user.destroy
      end
    end
  end

  describe '.publish' do
    context 'Yaps is disable' do
      it "should not publish message" do
        Yaps.configuration.enable = false
        user = User.create(:name => 'John')
        expect(user.send(:publish, :user_created, user)).to eq(false)
      end
    end

    context 'Yaps is enable' do
      it "should publish message" do
        Yaps.configuration.enable = true
        user = User.create(:name => 'John')
        expect(user.send(:publish, :user_created, user)).not_to eq(false)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yaps-0.1.0 spec/publisher_spec.rb
yaps-0.0.2 spec/publisher_spec.rb