Skip to content

Commit

Permalink
Merge pull request #667 from amatsuda/enable_enabled
Browse files Browse the repository at this point in the history
Alias `Bullet.enable?` to `enabled?`, and `Bullet.enable=` to `enabled=`
  • Loading branch information
flyerhzm committed Sep 7, 2023
2 parents 41d713f + 6f66c22 commit 1a71e5a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/bullet.rb
Expand Up @@ -70,10 +70,14 @@ def enable=(enable)
end
end

alias enabled= enable=

def enable?
!!@enable
end

alias enabled? enable?

# Rails.root might be nil if `railties` is a dependency on a project that does not use Rails
def app_root
@app_root ||= (defined?(::Rails.root) && !::Rails.root.nil? ? Rails.root.to_s : Dir.pwd).to_s
Expand Down
34 changes: 34 additions & 0 deletions spec/bullet_spec.rb
Expand Up @@ -38,6 +38,40 @@
end
end

# Testing the aliases.
describe '#enabled' do
context 'enable Bullet' do
before do
# Bullet.enable
# Do nothing. Bullet has already been enabled for the whole test suite.
end

it 'should be enabled' do
expect(subject).to be_enabled
end

context 'disable Bullet' do
before { Bullet.enabled = false }

it 'should be disabled' do
expect(subject).to_not be_enabled
end

context 'enable Bullet again without patching again the orms' do
before do
expect(Bullet::Mongoid).not_to receive(:enabled) if defined?(Bullet::Mongoid)
expect(Bullet::ActiveRecord).not_to receive(:enabled) if defined?(Bullet::ActiveRecord)
Bullet.enabled = true
end

it 'should be enabled again' do
expect(subject).to be_enabled
end
end
end
end
end

describe '#start?' do
context 'when bullet is disabled' do
before(:each) { Bullet.enable = false }
Expand Down

0 comments on commit 1a71e5a

Please sign in to comment.