Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/code_teams/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ def self.create_code_team(attributes)
)

code_teams << code_team
# Plugin's registry is keyed by team name, and the hook above only busts it after an
# example that built a fake team. An example reading only real teams therefore leaves
# real-team plugin instances behind, and a fake team sharing a real team's name would
# inherit that cached data. Drop the registry so the fake registers first.
Plugin.bust_caches!
code_team
end

Expand Down
18 changes: 18 additions & 0 deletions spec/lib/code_teams/testing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,23 @@
expect(CodeTeams.find('Temp Team')).to eq(team)
expect(team.raw_hash.dig('extra_data', 'foo', 'bar')).to eq(1)
end

it 'does not let a fake team inherit a real same-named team\'s cached plugin data' do
test_plugin_class = Class.new(CodeTeams::Plugin) do
def test_plugin
Data.define(:source).new(@team.raw_hash['extra_data']['source'])
end
end
stub_const('TestPlugin', test_plugin_class)
CodeTeams.bust_caches!
write_team_yml(extra_data: { 'source' => 'real' })

# Reading the real team caches its plugin instance under the name 'My Team'.
expect(CodeTeams.find('My Team').test_plugin.source).to eq('real')

fake = described_class.create_code_team({ name: 'My Team', extra_data: { 'source' => 'fake' } })

expect(fake.test_plugin.source).to eq('fake')
end
end
end