Authors mods counter cache

master
Zequez 2015-08-07 10:46:28 -03:00
parent c3e26ea65c
commit b84e99ebdc
4 changed files with 13 additions and 13 deletions

View File

@ -1,4 +1,4 @@
class AuthorsMod < ActiveRecord::Base
belongs_to :mod
belongs_to :author, counter_cache: :mods_count
belongs_to :author
end

View File

@ -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'

View File

@ -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

View File

@ -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