Sha256: f60521f7e71739d1c562e1f7406e20c785e160ac139cbc6eb0f085004c67581b

Contents?: true

Size: 1.09 KB

Versions: 12

Compression:

Stored size: 1.09 KB

Contents

require 'spec_helper'

describe RailsAdmin::Config::LazyModel do
  describe "#store" do
    let(:block) { Proc.new { register_instance_option('parameter') } } # an arbitrary instance method we can spy on
    let(:other_block) { Proc.new { register_instance_option('other parameter') } }

    it "doesn't evaluate the block immediately" do
      RailsAdmin::Config::Model.any_instance.should_not_receive(:register_instance_option)

      RailsAdmin::Config::LazyModel.new(:Team, &block)
    end

    it "evaluates block when reading" do
      RailsAdmin::Config::Model.any_instance.should_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
    end

    it "evaluates config block only once" do
      RailsAdmin::Config::Model.any_instance.should_receive(:register_instance_option).once.with('parameter')

      lazy_model = RailsAdmin::Config::LazyModel.new(:Team, &block)
      lazy_model.groups
      lazy_model.groups
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
rails_admin-0.5.0 spec/rails_admin/config/lazy_model_spec.rb
rails_admin-0.4.9 spec/rails_admin/config/lazy_model_spec.rb
rails_admin-0.4.8 spec/rails_admin/config/lazy_model_spec.rb
rails_admin-0.4.7 spec/rails_admin/config/lazy_model_spec.rb
rails_admin-0.4.6 spec/rails_admin/config/lazy_model_spec.rb
rails_admin-0.4.5 spec/rails_admin/config/lazy_model_spec.rb
rails_admin-0.4.4 spec/rails_admin/config/lazy_model_spec.rb
rails_admin-lbgraham-0.4.2 spec/rails_admin/config/lazy_model_spec.rb
rails_admin-0.4.3 spec/rails_admin/config/lazy_model_spec.rb
rails_admin-0.4.2 spec/rails_admin/config/lazy_model_spec.rb
rails_admin-0.4.1 spec/rails_admin/config/lazy_model_spec.rb
rails_admin-0.4.0 spec/rails_admin/config/lazy_model_spec.rb