Skip to content

Commit

Permalink
Use the id to determine whether to unselect a package
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Feb 4, 2020
1 parent 261053f commit c58ae93
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/registration/controllers/package_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def set_package_as_selected(package)
# @param package [RemotePackage] Package to remove
def unset_package_as_selected(package)
package.unselect!
selected_packages.delete(package)
selected_packages.reject! { |p| p.id == package.id }
end

# Asks the user to enable the addon
Expand Down
23 changes: 20 additions & 3 deletions test/registration/controllers/package_search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,40 @@
end

context "when the package is already selected for installation" do
let(:selected_package) do
Registration::RemotePackage.new(
id: 1, name: "gnome-desktop", arch: :x86_64, version: "3.34", release: "1.1", addon: addon
)
end

let(:addon) do
pure_addon = load_yaml_fixture("pure_addons.yml").first
Registration::Addon.new(pure_addon)
end

before do
allow(Yast2::Popup).to receive(:show).and_return(:yes)
subject.toggle_package(selected_package)
end

context "and the package is already selected" do
let(:package) do
instance_double(
Registration::RemotePackage, id: 1, name: "gnome-desktop", addon: addon,
selected?: true, unselect!: nil, installed?: false
Registration::RemotePackage, id: 1, selected?: true,
installed?: false, unselect!: nil, addon: addon
)
end

it "unselects the package" do
allow(Yast2::Popup).to receive(:show).and_return(:yes)
expect(package).to receive(:unselect!)
subject.toggle_package(package)
expect(subject.selected_packages).to be_empty
end

context "and the addon is still needed" do
let(:another_package) do
instance_double(Registration::RemotePackage, name: "eog", addon: addon)
instance_double(Registration::RemotePackage, id: 2, name: "eog", addon: addon)
end

before do
Expand Down

0 comments on commit c58ae93

Please sign in to comment.