Skip to content

Commit

Permalink
ProductLicense#{accept!,reject!} does not return anything
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Apr 5, 2018
1 parent 5b85533 commit b9b77ff
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
10 changes: 3 additions & 7 deletions library/packages/src/lib/y2packager/product_license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 51 additions & 12 deletions library/packages/test/y2packager/product_license_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit b9b77ff

Please sign in to comment.