Skip to content

Commit

Permalink
Extract class AlternativeClient to StartCheckingPermissions
Browse files Browse the repository at this point in the history
  • Loading branch information
jyeray committed Jul 26, 2016
1 parent 3ac8fb6 commit 0b187a5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
13 changes: 2 additions & 11 deletions src/clients/alternatives.rb
@@ -1,12 +1,3 @@
require "y2_alternatives/dialog/list_alternatives"
require "y2_alternatives/client/start_checking_permissions"

Yast.import "Confirm"

# Checks if user is root and create a ListAlternatives dialog
class AlternativesClient
def main
Y2Alternatives::Dialog::ListAlternatives.run if Yast::Confirm.MustBeRoot
end
end

AlternativesClient.new.main
Y2Alternatives::Client::StartCheckingPermissions.new.main
32 changes: 32 additions & 0 deletions src/lib/y2_alternatives/client/start_checking_permissions.rb
@@ -0,0 +1,32 @@
# Copyright (c) 2016 SUSE LLC.
# All Rights Reserved.

# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 or 3 of the GNU General
# Public License as published by the Free Software Foundation.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, contact SUSE LLC.

# To contact SUSE about this file by physical or electronic mail,
# you may find current contact information at www.suse.com

require "y2_alternatives/dialog/list_alternatives"

Yast.import "Confirm"

module Y2Alternatives
module Client
# Checks if user is root and create a ListAlternatives dialog
class StartCheckingPermissions
def main
Y2Alternatives::Dialog::ListAlternatives.run if Yast::Confirm.MustBeRoot
end
end
end
end
12 changes: 5 additions & 7 deletions test/client/client_spec.rb → test/client/alternative_spec.rb
Expand Up @@ -18,17 +18,15 @@

require_relative "../spec_helper.rb"
require "y2_alternatives/dialog/list_alternatives"
require "y2_alternatives/client/start_checking_permissions"

describe "AlternativesClient" do
before do
allow(Y2Alternatives::Dialog::ListAlternatives).to receive(:run)
require_relative "../../src/clients/alternatives.rb"
end

describe Y2Alternatives::Client::StartCheckingPermissions do
describe "#main" do
subject(:client) { AlternativesClient.new }
subject(:client) { Y2Alternatives::Client::StartCheckingPermissions.new }

it "checks if user is root" do
allow(Y2Alternatives::Dialog::ListAlternatives).to receive(:run)

expect(Yast::Confirm).to receive(:MustBeRoot).and_return true
client.main
end
Expand Down

0 comments on commit 0b187a5

Please sign in to comment.