spec/unit/cached_abilities_spec.rb in cancannible-2.0.0 vs spec/unit/cached_abilities_spec.rb in cancannible-2.1.0

- old
+ new

@@ -38,11 +38,11 @@ end context "when store_cached_abilities provided" do before do @stored = nil - Cancannible.store_cached_abilities = proc { |grantee, ability| @stored = { grantee_id: grantee.id, ability: ability } } + Cancannible.store_cached_abilities = proc { |grantee, ability| @stored = { grantee_id: grantee.id, ability: cached_object } } end it "stores the cached object" do expect { subject }.to change { @stored }.from(nil) expect(@stored[:grantee_id]).to eql(grantee.id) expect(@stored[:ability]).to be_an(Ability) @@ -51,31 +51,29 @@ context "when get and store cached_abilities provided" do before do @stored = nil @store = 0 - Cancannible.get_cached_abilities = proc { |grantee| @stored[:ability] if @stored } + Cancannible.get_cached_abilities = proc { |grantee| @stored && cached_object } Cancannible.store_cached_abilities = proc { |grantee, ability| @store += 1 ; @stored = { grantee_id: grantee.id, ability: ability } } end it "stores the cached object on the first call" do expect { subject }.to change { @stored }.from(nil) expect(@store).to eql(1) - expect(@stored[:grantee_id]).to eql(grantee.id) - expect(@stored[:ability]).to be_an(Ability) + expect(grantee.abilities.instance_variable_get(:@rules).size).to eql(1) + expect(grantee.abilities.instance_variable_get(:@rules_index).size).to eql(1) end it "returns the cached object on the second call" do expect { subject }.to change { @stored }.from(nil) expect(@store).to eql(1) expect { grantee.abilities }.to_not change { @store } expect(grantee.abilities).to be_an(Ability) - expect(@stored[:grantee_id]).to eql(grantee.id) end it "should re-cache object on the second call if refresh requested" do expect { subject }.to change { @stored }.from(nil) expect(@store).to eql(1) expect { grantee.abilities(true) }.to change { @store }.from(1).to(2) expect(grantee.abilities).to be_an(Ability) - expect(@stored[:grantee_id]).to eql(grantee.id) end end end end