Skip to content

Commit

Permalink
Merge pull request #1157 from yast/fix-issue-location
Browse files Browse the repository at this point in the history
Fix issue location
  • Loading branch information
imobachgs committed Apr 26, 2021
2 parents bfa33e1 + a5770eb commit 8313e89
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 3 additions & 3 deletions library/general/src/lib/y2issues/issue.rb
Expand Up @@ -38,21 +38,21 @@ module Y2Issues
class Issue
include Yast::I18n

# @return [String,nil] Where the error is located.
# @return [Location,nil] Where the error is located.
attr_reader :location
# @return [String] Error message
attr_reader :message
# @return [Symbol] Error severity (:warn, :fatal)
attr_reader :severity

# @param message [String] User-oriented message describing the problem
# @param location [URI,String,nil] Where the error is located. Use a URI or
# @param location [String,nil] Where the error is located. Use a URI or
# a string to represent the error location. Use 'nil' if it
# does not exist an specific location.
# @param severity [Symbol] warning (:warn) or fatal (:fatal)
def initialize(message, location: nil, severity: :warn)
@message = message
@location = Location.parse(location) if location
@location = location.is_a?(String) ? Location.parse(location) : location
@severity = severity
end

Expand Down
17 changes: 16 additions & 1 deletion library/general/test/y2issues/issue_test.rb
Expand Up @@ -25,7 +25,9 @@
describe "#new" do
subject(:issue) do
described_class.new(
"Something went wrong", location: "file:/etc/hosts", severity: :fatal
"Something went wrong",
location: Y2Issues::Location.parse("file:/etc/hosts"),
severity: :fatal
)
end

Expand All @@ -35,6 +37,19 @@
expect(issue.severity).to eq(:fatal)
end

context "when location is given as a string" do
subject(:issue) do
described_class.new(
"Something went wrong",
location: "file:/etc/hosts"
)
end

it "parses the given location" do
expect(issue.location).to eq(Y2Issues::Location.parse("file:/etc/hosts"))
end
end

context "when a severity is not given" do
subject(:issue) { described_class.new("Something went wrong") }

Expand Down
6 changes: 6 additions & 0 deletions package/yast2.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Thu Apr 22 06:35:11 UTC 2021 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- The location given to the Y2Issue::Issue constructor can be a
string or a location object.

-------------------------------------------------------------------
Fri Apr 16 12:03:50 UTC 2021 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down

0 comments on commit 8313e89

Please sign in to comment.