Implement ResetProjectCacheService

This commit is contained in:
Matija Čupić 2017-12-22 21:28:25 +01:00
parent f58cc2ee60
commit 0a002e230b
No known key found for this signature in database
GPG key ID: 4BAF84FFACD2E5DE
2 changed files with 19 additions and 2 deletions

View file

@ -1,4 +1,5 @@
class ResetProjectCacheService < BaseService class ResetProjectCacheService < BaseService
def execute def execute
@project.increment!(:cache_index)
end end
end end

View file

@ -6,7 +6,23 @@ describe ResetProjectCacheService do
subject { described_class.new(project, user).execute } subject { described_class.new(project, user).execute }
it "resets project cache" do context 'when project cache_index is nil' do
fail before do
project.cache_index = nil
end
it 'sets project cache_index to one' do
expect { subject }.to change { project.reload.cache_index }.from(nil).to(1)
end
end
context 'when project cache_index is a numeric value' do
before do
project.update_attributes(cache_index: 1)
end
it 'increments project cache index' do
expect { subject }.to change { project.reload.cache_index }.by(1)
end
end end
end end