Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to temporary enable yaps
- Loading branch information
Võ Anh Duy
committed
Apr 12, 2014
1 parent
71788a3
commit f724ba2
Showing
6 changed files
with
92 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'spec_helper' | ||
|
||
describe Yaps do | ||
describe '#with_pushlisher_enable' do | ||
it 'should enable Yaps for block in its scope' do | ||
Yaps.configuration.enable = false | ||
Yaps.with_pushlisher_enable do | ||
expect(Yaps.configuration.enable).to eq(true) | ||
end | ||
end | ||
|
||
it 'should not change configuration state outside of its scope' do | ||
Yaps.configuration.enable = false | ||
Yaps.with_pushlisher_enable do | ||
end | ||
expect(Yaps.configuration.enable).to eq(false) | ||
end | ||
|
||
it ' should execute the block pass to it' do | ||
a = 5 | ||
Yaps.with_pushlisher_enable do | ||
a = 10 | ||
end | ||
expect(a).to eq(10) | ||
end | ||
end | ||
end |