Skip to content

Commit

Permalink
Update libzypp acceptance status
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Apr 5, 2018
1 parent a7e2f5a commit ede6ca9
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
32 changes: 30 additions & 2 deletions library/packages/src/lib/y2packager/product_license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module Y2Packager
class ProductLicense
extend Forwardable

def_delegators :@license, :content_for, :locales, :accept!, :reject!
def_delegators :@license, :content_for, :locales

# @!method license_confirmation_required?
# Determine whether the license should be accepted or not
Expand Down Expand Up @@ -81,11 +81,39 @@ def initialize(product_name, license, source: nil)
@handler = Y2Packager::LicensesHandlers.for(source, product_name) if source
end

# Determines whether the license have been accepted or not
# Determine whether the license have been accepted or not
#
# @return [Boolean] true if the license has been accepted; false otherwise.
def accepted?
license.accepted?
sync_acceptance
end

# Accept the license
#
# As a side effect, it will update the source acceptance
#
# @return [Boolean] true if the license has been accepted; false otherwise.
def accept!
license.accept!
sync_acceptance
license.accepted?
end

# Reject the license
#
# @return [Boolean] true if the license has been accepted; false otherwise.
def reject!
license.reject!
sync_acceptance
license.accepted?
end

private

def sync_acceptance
return @handler unless @handler
@handler.confirmation = license.accepted?
end
end
end
41 changes: 38 additions & 3 deletions library/packages/test/y2packager/product_license_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@
require "y2packager/product_license"

describe Y2Packager::ProductLicense do
subject(:product_license) { Y2Packager::ProductLicense.new(product_name, license) }
subject(:product_license) do
Y2Packager::ProductLicense.new(product_name, license, source: :libzypp)
end

let(:license) { instance_double(Y2Packager::License) }
let(:license) { instance_double(Y2Packager::License, accept!: true, reject!: false) }
let(:product_name) { "SLES" }
let(:handler) { instance_double(Y2Packager::LicensesHandlers::Libzypp, :confirmation= => nil) }

before do
described_class.clear_cache
allow(Y2Packager::LicensesHandlers).to receive(:for)
.with(:libzypp, product_name).and_return(handler)
end

describe ".find" do
Expand Down Expand Up @@ -80,17 +85,47 @@
end

describe "#accept!" do
subject(:product_license) do
Y2Packager::ProductLicense.new(product_name, license, source: :libzypp)
end

let(:license) { Y2Packager::License.new(content: "Some content") }

it "delegates to License#accept!" do
expect(license).to receive(:accept!)
expect(license).to receive(:accept!).and_call_original
product_license.accept!
end

it "returns true" do
expect(product_license.accept!).to eq(true)
end

context "when a handler for the source is given" do
it "synchronizes the source" do
expect(handler).to receive(:confirmation=).with(true)
product_license.accept!
end
end
end

describe "#reject!" do
let(:license) { Y2Packager::License.new(content: "Some content") }

it "delegates to License#reject!" do
expect(license).to receive(:reject!)
product_license.reject!
end

it "returns false" do
expect(product_license.reject!).to eq(false)
end

context "when a handler for the source is given" do
it "synchronizes the source" do
expect(handler).to receive(:confirmation=).with(false)
product_license.reject!
end
end
end

describe "#accepted?" do
Expand Down

0 comments on commit ede6ca9

Please sign in to comment.