Authors mods counter cache
parent
c3e26ea65c
commit
b84e99ebdc
|
@ -1,4 +1,4 @@
|
|||
class AuthorsMod < ActiveRecord::Base
|
||||
belongs_to :mod
|
||||
belongs_to :author, counter_cache: :mods_count
|
||||
belongs_to :author
|
||||
end
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue