From 590e1b4b21f2a39bf573800392b04859b563f3e5 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 8 Mar 2016 18:04:00 +0100 Subject: Call after_create_branch in Repository#add_branch This ensures the right caches are flushed when adding a branch via the UI, instead of only flushing this one random cache. --- app/models/repository.rb | 3 ++- spec/models/repository_spec.rb | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index c0730b34316..6441cd87e87 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -133,7 +133,7 @@ class Repository rugged.branches.create(branch_name, target) end - expire_branches_cache + after_create_branch find_branch(branch_name) end @@ -356,6 +356,7 @@ class Repository # Runs code after a new branch has been created. def after_create_branch + expire_branches_cache expire_has_visible_content_cache expire_branch_count_cache end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 97778c354a4..34866be3395 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -148,6 +148,12 @@ describe Repository, models: true do expect(branch.name).to eq('new_feature') end + + it 'calls the after_create_branch hook' do + expect(repository).to receive(:after_create_branch) + + repository.add_branch(user, 'new_feature', 'master') + end end context 'when pre hooks failed' do -- cgit v1.2.1