Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Set license accepted default as false and added license unit test
  • Loading branch information
teclator authored and imobachgs committed Apr 5, 2018
1 parent 5c3fb71 commit 8831ab8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions library/packages/src/lib/y2packager/license.rb
Expand Up @@ -35,6 +35,7 @@ class License
#
# @param options [Hash<String, String>]
def initialize(options = {})
@accepted = false
@id = id_for(options)
@translations = { DEFAULT_LANG => options[:content] }
end
Expand Down
53 changes: 53 additions & 0 deletions library/packages/test/y2packager/license_test.rb
@@ -0,0 +1,53 @@
#!/usr/bin/env rspec

require_relative "../test_helper"

require "y2packager/license"

describe Y2Packager::License do
let(:license) { Y2Packager::License.new(content: "dummy content") }

describe "#content_for" do
it "returns the license content for the given language if exists" do
expect(license.content_for(described_class::DEFAULT_LANG)).to eq("dummy content")
end

it "returns nil if there is no content for the given language" do
expect(license.content_for("es_ES")).to eq(nil)
end
end

describe "#add_content_for" do
it "adds a new translated content to the license" do
expect(license.content_for("es_ES")).to eq(nil)
expect(license.add_content_for("es_ES", "contenido ficticio"))
expect(license.content_for("es_ES")).to eq("contenido ficticio")
end
end

describe "#accept!" do
it "marks the license as accepted" do
expect(license.accepted?).to be(false)
license.accept!
expect(license.accepted?).to be(true)
end
end

describe "#reject!" do
it "marks the license as rejected" do
license.accept!
expect(license.accepted?).to be(true)
license.reject!
expect(license.accepted?).to be(false)
end
end

describe "#accepted?" do
it "returns whether the license has been accepted or not" do
license.reject!
expect(license.accepted?).to be(false)
license.accept!
expect(license.accepted?).to be(true)
end
end
end
7 changes: 4 additions & 3 deletions library/packages/test/y2packager/product_test.rb
Expand Up @@ -187,27 +187,28 @@
describe "#license_content" do
let(:license_content) { "license content" }
let(:lang) { "en_US" }
let(:license_reader) { product.send(:license_reader) }

before do
allow(Yast::Pkg).to receive(:PrdGetLicenseToConfirm).with(product.name, lang)
.and_return(license_content)
allow(product.license_reader).to receive(:license_content).and_return(license_content)
allow(license_reader).to receive(:license_content).and_return(license_content)
end

it "return the license content" do
expect(product.license_content(lang)).to eq(license_content)
end

context "when the no license to confirm was found" do
let(:license) { "" }
let(:license_content) { "" }

it "return the empty string" do
expect(product.license_content(lang)).to eq("")
end
end

context "when the product does not exist" do
let(:license) { nil }
let(:license_content) { nil }

it "return nil" do
expect(product.license_content(lang)).to be_nil
Expand Down

0 comments on commit 8831ab8

Please sign in to comment.