-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
counter_cache should also update the counter in memory.
This spec should pass:
diff --git a/spec/mongoid/relations/referenced/many_spec.rb b/spec/mongoid/relations/referenced/many_spec.rb index 8c1f098..cb9e830 100644 --- a/spec/mongoid/relations/referenced/many_spec.rb +++ b/spec/mongoid/relations/referenced/many_spec.rb @@ -173,7 +173,19 @@ describe Mongoid::Relations::Referenced::Many do end it "increments the counter cache" do - expect(person.reload.posts_count).to eq(1) + expect(person[:posts_count]).to eq(1) + end + + context "when saving another post" do + + before do + person.reload + person.posts.send(method, Post.new) + end + + it "increments the counter cache" do + expect(person.posts_count).to eq(2) + end end context "when documents already exist on the relation" do