Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

description_cache_store: handle empty database. #5111

Merged
merged 1 commit into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions Library/Homebrew/description_cache_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def delete!(formula_name)
# @return [nil]
def populate_if_empty!
return unless database.empty?

Formula.each { |f| update!(f.full_name, f.desc) }
end

Expand All @@ -39,6 +40,7 @@ def populate_if_empty!
# @param [Report] report: an update report generated by cmd/update.rb
# @return [nil]
def update_from_report!(report)
return populate_if_empty! if database.empty?
return if report.empty?

renamings = report.select_formula(:R)
Expand All @@ -56,11 +58,12 @@ def update_from_report!(report)
# @param [Array] formula_names: the formulae to update.
# @return [nil]
def update_from_formula_names!(formula_names)
return populate_if_empty! if database.empty?

formula_names.each do |name|
begin
update!(name, Formula[name].desc)
rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS => e
p e
rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS
delete!(name)
end
end
Expand All @@ -71,6 +74,8 @@ def update_from_formula_names!(formula_names)
# @param [Array] formula_names: the formulae to delete.
# @return [nil]
def delete_from_formula_names!(formula_names)
return if database.empty?

formula_names.each(&method(:delete!))
end

Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/test/description_cache_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
let(:report) { double(select_formula: [], empty?: false) }

it "reads from the report" do
expect(database).to receive(:empty?).at_least(:once).and_return(false)
cache_store.update_from_report!(report)
end
end
Expand All @@ -36,13 +37,15 @@
desc "desc"
end
expect(Formulary).to receive(:factory).with(f.name).and_return(f)
expect(database).to receive(:empty?).and_return(false)
expect(database).to receive(:set).with(f.name, f.desc)
cache_store.update_from_formula_names!([f.name])
end
end

describe "#delete_from_formula_names!" do
it "deletes the formulae descriptions" do
expect(database).to receive(:empty?).and_return(false)
expect(database).to receive(:delete).with(formula_name)
cache_store.delete_from_formula_names!([formula_name])
end
Expand Down