From b9b77ff62e79cbbfcc9435470aa7ef351db1cc4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Thu, 5 Apr 2018 14:29:35 +0100 Subject: [PATCH] ProductLicense#{accept!,reject!} does not return anything --- .../src/lib/y2packager/product_license.rb | 10 +-- .../test/y2packager/product_license_test.rb | 63 +++++++++++++++---- 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/library/packages/src/lib/y2packager/product_license.rb b/library/packages/src/lib/y2packager/product_license.rb index 99e19ca00..353f626c9 100644 --- a/library/packages/src/lib/y2packager/product_license.rb +++ b/library/packages/src/lib/y2packager/product_license.rb @@ -85,28 +85,24 @@ def initialize(product_name, license, source: nil) # # @return [Boolean] true if the license has been accepted; false otherwise. def accepted? - license.accepted? sync_acceptance + license.accepted? 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? + nil end # Reject the license - # - # @return [Boolean] true if the license has been accepted; false otherwise. def reject! license.reject! sync_acceptance - license.accepted? + nil end private diff --git a/library/packages/test/y2packager/product_license_test.rb b/library/packages/test/y2packager/product_license_test.rb index 2d8993946..bb4a5426a 100644 --- a/library/packages/test/y2packager/product_license_test.rb +++ b/library/packages/test/y2packager/product_license_test.rb @@ -96,16 +96,21 @@ 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 + + context "when a handler was not given" do + let(:handler) { nil } + + it "does not try to synchronize the status and does not crash" do + expect(license).to receive(:accept!).and_call_original + product_license.accept! + end + end end describe "#reject!" do @@ -116,27 +121,61 @@ 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 + + context "when a handler was not given" do + let(:handler) { nil } + + it "does not try to synchronize the status and does not crash" do + expect(license).to receive(:reject!).and_call_original + product_license.reject! + end + end end describe "#accepted?" do - context "if the product license has been accepted" do - it "returns true" + before do + allow(license).to receive(:accepted?).and_return(accepted?) end context "if the product license has been accepted" do - it "returns false" + let(:accepted?) { true } + + it "returns true" do + expect(product_license).to be_accepted + end + + it "synchronizes the source" do + expect(handler).to receive(:confirmation=).with(true) + product_license.reject! + end end - context "synchronizes the license status" + context "if the product license has not been accepted" do + let(:accepted?) { false } + + it "returns false" do + expect(product_license).to_not be_accepted + end + + it "synchronizes the source" do + expect(handler).to receive(:confirmation=).with(false) + product_license.reject! + end + end + + context "when a handler was not given" do + let(:handler) { nil } + let(:accepted?) { true } + + it "does not try to synchronize the status and does not crash" do + product_license.accepted? + end + end end end