spec/publisher_spec.rb in yaps-0.0.1 vs spec/publisher_spec.rb in yaps-0.0.2

- old
+ new

@@ -1,24 +1,48 @@ require 'spec_helper' describe Yaps::Publisher do - describe 'messages' do - it "it should fired a message after create" do - user = User.new(:name => 'John') - expect(user).to receive(:publish).once.with(:user_created, user) - user.save + 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 - it "it should fired a message after update" do - user = User.create(:name => 'John') - user.name = 'Jack' - expect(user).to receive(:publish).once.with(:user_updated, user) - user.save + 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 - it "it should fired a message after update" do - user = User.create(:name => 'John') - expect(user).to receive(:publish).once.with(:user_deleted, user) - user.destroy + 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