-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proxy classes should inherit from BasicObject. Closes #2434
- Loading branch information
Showing
4 changed files
with
55 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,45 @@ | ||
require 'spec_helper' | ||
|
||
describe RailsAdmin::Config::LazyModel do | ||
describe '#store' do | ||
let(:block) { proc { register_instance_option('parameter') } } # an arbitrary instance method we can spy on | ||
let(:other_block) { proc { register_instance_option('other parameter') } } | ||
subject { RailsAdmin::Config::LazyModel.new(:Team, &block) } | ||
let(:block) { proc { register_instance_option('parameter') } } # an arbitrary instance method we can spy on | ||
|
||
describe '#store' do | ||
it "doesn't evaluate the block immediately" do | ||
expect_any_instance_of(RailsAdmin::Config::Model).not_to receive(:register_instance_option) | ||
|
||
RailsAdmin::Config::LazyModel.new(:Team, &block) | ||
subject | ||
end | ||
|
||
it 'evaluates block when reading' do | ||
expect_any_instance_of(RailsAdmin::Config::Model).to receive(:register_instance_option).with('parameter') | ||
|
||
lazy_model = RailsAdmin::Config::LazyModel.new(:Team, &block) | ||
lazy_model.groups # an arbitrary instance method on RailsAdmin::Config::Model to wake up lazy_model | ||
subject.groups # an arbitrary instance method on RailsAdmin::Config::Model to wake up lazy_model | ||
end | ||
|
||
it 'evaluates config block only once' do | ||
expect_any_instance_of(RailsAdmin::Config::Model).to receive(:register_instance_option).once.with('parameter') | ||
|
||
lazy_model = RailsAdmin::Config::LazyModel.new(:Team, &block) | ||
lazy_model.groups | ||
lazy_model.groups | ||
subject.groups | ||
subject.groups | ||
end | ||
end | ||
|
||
context 'when a method is defined in Kernel' do | ||
before do | ||
Kernel.module_eval do | ||
def weight | ||
42 | ||
end | ||
end | ||
end | ||
|
||
after do | ||
Kernel.module_eval do | ||
undef weight | ||
end | ||
end | ||
|
||
it 'proxies calls for the method to @object' do | ||
expect(subject.weight).to eq 0 | ||
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