Skip to content

Commit 643d330

Browse files
authored
fix: Clear CodeTeams::Plugin registries when busting caches (#12)
* fix: Clear CodeTeams::Plugin registries when busting caches This ensures stale team configs are purged when calling CodeTeams.bust_caches! * chore: Increment version number
1 parent 182c347 commit 643d330

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

code_teams.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = 'code_teams'
3-
spec.version = '1.0.1'
3+
spec.version = '1.0.2'
44
spec.authors = ['Gusto Engineers']
55
spec.email = ['[email protected]']
66
spec.summary = 'A low-dependency gem for declaring and querying engineering teams'

lib/code_teams.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def self.tag_value_for(string)
6060
# The primary reason this is helpful is for clients of CodeTeams who want to test their code, and each test context has different set of teams
6161
sig { void }
6262
def self.bust_caches!
63+
Plugin.bust_caches!
6364
@all = nil
6465
@index_by_name = nil
6566
end

lib/code_teams/plugin.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ def self.register_team(team)
6161
T.unsafe(registry_for_team[self])
6262
end
6363

64+
sig { void }
65+
def self.bust_caches!
66+
all_plugins.each(&:clear_team_registry!)
67+
end
68+
69+
sig { void }
70+
def self.clear_team_registry!
71+
@registry = nil
72+
end
73+
6474
private_class_method :registry
6575
private_class_method :register_team
6676
end

spec/lib/plugin_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
RSpec.describe CodeTeams::Plugin do
2+
def write_team_yml(extra_data: false)
3+
write_file('config/teams/my_team.yml', <<~YML.strip)
4+
name: My Team
5+
extra_data: #{extra_data}
6+
YML
7+
end
8+
9+
before do
10+
CodeTeams.bust_caches!
11+
12+
test_plugin_class = Class.new(described_class) do
13+
def extra_data
14+
@team.raw_hash['extra_data']
15+
end
16+
end
17+
stub_const('TestPlugin', test_plugin_class)
18+
end
19+
20+
describe '.bust_caches!' do
21+
it 'clears all plugins team registries ensuring cached configs are purged' do
22+
write_team_yml(extra_data: true)
23+
team = CodeTeams.find('My Team')
24+
expect(TestPlugin.for(team).extra_data).to be(true)
25+
write_team_yml(extra_data: false)
26+
CodeTeams.bust_caches!
27+
team = CodeTeams.find('My Team')
28+
expect(TestPlugin.for(team).extra_data).to be(false)
29+
end
30+
end
31+
end

0 commit comments

Comments
 (0)