Skip to content

Commit

Permalink
Update from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Aug 7, 2018
1 parent 90fc0fb commit f0374a0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
16 changes: 13 additions & 3 deletions src/include/dns-server/dialog-main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# Summary: Data for configuration of dns-server, input and output functions.
# Authors: Jiri Srain <jsrain@suse.cz>

require "yast"
require "yast2/popup"
require "dns-server/service_widget_helpers"

module Yast
Expand Down Expand Up @@ -1878,11 +1880,11 @@ def WriteDialog
Wizard.RestoreHelp(write_help_text)

return :next if write_settings
return :back if Popup.YesNo(_("Saving the configuration failed. Change the settings?"))
return :back if back_to_change_setting?
:abort
end

# Writes settings without exit
# Writes settings without exiting
def SaveAndRestart(event)
return nil unless validate_and_save_widgets(event)

Expand All @@ -1898,14 +1900,22 @@ def SaveAndRestart(event)

# Writes DNS server settings and save the service
#
# NOTE: currently, the DnsServer is a Perl module, reason why the write of
# @note currently, the DnsServer is a Perl module, reason why the write of
# settings is being performed in two steps.
#
# @return [Boolean] true if settings are saved successfully; false otherwise
def write_settings
DnsServer.Write && service.save
end

# Shows a popup asking to user if wants to change settings
#
# @return [Boolean] true if user decides to go back to change settings; false otherwise
def back_to_change_setting?
change_settings_message = _("Saving the configuration failed. Change the settings?")
Yast2::Popup.show(change_settings_message, headline: :warning, buttons: :yes_no) == :yes
end

# Validates and saves CWM widgets
#
# @param [Hash] event map that triggered saving
Expand Down
28 changes: 25 additions & 3 deletions src/lib/dns-server/service_widget_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# encoding: utf-8

# Copyright (c) [2018] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 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 LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
# encoding: utf-8

require "cwm/service_widget"
require "yast2/system_service"

Expand All @@ -10,13 +32,13 @@ def service
@service ||= Yast2::SystemService.find("named")
end

# Returns the status widget for service
# Returns the service widget
#
# @return [::CWM::ServiceWidget] service status widget
# @return [CWM::ServiceWidget] service status widget
#
# @see #service
def service_widget
@service_widget ||= ::CWM::ServiceWidget.new(service)
@service_widget ||= CWM::ServiceWidget.new(service)
end
end
end
8 changes: 4 additions & 4 deletions test/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def initialize

context "when the configuration is not written" do
let(:written) { false }
let(:change_settings) { true }
let(:change_settings) { :yes }

before do
allow(Yast::Popup).to receive(:YesNo).and_return(change_settings)
allow(Yast2::Popup).to receive(:show).and_return(change_settings)
end

it "aks for changing the current settings" do
expect(Yast::Popup).to receive(:YesNo)
expect(Yast2::Popup).to receive(:show).with(instance_of(String), hash_including(buttons: :yes_no))

subject.WriteDialog
end
Expand All @@ -51,7 +51,7 @@ def initialize
end

context "and user decides to cancel" do
let(:change_settings) { false }
let(:change_settings) { :no }

it "returns :abort" do
expect(subject.WriteDialog).to eq(:abort)
Expand Down

0 comments on commit f0374a0

Please sign in to comment.