From a3cb596db8d95577a20eee35503e78ba4978faf0 Mon Sep 17 00:00:00 2001 From: Zequez Date: Thu, 6 Aug 2015 10:54:33 -0300 Subject: [PATCH] :bug: Add authors#mods_count that wasn't being used --- app/models/authors_mod.rb | 2 +- spec/models/authors_mod_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/models/authors_mod.rb b/app/models/authors_mod.rb index 29a383d..e5e1eb8 100644 --- a/app/models/authors_mod.rb +++ b/app/models/authors_mod.rb @@ -1,4 +1,4 @@ class AuthorsMod < ActiveRecord::Base belongs_to :mod - belongs_to :author + belongs_to :author, counter_cache: :mods_count end diff --git a/spec/models/authors_mod_spec.rb b/spec/models/authors_mod_spec.rb index b5ad65b..b6b8239 100644 --- a/spec/models/authors_mod_spec.rb +++ b/spec/models/authors_mod_spec.rb @@ -7,4 +7,15 @@ describe AuthorsMod, type: :model do it { expect(authors_mod.build_author).to be_kind_of Author } it { is_expected.to respond_to :sort_order } it { expect(authors_mod.sort_order).to be_kind_of Integer } + + describe '#mods_count' do + it 'should increase with mods' do + a = create :author + create :mod, authors: [a] + create :mod, authors: [a] + create :mod, authors: [a] + a.reload + expect(a.mods_count).to eq 3 + end + end end