diff --git a/app/models/authors_mod.rb b/app/models/authors_mod.rb index e5e1eb8..29a383d 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, counter_cache: :mods_count + belongs_to :author end diff --git a/app/models/mod.rb b/app/models/mod.rb index 6fcad10..3ad4669 100644 --- a/app/models/mod.rb +++ b/app/models/mod.rb @@ -23,7 +23,7 @@ class Mod < ActiveRecord::Base ### Relationships ################# - belongs_to :author, validate: true, autosave: true + belongs_to :author, validate: true, autosave: true, counter_cache: :mods_count belongs_to :owner, class_name: 'User' belongs_to :game_version_start, class_name: 'GameVersion' belongs_to :game_version_end, class_name: 'GameVersion' diff --git a/spec/models/author_spec.rb b/spec/models/author_spec.rb index 17f45ed..c539a0c 100644 --- a/spec/models/author_spec.rb +++ b/spec/models/author_spec.rb @@ -97,4 +97,15 @@ describe Author do end end end + + describe '#mods_count' do + it 'should increase with mods' do + a = create :author + create :mod, author: a + create :mod, author: a + create :mod, author: a + a.reload + expect(a.mods_count).to eq 3 + end + end end diff --git a/spec/models/authors_mod_spec.rb b/spec/models/authors_mod_spec.rb index b6b8239..b5ad65b 100644 --- a/spec/models/authors_mod_spec.rb +++ b/spec/models/authors_mod_spec.rb @@ -7,15 +7,4 @@ 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